From 5328edb317d46e780f512a5e1696097dd7030c54 Mon Sep 17 00:00:00 2001 From: Alex Popa Date: Mon, 30 Dec 2024 13:11:27 +0200 Subject: [PATCH] Beneficiary history - filters --- .../Pages/ListBeneficiaryHistories.php | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/app/Filament/Organizations/Resources/BeneficiaryHistoryResource/Pages/ListBeneficiaryHistories.php b/app/Filament/Organizations/Resources/BeneficiaryHistoryResource/Pages/ListBeneficiaryHistories.php index 088ee92e..107fa811 100644 --- a/app/Filament/Organizations/Resources/BeneficiaryHistoryResource/Pages/ListBeneficiaryHistories.php +++ b/app/Filament/Organizations/Resources/BeneficiaryHistoryResource/Pages/ListBeneficiaryHistories.php @@ -7,14 +7,16 @@ use App\Concerns\HasParentResource; use App\Enums\ActivityDescription; use App\Filament\Organizations\Resources\BeneficiaryHistoryResource; +use App\Filters\DateFilter; use App\Models\Activity; use App\Models\Beneficiary; +use App\Models\User; use App\Services\Breadcrumb\BeneficiaryBreadcrumb; use App\Tables\Columns\DateColumn; +use App\Tables\Filters\SelectFilter; use Filament\Resources\Pages\ListRecords; use Filament\Tables\Actions\ViewAction; use Filament\Tables\Columns\TextColumn; -use Filament\Tables\Filters\SelectFilter; use Filament\Tables\Table; use Illuminate\Contracts\Support\Htmlable; use Illuminate\Database\Eloquent\Builder; @@ -51,8 +53,8 @@ public function getTitle(): string|Htmlable public function table(Table $table): Table { return $table - ->query( - fn () => Activity::whereMorphedTo('subject', $this->parent) + ->modifyQueryUsing( + fn (Builder $query) => $query->whereMorphedTo('subject', $this->parent) ->when( ! auth()->user()->hasAccessToAllCases() && ! auth()->user()->isNgoAdmin(), fn (Builder $query) => $query->whereHasMorph( @@ -108,11 +110,14 @@ public function table(Table $table): Table ? $query->where('description', $state['value']) : $query ), - ]); - } - protected function applyFiltersToTableQuery(Builder $query): Builder - { - return $query; + SelectFilter::make('causer_id') + ->label(__('beneficiary.section.history.labels.user')) + ->options(User::getTenantOrganizationUsers()), + + DateFilter::make('created_at') + ->label(__('beneficiary.section.history.labels.date')), + + ]); } }