Skip to content

Commit

Permalink
Use tabs instead of filter for server list (#937)
Browse files Browse the repository at this point in the history
* use tabs instead of filter for server list

* move "all servers" to end
  • Loading branch information
Boy132 authored Jan 24, 2025
1 parent fef19b9 commit 6fb54e3
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions app/Filament/App/Resources/ServerResource/Pages/ListServers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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()),
];
}
}

0 comments on commit 6fb54e3

Please sign in to comment.