-
-
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 1 commit
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,48 @@ | ||
<?php | ||
|
||
namespace App\Filament\Actions; | ||
|
||
use Filament\Actions\Concerns\CanCustomizeProcess; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class ApprovedAction extends \Filament\Tables\Actions\Action | ||
{ | ||
use CanCustomizeProcess; | ||
cybersoldattech marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public static function getDefaultName(): ?string | ||
{ | ||
return 'approved'; | ||
} | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->label(__('Approuver')); | ||
|
||
$this->modalHeading(fn (): string => __('Voulez vous approuver cet article', ['label' => $this->getRecordTitle()])); | ||
|
||
$this->modalSubmitActionLabel(__('Approuver')); | ||
|
||
$this->successNotificationTitle(__('Opération effectuée avec succès')); | ||
|
||
$this->color('success'); | ||
|
||
$this->icon( 'heroicon-s-check'); | ||
|
||
$this->requiresConfirmation(); | ||
|
||
$this->modalIcon('heroicon-s-check'); | ||
|
||
$this->action(function (): void { | ||
$result = $this->process(static fn (Model $record) => $record->update(['approved_at' => now(), 'declined_at' => null])); | ||
|
||
if (! $result) { | ||
$this->failure(); | ||
|
||
return; | ||
} | ||
|
||
$this->success(); | ||
}); | ||
} | ||
} |
cybersoldattech marked this conversation as resolved.
Show resolved
Hide resolved
|
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,49 @@ | ||
<?php | ||
|
||
namespace App\Filament\Actions; | ||
|
||
use Filament\Actions\Concerns\CanCustomizeProcess; | ||
use Filament\Support\Facades\FilamentIcon; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class DeclinedAction extends \Filament\Tables\Actions\Action | ||
{ | ||
use CanCustomizeProcess; | ||
cybersoldattech marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public static function getDefaultName(): ?string | ||
{ | ||
return 'declined'; | ||
} | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->label(__('Décliner')); | ||
|
||
$this->modalHeading(fn (): string => __('Voulez vous décliner cet article', ['label' => $this->getRecordTitle()])); | ||
|
||
$this->modalSubmitActionLabel(__('Décliner')); | ||
|
||
$this->successNotificationTitle(__('Opération effectuée avec succès')); | ||
|
||
$this->color('warning'); | ||
|
||
$this->icon( 'heroicon-s-x-mark'); | ||
|
||
$this->requiresConfirmation(); | ||
|
||
$this->modalIcon('heroicon-s-x-mark'); | ||
|
||
$this->action(function (): void { | ||
$result = $this->process(static fn (Model $record) => $record->update(['declined_at' => now(), 'approved_at' => null])); | ||
|
||
if (! $result) { | ||
$this->failure(); | ||
|
||
return; | ||
} | ||
|
||
$this->success(); | ||
}); | ||
} | ||
} |
cybersoldattech marked this conversation as resolved.
Show resolved
Hide resolved
|
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,10 @@ | ||
<?php | ||
|
||
namespace App\Filament\Clusters; | ||
|
||
use Filament\Clusters\Cluster; | ||
|
||
class Articles extends Cluster | ||
{ | ||
protected static ?string $navigationIcon = 'heroicon-o-squares-2x2'; | ||
cybersoldattech marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
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,83 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources; | ||
|
||
use App\Filament\Actions\ApprovedAction; | ||
use App\Filament\Actions\DeclinedAction; | ||
use App\Filament\Resources\ArticleResource\Pages; | ||
use App\Models\Article; | ||
use Filament\Resources\Resource; | ||
use Filament\Tables; | ||
use Filament\Tables\Columns\TextColumn; | ||
use Filament\Tables\Table; | ||
use Filament\Tables\Filters\Filter; | ||
use Illuminate\Database\Eloquent\Builder; | ||
use Filament\Tables\Actions\ActionGroup; | ||
|
||
class ArticleResource extends Resource | ||
{ | ||
protected static ?string $model = Article::class; | ||
|
||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack'; | ||
public static function table(Table $table): Table | ||
{ | ||
return $table | ||
->columns([ | ||
TextColumn::make('title') | ||
->label('Titre') | ||
->sortable(), | ||
TextColumn::make('status') | ||
->label('Status') | ||
cybersoldattech marked this conversation as resolved.
Show resolved
Hide resolved
|
||
->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([ | ||
ApprovedAction::make('approved'), | ||
DeclinedAction::make('declined'), | ||
Tables\Actions\DeleteAction::make('delete'), | ||
]), | ||
|
||
]) | ||
->bulkActions([ | ||
Tables\Actions\BulkActionGroup::make([ | ||
Tables\Actions\DeleteBulkAction::make(), | ||
]), | ||
]); | ||
} | ||
|
||
public static function getPages(): array | ||
{ | ||
return [ | ||
'index' => Pages\ListArticles::route('/'), | ||
]; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
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,19 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\ArticleResource\Pages; | ||
|
||
use App\Filament\Resources\ArticleResource; | ||
use Filament\Actions; | ||
use Filament\Resources\Pages\ListRecords; | ||
|
||
class ListArticles extends ListRecords | ||
{ | ||
protected static string $resource = ArticleResource::class; | ||
|
||
protected function getHeaderActions(): array | ||
cybersoldattech marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
return [ | ||
|
||
]; | ||
} | ||
} |
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
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,74 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use App\Filament\Resources\ArticleResource; | ||
use Filament\Tables\Actions\DeleteAction; | ||
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('table can render columns', function (): void { | ||
cybersoldattech marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Livewire::test(ArticleResource\Pages\ListArticles::class) | ||
->assertCanRenderTableColumn('title') | ||
->assertCanRenderTableColumn('status') | ||
->assertCanRenderTableColumn('status') | ||
->assertCanRenderTableColumn('submitted_at'); | ||
}); | ||
|
||
it('admin user can approved article', function (): void { | ||
cybersoldattech marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$article = Article::factory()->create(['submitted_at' => now()]); | ||
cybersoldattech marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Livewire::test(ArticleResource\Pages\ListArticles::class) | ||
->callTableAction('approved', $article); | ||
|
||
$article->refresh(); | ||
|
||
expect($article->approved_at) | ||
->not | ||
->toBe(null); | ||
cybersoldattech marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
expect($article->declined_at) | ||
->toBe(null); | ||
cybersoldattech marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
|
||
it('admin user can declined article', function (): void { | ||
$article = Article::factory()->create(['submitted_at' => now()]); | ||
|
||
Livewire::test(ArticleResource\Pages\ListArticles::class) | ||
->callTableAction('declined', $article); | ||
|
||
$article->refresh(); | ||
|
||
expect($article->declined_at) | ||
->not | ||
->toBe(null); | ||
|
||
expect($article->approved_at) | ||
->toBe(null); | ||
}); | ||
cybersoldattech marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// it('admin user can deleted article', function () { | ||
cybersoldattech marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// $article = Article::factory()->create(['submitted_at' => now()]); | ||
|
||
// Livewire::test(ArticleResource\Pages\ListArticles::class) | ||
// ->callTableAction('delete', $article); | ||
// //->callAction(DeleteAction::class); | ||
|
||
// expect(Article::find($article->id)) | ||
// ->toBe(null); | ||
// }); | ||
})->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.