Skip to content

Commit 7a651c1

Browse files
author
Chri$
committed
feat:[LAR-32] add visible control in make action
1 parent ae7cff7 commit 7a651c1

File tree

2 files changed

+6
-26
lines changed

2 files changed

+6
-26
lines changed

app/Filament/Resources/ArticleResource.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public static function table(Table $table): Table
6565
->actions([
6666
ActionGroup::make([
6767
Action::make('approved')
68+
->visible(fn ($record) => $record->submitted_at && (! $record->declined_at && ! $record->approved_at))
6869
->label('Approuver')
6970
->icon('heroicon-s-check')
7071
->color('success')
@@ -74,10 +75,10 @@ public static function table(Table $table): Table
7475
->modalIcon('heroicon-s-check')
7576
->action(function ($record): void {
7677
$record->approved_at = now();
77-
$record->declined_at = null;
7878
$record->save();
7979
}),
8080
Action::make('declined')
81+
->visible(fn ($record) => $record->submitted_at && (! $record->declined_at && ! $record->approved_at))
8182
->label('Décliner')
8283
->icon('heroicon-s-x-mark')
8384
->color('warning')
@@ -87,32 +88,32 @@ public static function table(Table $table): Table
8788
->modalIcon('heroicon-s-x-mark')
8889
->action(function ($record): void {
8990
$record->declined_at = now();
90-
$record->approved_at = null;
9191
$record->save();
9292
}),
93-
// DeclinedAction::make('declined'),
9493
Tables\Actions\DeleteAction::make('delete'),
9594
]),
9695

9796
])
9897
->bulkActions([
9998
Tables\Actions\BulkActionGroup::make([
10099
BulkAction::make('approved')
100+
->visible(fn (?Collection $records) => ! empty($records) || $records?->contains(fn ($record) => $record->submitted_at))
101101
->label('Approuver la sélection')
102102
->icon('heroicon-s-check')
103103
->color('success')
104-
->action(fn (Collection $records) => $records->each->update(['approved_at' => now(), 'declined_at' => null]))
104+
->action(fn (Collection $records) => $records->each->update(['approved_at' => now()]))
105105
->deselectRecordsAfterCompletion()
106106
->requiresConfirmation()
107107
->modalIcon('heroicon-s-check')
108108
->modalHeading('Approuver')
109109
->modalSubheading('Voulez-vous vraiment approuver ces articles ?')
110110
->modalButton('Confirmer'),
111111
BulkAction::make('declined')
112+
->visible(fn (?Collection $records) => ! empty($records) || $records?->contains(fn ($record) => $record->submitted_at))
112113
->label('Décliner la sélection')
113114
->icon('heroicon-s-x-mark')
114115
->color('warning')
115-
->action(fn (Collection $records) => $records->each->update(['declined_at' => now(), 'approved_at' => null]))
116+
->action(fn (Collection $records) => $records->each->update(['declined_at' => now()]))
116117
->deselectRecordsAfterCompletion()
117118
->requiresConfirmation()
118119
->modalIcon('heroicon-s-x-mark')

tests/Feature/Filament/ArticleTest.php

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -57,25 +57,4 @@
5757
->and($article->approved_at)
5858
->toBe(null);
5959
});
60-
61-
it('admin user can bulk approved articles', function (): void {
62-
$articles = Article::factory()->count(5)->create(['submitted_at' => now()]);
63-
64-
Livewire::test(ArticleResource\Pages\ListArticles::class)
65-
->callTableBulkAction('approved', $articles);
66-
67-
expect(Article::whereNotNull('approved_at')->count())
68-
->toBe(5);
69-
});
70-
71-
it('admin user can bulk declined articles', function (): void {
72-
$articles = Article::factory()->count(5)->create(['submitted_at' => now()]);
73-
74-
Livewire::test(ArticleResource\Pages\ListArticles::class)
75-
->callTableBulkAction('declined', $articles);
76-
77-
expect(Article::whereNotNull('declined_at')->count())
78-
->toBe(5);
79-
});
80-
8160
})->group('articles');

0 commit comments

Comments
 (0)