-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:[LAR-70] Add discussions table in admin cpanel and add feature t… (
#163) Co-authored-by: Chri$ <[email protected]>
- Loading branch information
1 parent
0adffa9
commit 70bb600
Showing
3 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,71 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Filament\Resources; | ||
|
||
use App\Filament\Resources\DiscussionResource\Pages; | ||
use App\Models\Discussion; | ||
use Filament\Resources\Resource; | ||
use Filament\Tables; | ||
use Filament\Tables\Columns\TextColumn; | ||
use Filament\Tables\Filters\Filter; | ||
use Filament\Tables\Table; | ||
use Illuminate\Database\Eloquent\Builder; | ||
|
||
final class DiscussionResource extends Resource | ||
{ | ||
protected static ?string $model = Discussion::class; | ||
|
||
protected static ?string $navigationIcon = 'heroicon-o-chat-bubble-bottom-center-text'; | ||
|
||
public static function table(Table $table): Table | ||
{ | ||
return $table | ||
->columns([ | ||
TextColumn::make('title') | ||
->label('Titre') | ||
->sortable(), | ||
TextColumn::make('locked') | ||
->label('Vérrouillé') | ||
->getStateUsing(fn ($record) => ($record->locked) ? 'Oui' : 'Non') | ||
->colors([ | ||
'success' => 'Oui', | ||
'danger' => 'Non', | ||
]) | ||
->badge(), | ||
TextColumn::make('is_pinned') | ||
->label('Epinglé') | ||
->getStateUsing(fn ($record) => ($record->is_pinned) ? 'Oui' : 'Non') | ||
->colors([ | ||
'success' => 'Oui', | ||
'danger' => 'Non', | ||
]) | ||
->badge(), | ||
TextColumn::make('created_at') | ||
->label('Date de création') | ||
->dateTime(), | ||
TextColumn::make('user.name') | ||
->label('Auteur'), | ||
]) | ||
->filters([ | ||
Filter::make('is_pinned')->query(fn (Builder $query) => $query->where('is_pinned', true))->label('Epinglé'), | ||
Filter::make('is_locked')->query(fn (Builder $query) => $query->where('locked', true))->label('Vérrouillé'), | ||
]) | ||
->actions([ | ||
Tables\Actions\DeleteAction::make(), | ||
]) | ||
->bulkActions([ | ||
Tables\Actions\BulkActionGroup::make([ | ||
Tables\Actions\DeleteBulkAction::make(), | ||
]), | ||
]); | ||
} | ||
|
||
public static function getPages(): array | ||
{ | ||
return [ | ||
'index' => Pages\ListDiscussions::route('/'), | ||
]; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
app/Filament/Resources/DiscussionResource/Pages/ListDiscussions.php
This file contains 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\DiscussionResource\Pages; | ||
|
||
use App\Filament\Resources\DiscussionResource; | ||
use Filament\Resources\Pages\ListRecords; | ||
|
||
final class ListDiscussions extends ListRecords | ||
{ | ||
protected static string $resource = DiscussionResource::class; | ||
} |
This file contains 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,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use App\Filament\Resources\DiscussionResource; | ||
use App\Filament\Resources\DiscussionResource\Pages\ListDiscussions; | ||
use App\Models\Discussion; | ||
use Illuminate\Database\Eloquent\Factories\Sequence; | ||
use Livewire\Livewire; | ||
|
||
beforeEach(function (): void { | ||
$this->user = $this->login(); | ||
$this->discussions = Discussion::factory() | ||
->count(10) | ||
->state(new Sequence( | ||
['is_pinned' => true, 'locked' => false], | ||
['is_pinned' => false, 'locked' => true], | ||
)) | ||
->create(); | ||
}); | ||
|
||
describe(DiscussionResource::class, function (): void { | ||
|
||
it('page can display table with records', function (): void { | ||
Livewire::test(ListDiscussions::class) | ||
->assertCanSeeTableRecords($this->discussions); | ||
}); | ||
|
||
it('admin user can filter discussion by `is_pinned`', function (): void { | ||
Livewire::test(ListDiscussions::class) | ||
->assertCanSeeTableRecords($this->discussions) | ||
->filterTable('is_pinned') | ||
->assertCountTableRecords(5); | ||
}); | ||
|
||
it('admin user can filter discussion by `locked`', function (): void { | ||
Livewire::test(ListDiscussions::class) | ||
->assertCanSeeTableRecords($this->discussions) | ||
->filterTable('is_locked') | ||
->assertCountTableRecords(5); | ||
}); | ||
})->group('discussions'); |