-
-
Notifications
You must be signed in to change notification settings - Fork 15
feat:[LAR-32] Add article list with action in cpanel #160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mckenziearts
merged 6 commits into
develop
from
feature/lar-32-admin-filament-listing-des-articles
Oct 21, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7b8a253
feat:[LAR-32] Add article list wit action in cpanl
63e70df
refactor:[LAR-32] integrate review comment
ae7cff7
refactor:[LAR-32] Remove action class(Approved and Declined) , Add fi…
7a651c1
feat:[LAR-32] add visible control in make action
fbbeec4
fix:[LAR-32] remove unwork function to fix phpstan error
197d693
feat:[LAR-32]replace inline condition with model function , delete un…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Filament\Resources; | ||
|
||
use App\Filament\Resources\ArticleResource\Pages; | ||
use App\Models\Article; | ||
use Filament\Resources\Resource; | ||
use Filament\Tables; | ||
use Filament\Tables\Actions\Action; | ||
use Filament\Tables\Actions\ActionGroup; | ||
use Filament\Tables\Actions\BulkAction; | ||
use Filament\Tables\Columns\TextColumn; | ||
use Filament\Tables\Filters\Filter; | ||
use Filament\Tables\Table; | ||
use Illuminate\Database\Eloquent\Builder; | ||
use Illuminate\Database\Eloquent\Collection; | ||
|
||
final class ArticleResource extends Resource | ||
{ | ||
protected static ?string $model = Article::class; | ||
|
||
protected static ?string $navigationIcon = 'heroicon-o-newspaper'; | ||
|
||
public static function table(Table $table): Table | ||
{ | ||
return $table | ||
->columns([ | ||
TextColumn::make('title') | ||
->label('Titre') | ||
->sortable(), | ||
TextColumn::make('status') | ||
->getStateUsing(function ($record) { | ||
if ($record->approved_at) { | ||
return 'Approuver'; | ||
} elseif ($record->declined_at) { | ||
return 'Décliner'; | ||
} elseif ($record->submitted_at) { | ||
return 'Soumis'; | ||
} else { | ||
return 'Brouillon'; | ||
} | ||
}) | ||
->colors([ | ||
'success' => 'Approuver', | ||
'danger' => 'Décliner', | ||
'warning' => 'Soumis', | ||
'default' => 'Brouillon', | ||
]) | ||
->badge(), | ||
TextColumn::make('submitted_at') | ||
->label('Date de soumission') | ||
->dateTime(), | ||
TextColumn::make('user.name') | ||
->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'), | ||
]) | ||
|
||
->actions([ | ||
ActionGroup::make([ | ||
Action::make('approved') | ||
->visible(fn (Article $record) => $record->isAwaitingApproval()) | ||
->label('Approuver') | ||
->icon('heroicon-s-check') | ||
->color('success') | ||
->modalHeading(__('Voulez vous approuver cet article')) | ||
->successNotificationTitle(__('Opération effectuée avec succès')) | ||
->requiresConfirmation() | ||
->modalIcon('heroicon-s-check') | ||
->action(function ($record): void { | ||
$record->approved_at = now(); | ||
$record->save(); | ||
}), | ||
Action::make('declined') | ||
->visible(fn (Article $record) => $record->isAwaitingApproval()) | ||
->label('Décliner') | ||
->icon('heroicon-s-x-mark') | ||
->color('warning') | ||
->modalHeading(__('Voulez vous décliner cet article')) | ||
->successNotificationTitle(__('Opération effectuée avec succès')) | ||
->requiresConfirmation() | ||
->modalIcon('heroicon-s-x-mark') | ||
->action(function ($record): void { | ||
$record->declined_at = now(); | ||
$record->save(); | ||
}), | ||
Tables\Actions\DeleteAction::make('delete'), | ||
]), | ||
|
||
]) | ||
->bulkActions([ | ||
Tables\Actions\BulkActionGroup::make([ | ||
BulkAction::make('approved') | ||
->label('Approuver la sélection') | ||
->icon('heroicon-s-check') | ||
->color('success') | ||
->action(fn (Collection $records) => $records->each->update(['approved_at' => now()])) | ||
->deselectRecordsAfterCompletion() | ||
->requiresConfirmation() | ||
->modalIcon('heroicon-s-check') | ||
->modalHeading('Approuver') | ||
->modalSubheading('Voulez-vous vraiment approuver ces articles ?') | ||
->modalButton('Confirmer'), | ||
BulkAction::make('declined') | ||
->label('Décliner la sélection') | ||
->icon('heroicon-s-x-mark') | ||
->color('warning') | ||
->action(fn (Collection $records) => $records->each->update(['declined_at' => now()])) | ||
->deselectRecordsAfterCompletion() | ||
->requiresConfirmation() | ||
->modalIcon('heroicon-s-x-mark') | ||
->modalHeading('Décliner') | ||
->modalSubheading('Voulez-vous vraiment décliner ces articles ?') | ||
->modalButton('Confirmer'), | ||
|
||
Tables\Actions\DeleteBulkAction::make(), | ||
]), | ||
]); | ||
} | ||
|
||
public static function getPages(): array | ||
{ | ||
return [ | ||
'index' => Pages\ListArticles::route('/'), | ||
]; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
app/Filament/Resources/ArticleResource/Pages/ListArticles.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Filament\Resources\ArticleResource\Pages; | ||
|
||
use App\Filament\Resources\ArticleResource; | ||
use Filament\Resources\Pages\ListRecords; | ||
|
||
final class ListArticles extends ListRecords | ||
{ | ||
protected static string $resource = ArticleResource::class; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use App\Filament\Resources\ArticleResource; | ||
use App\Models\Article; | ||
use Livewire\Livewire; | ||
|
||
beforeEach(function (): void { | ||
$this->user = $this->login(); | ||
$this->articles = Article::factory()->count(10)->create([ | ||
'submitted_at' => now(), | ||
]); | ||
}); | ||
|
||
describe(ArticleResource::class, function (): void { | ||
|
||
it('page can display table with records', function (): void { | ||
Livewire::test(ArticleResource\Pages\ListArticles::class) | ||
->assertCanSeeTableRecords($this->articles); | ||
}); | ||
|
||
it('admin user can approved article', function (): void { | ||
$article = $this->articles->first(); | ||
|
||
Livewire::test(ArticleResource\Pages\ListArticles::class) | ||
->callTableAction('approved', $article); | ||
|
||
$article->refresh(); | ||
|
||
expect($article->approved_at) | ||
->not | ||
->toBe(null) | ||
->and($article->declined_at) | ||
->toBe(null); | ||
cybersoldattech marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Livewire::test(ArticleResource\Pages\ListArticles::class) | ||
->assertTableActionHidden('approved', $article) | ||
->assertTableActionHidden('declined', $article); | ||
}); | ||
|
||
it('admin user can declined article', function (): void { | ||
$article = $this->articles->first(); | ||
|
||
Livewire::test(ArticleResource\Pages\ListArticles::class) | ||
->callTableAction('declined', $article); | ||
|
||
$article->refresh(); | ||
|
||
expect($article->declined_at) | ||
->not | ||
->toBe(null) | ||
->and($article->approved_at) | ||
->toBe(null); | ||
|
||
Livewire::test(ArticleResource\Pages\ListArticles::class) | ||
->assertTableActionHidden('approved', $article) | ||
->assertTableActionHidden('declined', $article); | ||
|
||
}); | ||
cybersoldattech marked this conversation as resolved.
Show resolved
Hide resolved
|
||
})->group('articles'); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.