diff --git a/app/Form/Actions/UpdateParticipantSearchIndexAction.php b/app/Form/Actions/UpdateParticipantSearchIndexAction.php index 450af0ea..9e6c34b0 100644 --- a/app/Form/Actions/UpdateParticipantSearchIndexAction.php +++ b/app/Form/Actions/UpdateParticipantSearchIndexAction.php @@ -20,7 +20,7 @@ class UpdateParticipantSearchIndexAction [ 'filterableAttributes' => [...$form->getFields()->filterables()->getKeys(), 'parent-id'], 'searchableAttributes' => $form->getFields()->searchables()->getKeys(), - 'sortableAttributes' => [...$form->getFields()->sortables()->getKeys(), 'id'], + 'sortableAttributes' => [...$form->getFields()->sortables()->getKeys(), 'id', 'created_at'], 'displayedAttributes' => [...$form->getFields()->filterables()->getKeys(), ...$form->getFields()->searchables()->getKeys(), 'id'], 'pagination' => [ 'maxTotalHits' => 1000000, diff --git a/app/Form/Models/Participant.php b/app/Form/Models/Participant.php index 96c446ca..1c863539 100644 --- a/app/Form/Models/Participant.php +++ b/app/Form/Models/Participant.php @@ -112,6 +112,6 @@ class Participant extends Model implements Preventable /** @return array */ public function toSearchableArray(): array { - return [...$this->data, 'parent-id' => $this->parent_id]; + return [...$this->data, 'parent-id' => $this->parent_id, 'created_at' => $this->created_at->timestamp]; } } diff --git a/app/Invoice/Actions/InvoiceIndexAction.php b/app/Invoice/Actions/InvoiceIndexAction.php index d64325a5..cb25cf53 100644 --- a/app/Invoice/Actions/InvoiceIndexAction.php +++ b/app/Invoice/Actions/InvoiceIndexAction.php @@ -6,9 +6,9 @@ use Lorisleiva\Actions\Concerns\AsAction; use App\Invoice\Models\Invoice; use App\Invoice\Resources\InvoiceResource; use App\Invoice\Scopes\InvoiceFilterScope; -use Illuminate\Pagination\LengthAwarePaginator; use Inertia\Inertia; use Inertia\Response; +use Laravel\Scout\Builder; use Lorisleiva\Actions\ActionRequest; class InvoiceIndexAction @@ -17,9 +17,9 @@ class InvoiceIndexAction /** - * @return LengthAwarePaginator + * @return Builder */ - public function handle(InvoiceFilterScope $filter) + public function handle(InvoiceFilterScope $filter): Builder { return $filter->getQuery()->query(fn ($q) => $q->with('positions')); } diff --git a/app/Invoice/Models/Invoice.php b/app/Invoice/Models/Invoice.php index 008b789d..fe0c0894 100644 --- a/app/Invoice/Models/Invoice.php +++ b/app/Invoice/Models/Invoice.php @@ -122,15 +122,6 @@ class Invoice extends Model ->where('last_remembered_at', '<=', now()->subWeeks($weeks)); } - /** - * @param Builder $query - * @return Builder - */ - public function scopeWithFilter(Builder $query, InvoiceFilterScope $filter): Builder - { - return $filter->apply($query); - } - public function getMailRecipient(): stdClass { return (object) [ diff --git a/app/Invoice/Scopes/InvoiceFilterScope.php b/app/Invoice/Scopes/InvoiceFilterScope.php index 941f58a3..2d16d992 100644 --- a/app/Invoice/Scopes/InvoiceFilterScope.php +++ b/app/Invoice/Scopes/InvoiceFilterScope.php @@ -12,7 +12,7 @@ use Spatie\LaravelData\Attributes\MapOutputName; use Spatie\LaravelData\Mappers\SnakeCaseMapper; /** - * @extends Filter + * @extends ScoutFilter */ #[MapInputName(SnakeCaseMapper::class)] #[MapOutputName(SnakeCaseMapper::class)] diff --git a/database/migrations/2024_12_16_235710_update_form_searching_2.php b/database/migrations/2024_12_16_235710_update_form_searching_2.php new file mode 100644 index 00000000..4bf13fbb --- /dev/null +++ b/database/migrations/2024_12_16_235710_update_form_searching_2.php @@ -0,0 +1,30 @@ +participants as $participant) { + $participant->searchable(); + } + } + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + // + } +}; diff --git a/tests/EndToEnd/Form/ParticipantIndexActionTest.php b/tests/EndToEnd/Form/ParticipantIndexActionTest.php index 06a0f9c3..9f279b9b 100644 --- a/tests/EndToEnd/Form/ParticipantIndexActionTest.php +++ b/tests/EndToEnd/Form/ParticipantIndexActionTest.php @@ -80,20 +80,23 @@ it('testItShowsEmptyFilters', function () { $this->callFilter('form.participant.index', ['data' => []], ['form' => $form])->assertJsonPath('meta.filter.data.check', ParticipantFilterScope::$nan); }); -it('sorts by active colums sorting by default', function () { +it('sorts by active colums sorting by default', function (array $sorting, string $by, bool $direction) { $this->login()->loginNami()->withoutExceptionHandling(); $form = Form::factory()->fields([ $this->checkboxField('check'), $this->checkboxField('vorname'), ])->create(); - $form->update(['meta' => ['active_columns' => [], 'sorting' => ['by' => 'vorname', 'direction' => true]]]); + $form->update(['meta' => ['active_columns' => [], 'sorting' => $sorting]]); sleep(2); $this->callFilter('form.participant.index', [], ['form' => $form]) ->assertOk() - ->assertJsonPath('meta.filter.sort.by', 'vorname') - ->assertJsonPath('meta.filter.sort.direction', true); -}); + ->assertJsonPath('meta.filter.sort.by', $by) + ->assertJsonPath('meta.filter.sort.direction', $direction); +})->with([ + [['by' => 'vorname', 'direction' => true], 'vorname', true], + [['by' => 'created_at', 'direction' => true], 'created_at', true], +]); it('testItDisplaysHasNamiField', function () {