From 6fb54e32f129c3a96f621f2f0c2b785aa3b4a2d4 Mon Sep 17 00:00:00 2001 From: Boy132 Date: Fri, 24 Jan 2025 08:29:07 +0100 Subject: [PATCH] Use tabs instead of filter for server list (#937) * use tabs instead of filter for server list * move "all servers" to end --- .../ServerResource/Pages/ListServers.php | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/app/Filament/App/Resources/ServerResource/Pages/ListServers.php b/app/Filament/App/Resources/ServerResource/Pages/ListServers.php index 8e9ae820b8..e293b4e435 100644 --- a/app/Filament/App/Resources/ServerResource/Pages/ListServers.php +++ b/app/Filament/App/Resources/ServerResource/Pages/ListServers.php @@ -6,10 +6,10 @@ use App\Filament\Components\Tables\Columns\ServerEntryColumn; use App\Filament\Server\Pages\Console; use App\Models\Server; +use Filament\Resources\Components\Tab; use Filament\Resources\Pages\ListRecords; use Filament\Tables\Columns\Layout\Stack; use Filament\Tables\Filters\SelectFilter; -use Filament\Tables\Filters\TernaryFilter; use Filament\Tables\Table; use Illuminate\Database\Eloquent\Builder; @@ -41,21 +41,28 @@ public function table(Table $table): Table ->emptyStateHeading('You don\'t have access to any servers!') ->persistFiltersInSession() ->filters([ - TernaryFilter::make('only_my_servers') - ->label('Owned by') - ->placeholder('All servers') - ->trueLabel('My Servers') - ->falseLabel('Others\' Servers') - ->default() - ->queries( - true: fn (Builder $query) => $query->where('owner_id', auth()->user()->id), - false: fn (Builder $query) => $query->whereNot('owner_id', auth()->user()->id), - blank: fn (Builder $query) => $query, - ), SelectFilter::make('egg') ->relationship('egg', 'name', fn (Builder $query) => $query->whereIn('id', $baseQuery->pluck('egg_id'))) ->searchable() ->preload(), ]); } + + public function getTabs(): array + { + $baseQuery = auth()->user()->accessibleServers(); + + return [ + 'my' => Tab::make('My Servers') + ->badge(fn () => $baseQuery->where('owner_id', auth()->user()->id)->count()) + ->modifyQueryUsing(fn (Builder $query) => $query->where('owner_id', auth()->user()->id)), + + 'other' => Tab::make('Others\' Servers') + ->badge(fn () => $baseQuery->whereNot('owner_id', auth()->user()->id)->count()) + ->modifyQueryUsing(fn (Builder $query) => $query->whereNot('owner_id', auth()->user()->id)), + + 'all' => Tab::make('All Servers') + ->badge($baseQuery->count()), + ]; + } }