From 6661b643578911b424eee40d3e7a73e1ad3ed67f Mon Sep 17 00:00:00 2001 From: Chri$ Date: Fri, 8 Nov 2024 04:03:58 +0100 Subject: [PATCH 1/7] feat:[LAR-33] Add filament channel crud in cpanel with feature test --- app/Filament/Resources/ChannelResource.php | 98 +++++++++++++++++++ .../ChannelResource/Pages/CreateChannel.php | 13 +++ .../ChannelResource/Pages/EditChannel.php | 21 ++++ .../ChannelResource/Pages/ListChannels.php | 21 ++++ tests/Feature/Filament/ChannelTest.php | 52 ++++++++++ 5 files changed, 205 insertions(+) create mode 100644 app/Filament/Resources/ChannelResource.php create mode 100644 app/Filament/Resources/ChannelResource/Pages/CreateChannel.php create mode 100644 app/Filament/Resources/ChannelResource/Pages/EditChannel.php create mode 100644 app/Filament/Resources/ChannelResource/Pages/ListChannels.php create mode 100644 tests/Feature/Filament/ChannelTest.php diff --git a/app/Filament/Resources/ChannelResource.php b/app/Filament/Resources/ChannelResource.php new file mode 100644 index 00000000..f4b4374d --- /dev/null +++ b/app/Filament/Resources/ChannelResource.php @@ -0,0 +1,98 @@ +schema([ + Forms\Components\TextInput::make('name') + ->required() + ->live(onBlur: true) + ->afterStateUpdated(function (Get $get, Set $set, ?string $old, ?string $state): void { + if (($get('slug') ?? '') !== Str::slug($old)) { + return; + } + + $set('slug', Str::slug($state)); + }), + Forms\Components\TextInput::make('slug') + ->required(), + Forms\Components\Select::make('parent_id') + ->relationship('parent', 'name', modifyQueryUsing: fn (Builder $query) => $query->whereNull('parent_id')) + ->default(null), + Forms\Components\TextInput::make('color') + ->maxLength(255) + ->type('color'), + ]); + } + + 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('color') + ->searchable(), + Tables\Columns\TextColumn::make('created_at') + ->dateTime() + ->sortable() + ->toggleable(isToggledHiddenByDefault: true), + Tables\Columns\TextColumn::make('updated_at') + ->dateTime() + ->sortable() + ->toggleable(isToggledHiddenByDefault: true), + ]) + ->filters([ + // + ]) + ->actions([ + ActionGroup::make([ + Tables\Actions\DeleteAction::make(), + Tables\Actions\EditAction::make() + ->color('warning'), + ]), + ]) + ->bulkActions([ + Tables\Actions\BulkActionGroup::make([ + Tables\Actions\DeleteBulkAction::make(), + ]), + ]); + } + + public static function getPages(): array + { + return [ + 'index' => Pages\ListChannels::route('/'), + 'create' => Pages\CreateChannel::route('/create'), + 'edit' => Pages\EditChannel::route('/{record}/edit'), + ]; + } +} diff --git a/app/Filament/Resources/ChannelResource/Pages/CreateChannel.php b/app/Filament/Resources/ChannelResource/Pages/CreateChannel.php new file mode 100644 index 00000000..79f60896 --- /dev/null +++ b/app/Filament/Resources/ChannelResource/Pages/CreateChannel.php @@ -0,0 +1,13 @@ +user = $this->login(); + $this->channels = Channel::factory() + ->count(10) + ->create(); +}); + +describe(ChannelResource::class, function (): void { + + it('page can display table with records', function (): void { + Livewire::test(ListChannels::class) + ->assertCanSeeTableRecords($this->channels); + }); + + it('Admin user can create channel', function (): void { + $name = 'my channel'; + + Livewire::test(CreateChannel::class) + ->fillForm([ + 'name' => $name, + 'color' => '#FFFFFF', + ]) + ->call('create'); + }); + + 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'); From ee78ed91d2d5fd22a5f026e82157dd78584203f7 Mon Sep 17 00:00:00 2001 From: Chri$ Date: Fri, 8 Nov 2024 20:13:18 +0100 Subject: [PATCH 2/7] feat: [LAR-33] Remove Edit and Page and add SliveOver , Add Channel description , remove blank space and add thread number columns and Edit create Test --- app/Filament/Resources/ChannelResource.php | 62 ++++++++++--------- .../ChannelResource/Pages/CreateChannel.php | 13 ---- .../ChannelResource/Pages/EditChannel.php | 21 ------- .../ChannelResource/Pages/ListChannels.php | 5 +- tests/Feature/Filament/ChannelTest.php | 28 +++++---- 5 files changed, 54 insertions(+), 75 deletions(-) delete mode 100644 app/Filament/Resources/ChannelResource/Pages/CreateChannel.php delete mode 100644 app/Filament/Resources/ChannelResource/Pages/EditChannel.php diff --git a/app/Filament/Resources/ChannelResource.php b/app/Filament/Resources/ChannelResource.php index f4b4374d..8cf56117 100644 --- a/app/Filament/Resources/ChannelResource.php +++ b/app/Filament/Resources/ChannelResource.php @@ -8,9 +8,8 @@ use App\Models\Channel; use Filament\Forms; use Filament\Forms\Form; -use Filament\Forms\Get; -use Filament\Forms\Set; use Filament\Resources\Resource; +use Filament\Support\Enums\MaxWidth; use Filament\Tables; use Filament\Tables\Actions\ActionGroup; use Filament\Tables\Table; @@ -23,28 +22,37 @@ final class ChannelResource extends Resource 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\TextInput::make('name') - ->required() - ->live(onBlur: true) - ->afterStateUpdated(function (Get $get, Set $set, ?string $old, ?string $state): void { - if (($get('slug') ?? '') !== Str::slug($old)) { - return; - } - - $set('slug', Str::slug($state)); - }), - Forms\Components\TextInput::make('slug') - ->required(), - Forms\Components\Select::make('parent_id') - ->relationship('parent', 'name', modifyQueryUsing: fn (Builder $query) => $query->whereNull('parent_id')) - ->default(null), - Forms\Components\TextInput::make('color') - ->maxLength(255) - ->type('color'), + 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]), ]); } @@ -59,25 +67,25 @@ public static function table(Table $table): Table 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), - Tables\Columns\TextColumn::make('updated_at') - ->dateTime() - ->sortable() - ->toggleable(isToggledHiddenByDefault: true), ]) ->filters([ - // + ]) ->actions([ ActionGroup::make([ Tables\Actions\DeleteAction::make(), Tables\Actions\EditAction::make() - ->color('warning'), + ->slideOver() + ->modalWidth(MaxWidth::Large), ]), ]) ->bulkActions([ @@ -91,8 +99,6 @@ public static function getPages(): array { return [ 'index' => Pages\ListChannels::route('/'), - 'create' => Pages\CreateChannel::route('/create'), - 'edit' => Pages\EditChannel::route('/{record}/edit'), ]; } } diff --git a/app/Filament/Resources/ChannelResource/Pages/CreateChannel.php b/app/Filament/Resources/ChannelResource/Pages/CreateChannel.php deleted file mode 100644 index 79f60896..00000000 --- a/app/Filament/Resources/ChannelResource/Pages/CreateChannel.php +++ /dev/null @@ -1,13 +0,0 @@ -slideOver() + ->modalWidth(MaxWidth::Large), ]; } } diff --git a/tests/Feature/Filament/ChannelTest.php b/tests/Feature/Filament/ChannelTest.php index cf92bdd6..70b8a29a 100644 --- a/tests/Feature/Filament/ChannelTest.php +++ b/tests/Feature/Filament/ChannelTest.php @@ -3,35 +3,39 @@ declare(strict_types=1); use App\Filament\Resources\ChannelResource; -use App\Filament\Resources\ChannelResource\Pages\CreateChannel; 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(); - $this->channels = Channel::factory() - ->count(10) - ->create(); }); 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($this->channels); + ->assertCanSeeTableRecords($channels); }); it('Admin user can create channel', function (): void { - $name = 'my channel'; - - Livewire::test(CreateChannel::class) - ->fillForm([ - 'name' => $name, + Livewire::test(ListChannels::class) + ->callAction(CreateAction::class, data: [ + 'name' => $name = 'my channel', 'color' => '#FFFFFF', ]) - ->call('create'); + ->assertHasNoActionErrors() + ->assertStatus(200); + + $channel = Channel::first(); + + expect($channel) + ->toBeInstanceOf(Channel::class) + ->and($channel->name)->toBe($name); }); it('Admin user can edit channel', function (): void { From 78392758650521d8f4fd9829c5997c5e6c207023 Mon Sep 17 00:00:00 2001 From: Stevy Endaman Date: Fri, 8 Nov 2024 08:37:04 +0100 Subject: [PATCH 3/7] feat: (LAR-20) add xp to dashboard user (#202) --- resources/views/components/user/stats.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/components/user/stats.blade.php b/resources/views/components/user/stats.blade.php index 898b784f..c963e792 100644 --- a/resources/views/components/user/stats.blade.php +++ b/resources/views/components/user/stats.blade.php @@ -44,7 +44,7 @@ {{ __('pages/account.dashboard.stats.experience') }}
- 0 + {{ $user->getPoints() }}