Skip to content
Merged
104 changes: 104 additions & 0 deletions app/Filament/Resources/ChannelResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources;

use App\Filament\Resources\ChannelResource\Pages;
use App\Models\Channel;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Support\Enums\MaxWidth;
use Filament\Tables;
use Filament\Tables\Actions\ActionGroup;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Str;

final class ChannelResource extends Resource
{
protected static ?string $model = Channel::class;

protected static ?string $navigationIcon = 'heroicon-o-queue-list';

public static function getLabel(): string
{
return __('Channels');
}

public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Section::make()
->schema([
Forms\Components\TextInput::make('name')
->required()
->live(onBlur: true)
->afterStateUpdated(function (string $operation, $state, Forms\Set $set): void {
$set('slug', Str::slug($state));
}),
Forms\Components\TextInput::make('slug')
->readOnly()
->helperText(__('Cette valeur est générée dynamiquement en fonction du Name.')),
Forms\Components\Select::make('parent_id')
->relationship('parent', 'name', fn (Builder $query) => $query->whereNull('parent_id'))
->default(null),
Forms\Components\TextInput::make('color')
->maxLength(255)
->type('color'),
Forms\Components\Textarea::make('description.fr')
->label('Description')
->columnSpanFull(),
])
->columnSpan(['lg' => 2]),
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('name')
->searchable(),
Tables\Columns\TextColumn::make('slug')
->searchable(),
Tables\Columns\TextColumn::make('parent.name')
->numeric()
->sortable(),
Tables\Columns\TextColumn::make('thread_number')
->label('Nombre de thead')
->getStateUsing(fn ($record) => $record->threads()->count()),
Tables\Columns\TextColumn::make('color')
->searchable(),
Tables\Columns\TextColumn::make('created_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
->filters([

])
->actions([
ActionGroup::make([
Tables\Actions\DeleteAction::make(),
Tables\Actions\EditAction::make()
->slideOver()
->modalWidth(MaxWidth::Large),
]),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}

public static function getPages(): array
{
return [
'index' => Pages\ListChannels::route('/'),
];
}
}
24 changes: 24 additions & 0 deletions app/Filament/Resources/ChannelResource/Pages/ListChannels.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\ChannelResource\Pages;

use App\Filament\Resources\ChannelResource;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;
use Filament\Support\Enums\MaxWidth;

final class ListChannels extends ListRecords
{
protected static string $resource = ChannelResource::class;

protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make()
->slideOver()
->modalWidth(MaxWidth::Large),
];
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"spatie/laravel-feed": "^4.2.1",
"spatie/laravel-google-fonts": "^1.2.3",
"spatie/laravel-medialibrary": "^10.10.0",
"spatie/laravel-permission": "^5.10.1",
"spatie/laravel-permission": "^6.10.0",
"spatie/laravel-sitemap": "^7.2.1",
"spatie/laravel-translatable": "^6.8",
"stevebauman/location": "^6.6.2",
Expand Down
37 changes: 19 additions & 18 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
"devDependencies": {
"@alpinejs/intersect": "^3.6.1",
"@awcodes/alpine-floating-ui": "^3.5.0",
"@ryangjchandler/alpine-tooltip": "^1.2.0",
"@ryangjchandler/alpine-tooltip": "^2.0.1",
"@tailwindcss/aspect-ratio": "^0.4.2",
"@tailwindcss/forms": "^0.5.7",
"@tailwindcss/typography": "^0.5.10",
"alpinejs": "^3.12.0",
"autoprefixer": "^10.4.16",
"highlight.js": "^11.7.0",
"intl-tel-input": "^17.0.13",
"laravel-vite-plugin": "^0.7.8",
"laravel-vite-plugin": "^1.0.5",
"lodash": "^4.17.19",
"postcss": "^8.4.32",
"postcss-loader": "^6.2.1",
"postcss-loader": "^8.1.1",
"postcss-preset-env": "^7.0.1",
"prettier": "^3.2.5",
"prettier-plugin-tailwindcss": "^0.5.14",
Expand Down
2 changes: 1 addition & 1 deletion resources/views/components/user/stats.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
{{ __('pages/account.dashboard.stats.experience') }}
</dt>
<dd class="mt-2 text-3xl font-semibold font-mono slashed-zero tabular-nums text-gray-900 dark:text-white">
0
{{ $user->getPoints() }}
</dd>
<span class="absolute z-0 -bottom-2 right-0 text-primary-600/50 rotate-12 transform transition duration-200 ease-in-out group-hover:scale-105 group-hover:rotate-[10deg]">
<x-untitledui-trophy-02 class="size-20" stroke-width="1.5" aria-hidden="true" />
Expand Down
56 changes: 56 additions & 0 deletions tests/Feature/Filament/ChannelTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

declare(strict_types=1);

use App\Filament\Resources\ChannelResource;
use App\Filament\Resources\ChannelResource\Pages\ListChannels;
use App\Models\Channel;
use Filament\Actions\CreateAction;
use Filament\Actions\EditAction;
use Livewire\Livewire;

beforeEach(function (): void {
$this->user = $this->login();
});

describe(ChannelResource::class, function (): void {
it('page can display table with records', function (): void {
$channels = Channel::factory()
->count(10)
->create();
Livewire::test(ListChannels::class)
->assertCanSeeTableRecords($channels);
});

it('Admin user can create channel', function (): void {
Livewire::test(ListChannels::class)
->callAction(CreateAction::class, data: [
'name' => $name = 'my channel',
'color' => '#FFFFFF',
])
->assertHasNoActionErrors()
->assertStatus(200);

$channel = Channel::first();

expect($channel)
->toBeInstanceOf(Channel::class)
->and($channel->name)->toBe($name);
});

it('Admin user can edit channel', function (): void {
$channel = Channel::factory()->create();

Livewire::test(ListChannels::class)
->callTableAction(EditAction::class, $channel, data: [
'name' => 'Edited channel',
])
->assertHasNoTableActionErrors();

$channel->refresh();

expect($channel->name)
->toBe('Edited channel');
});

})->group('channels');
Loading