-
Notifications
You must be signed in to change notification settings - Fork 17
feat:[LAR-31] Add filament thread table in cpanel #169
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
cybersoldattech
merged 5 commits into
main
from
feature/lar-31-admin-filament-listing-des-threads
Nov 1, 2024
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b28fe02
feat:[LAR-31] Add filament thread table in cpanel
4167ff5
feat:[LAR-31] set icon in table and add redirect to thread action
35ba3e8
feat:[LAR-31] Change view action ,remove author filter and add channe…
b64749b
feat:[LAR-31] Remove unworke test
5798f25
feat:[LAR-31] Remove unworke test
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,64 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Filament\Resources; | ||
|
|
||
| use App\Filament\Resources\ThreadResource\Pages; | ||
| use App\Models\Thread; | ||
| use Filament\Resources\Resource; | ||
| use Filament\Tables; | ||
| use Filament\Tables\Columns\TextColumn; | ||
| use Filament\Tables\Filters\Filter; | ||
| use Filament\Tables\Filters\SelectFilter; | ||
| use Filament\Tables\Table; | ||
| use Illuminate\Database\Eloquent\Builder; | ||
|
|
||
| final class ThreadResource extends Resource | ||
| { | ||
| protected static ?string $model = Thread::class; | ||
|
|
||
| protected static ?string $navigationIcon = 'heroicon-o-chat-bubble-left-right'; | ||
|
|
||
| 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('created_at') | ||
| ->label('Date de publication') | ||
| ->dateTime(), | ||
| TextColumn::make('user.name') | ||
| ->label('Auteur'), | ||
| ]) | ||
| ->filters([ | ||
| Filter::make('is_locked')->query(fn (Builder $query) => $query->where('locked', true))->label('Vérrouillé'), | ||
cybersoldattech marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| SelectFilter::make('Auteur')->relationship('user', 'name')->searchable()->preload(), | ||
cybersoldattech marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ]) | ||
| ->actions([ | ||
| Tables\Actions\DeleteAction::make(), | ||
cybersoldattech marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ]) | ||
| ->bulkActions([ | ||
| Tables\Actions\BulkActionGroup::make([ | ||
| Tables\Actions\DeleteBulkAction::make(), | ||
| ]), | ||
| ]); | ||
| } | ||
|
|
||
| public static function getPages(): array | ||
| { | ||
| return [ | ||
| 'index' => Pages\ListThreads::route('/'), | ||
| ]; | ||
| } | ||
| } | ||
13 changes: 13 additions & 0 deletions
13
app/Filament/Resources/ThreadResource/Pages/ListThreads.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\ThreadResource\Pages; | ||
|
|
||
| use App\Filament\Resources\ThreadResource; | ||
| use Filament\Resources\Pages\ListRecords; | ||
|
|
||
| final class ListThreads extends ListRecords | ||
| { | ||
| protected static string $resource = ThreadResource::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
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 | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Tests\Feature\Filament; | ||
|
|
||
| use App\Filament\Resources\ThreadResource; | ||
| use App\Filament\Resources\ThreadResource\Pages\ListThreads; | ||
| use App\Models\Thread; | ||
| use Illuminate\Database\Eloquent\Factories\Sequence; | ||
| use Livewire\Livewire; | ||
|
|
||
| beforeEach(function (): void { | ||
| $this->user = $this->login(); | ||
| $this->ActingAs($this->user); | ||
| $this->threads = Thread::factory()->count(10)->state( | ||
| new Sequence( | ||
| ['locked' => false], | ||
| ['locked' => true] | ||
| ) | ||
| ) | ||
| ->create(); | ||
| }); | ||
|
|
||
| describe(ThreadResource::class, function (): void { | ||
|
|
||
| it('page can display table with records', function (): void { | ||
| Livewire::test(ThreadResource\Pages\ListThreads::class) | ||
| ->assertCanSeeTableRecords($this->threads); | ||
| }); | ||
|
|
||
| it('admin user can filter thread by `locked`', function (): void { | ||
| Livewire::test(ListThreads::class) | ||
| ->assertCanSeeTableRecords($this->threads) | ||
| ->filterTable('is_locked') | ||
| ->assertCountTableRecords(5); | ||
| }); | ||
|
|
||
| it('can filter thread by `user_id`', function (): void { | ||
| $authorId = $this->threads->first()->user_id; | ||
| Livewire::test(ListThreads::class) | ||
| ->assertCanSeeTableRecords($this->threads) | ||
| ->filterTable('Auteur', $authorId) | ||
| ->assertCanSeeTableRecords($this->threads->where('user_id', $authorId)) | ||
| ->assertCanNotSeeTableRecords($this->threads->where('user_id', '!=', $authorId)); | ||
| }); | ||
|
|
||
| })->group('threads'); |
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.