From 79eebde010a2766c9724d6afd937bf977abafc7a Mon Sep 17 00:00:00 2001 From: cybersoldattech Date: Tue, 15 Oct 2024 22:13:42 +0000 Subject: [PATCH] Fix code styling --- app/Filament/Actions/ApprovedAction.php | 10 ++-- app/Filament/Actions/DeclinedAction.php | 10 ++-- app/Filament/Clusters/Articles.php | 4 +- app/Filament/Resources/ArticleResource.php | 59 ++++++++++--------- .../ArticleResource/Pages/ListArticles.php | 6 +- app/Models/Article.php | 3 - tests/Feature/Filament/ArticleTest.php | 15 ++--- 7 files changed, 54 insertions(+), 53 deletions(-) diff --git a/app/Filament/Actions/ApprovedAction.php b/app/Filament/Actions/ApprovedAction.php index f7c8121b..98788028 100644 --- a/app/Filament/Actions/ApprovedAction.php +++ b/app/Filament/Actions/ApprovedAction.php @@ -1,14 +1,16 @@ color('success'); - $this->icon( 'heroicon-s-x-mark'); + $this->icon('heroicon-s-x-mark'); $this->requiresConfirmation(); @@ -37,7 +39,7 @@ protected function setUp(): void $this->action(function (): void { $result = $this->process(static fn (Model $record) => $record->update(['approved_at' => now(), 'declined_at' => null])); - if (! $result) { + if ( ! $result) { $this->failure(); return; diff --git a/app/Filament/Actions/DeclinedAction.php b/app/Filament/Actions/DeclinedAction.php index ae68a0e1..cd7abc3d 100644 --- a/app/Filament/Actions/DeclinedAction.php +++ b/app/Filament/Actions/DeclinedAction.php @@ -1,14 +1,16 @@ color('warning'); - $this->icon( 'heroicon-s-check'); + $this->icon('heroicon-s-check'); $this->requiresConfirmation(); @@ -37,7 +39,7 @@ protected function setUp(): void $this->action(function (): void { $result = $this->process(static fn (Model $record) => $record->update(['declined_at' => now(), 'approved_at' => null])); - if (! $result) { + if ( ! $result) { $this->failure(); return; diff --git a/app/Filament/Clusters/Articles.php b/app/Filament/Clusters/Articles.php index c1500920..a7f054c9 100644 --- a/app/Filament/Clusters/Articles.php +++ b/app/Filament/Clusters/Articles.php @@ -1,10 +1,12 @@ columns([ TextColumn::make('title') - ->label('Titre') - ->sortable(), + ->label('Titre') + ->sortable(), TextColumn::make('status') - ->label('Status') - ->getStateUsing(function ($record) { - if ($record->approved_at) { - return 'Approuver'; - } elseif ($record->declined_at) { - return 'Décliner'; - } elseif($record->submitted_at) { - return 'Soumis'; - } - }) - ->colors([ - 'success' => 'Approuver', - 'danger' => 'Décliner', - 'warning' => 'Soumis', - ]) - ->badge(), + ->label('Status') + ->getStateUsing(function ($record) { + if ($record->approved_at) { + return 'Approuver'; + } elseif ($record->declined_at) { + return 'Décliner'; + } elseif ($record->submitted_at) { + return 'Soumis'; + } + }) + ->colors([ + 'success' => 'Approuver', + 'danger' => 'Décliner', + 'warning' => 'Soumis', + ]) + ->badge(), TextColumn::make('submitted_at') - ->label('Date de soumission') - ->dateTime(), + ->label('Date de soumission') + ->dateTime(), TextColumn::make('user.name') - ->label('Auteur') - ->sortable() + ->label('Auteur') + ->sortable(), ]) ->filters([ - Filter::make('submitted_at')->query( fn (Builder $query) => $query->whereNotNull('submitted_at'))->label('Soumis'), - Filter::make('declined_at')->query( fn (Builder $query) => $query->whereNotNull('declined_at'))->label('Décliner'), - Filter::make('approved_at')->query( fn (Builder $query) => $query->whereNotNull('approved_at'))->label('Approuver') + Filter::make('submitted_at')->query(fn (Builder $query) => $query->whereNotNull('submitted_at'))->label('Soumis'), + Filter::make('declined_at')->query(fn (Builder $query) => $query->whereNotNull('declined_at'))->label('Décliner'), + Filter::make('approved_at')->query(fn (Builder $query) => $query->whereNotNull('approved_at'))->label('Approuver'), ]) ->actions([ diff --git a/app/Filament/Resources/ArticleResource/Pages/ListArticles.php b/app/Filament/Resources/ArticleResource/Pages/ListArticles.php index 6cde6e3b..9290dcd3 100644 --- a/app/Filament/Resources/ArticleResource/Pages/ListArticles.php +++ b/app/Filament/Resources/ArticleResource/Pages/ListArticles.php @@ -1,13 +1,13 @@ belongsTo(User::class); } - - public function excerpt(int $limit = 110): string { return Str::limit(strip_tags((string) md_to_html($this->body)), $limit); diff --git a/tests/Feature/Filament/ArticleTest.php b/tests/Feature/Filament/ArticleTest.php index 4959964a..e2bf54ef 100644 --- a/tests/Feature/Filament/ArticleTest.php +++ b/tests/Feature/Filament/ArticleTest.php @@ -2,8 +2,6 @@ declare(strict_types=1); -use App\Filament\Actions\ApprovedAction; -use App\Filament\Actions\DeclinedAction; use App\Filament\Resources\ArticleResource; use App\Models\Article; use Filament\Tables\Actions\DeleteAction; @@ -12,18 +10,18 @@ beforeEach(function (): void { $this->user = $this->login(); $this->articles = Article::factory()->count(10)->create([ - 'submitted_at' => now() + 'submitted_at' => now(), ]); }); describe(ArticleResource::class, function (): void { - it('page can display table with records', function () { + it('page can display table with records', function (): void { Livewire::test(ArticleResource\Pages\ListArticles::class) ->assertCanSeeTableRecords($this->articles); }); - it('table can render columns', function () { + it('table can render columns', function (): void { Livewire::test(ArticleResource\Pages\ListArticles::class) ->assertCanRenderTableColumn('title') ->assertCanRenderTableColumn('status') @@ -31,7 +29,7 @@ ->assertCanRenderTableColumn('submitted_at'); }); - it('admin user can approved article', function () { + it('admin user can approved article', function (): void { $article = Article::factory()->create(['submitted_at' => now()]); Livewire::test(ArticleResource\Pages\ListArticles::class) @@ -47,12 +45,11 @@ ->toBe(null); }); - - it('admin user can declined article', function () { + it('admin user can declined article', function (): void { $article = Article::factory()->create(['submitted_at' => now()]); Livewire::test(ArticleResource\Pages\ListArticles::class) - ->callTableAction('declined', $article); + ->callTableAction('declined', $article); $article->refresh();