-
-
Notifications
You must be signed in to change notification settings - Fork 15
feat:[LAR-70] Add discussions table in admin cpanel and add feature t… #163
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 4 commits into
develop
from
feature/lar-70-admin-filament-listing-de-discussion
Oct 22, 2024
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d32ce5b
feat:[LAR-70] Add discussions table in admin cpanel and add feature t…
b553afc
feat:[LAR-70]Add label in text input,remove space in files and add co…
11f4165
feat:[LAR-70] Replace uppercase word and remove parameter name
bb75c79
feat:[LAR-70] Replace uppercase word and remove parameter name
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,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 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\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 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,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'); |
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.