Fix: Sort participants by created_at
This commit is contained in:
parent
784b49c3dd
commit
a456cc1889
|
@ -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,
|
||||
|
|
|
@ -112,6 +112,6 @@ class Participant extends Model implements Preventable
|
|||
/** @return array<string, mixed> */
|
||||
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];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Invoice>
|
||||
* @return Builder<Invoice>
|
||||
*/
|
||||
public function handle(InvoiceFilterScope $filter)
|
||||
public function handle(InvoiceFilterScope $filter): Builder
|
||||
{
|
||||
return $filter->getQuery()->query(fn ($q) => $q->with('positions'));
|
||||
}
|
||||
|
|
|
@ -122,15 +122,6 @@ class Invoice extends Model
|
|||
->where('last_remembered_at', '<=', now()->subWeeks($weeks));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Builder<self> $query
|
||||
* @return Builder<self>
|
||||
*/
|
||||
public function scopeWithFilter(Builder $query, InvoiceFilterScope $filter): Builder
|
||||
{
|
||||
return $filter->apply($query);
|
||||
}
|
||||
|
||||
public function getMailRecipient(): stdClass
|
||||
{
|
||||
return (object) [
|
||||
|
|
|
@ -12,7 +12,7 @@ use Spatie\LaravelData\Attributes\MapOutputName;
|
|||
use Spatie\LaravelData\Mappers\SnakeCaseMapper;
|
||||
|
||||
/**
|
||||
* @extends Filter<Invoice>
|
||||
* @extends ScoutFilter<Invoice>
|
||||
*/
|
||||
#[MapInputName(SnakeCaseMapper::class)]
|
||||
#[MapOutputName(SnakeCaseMapper::class)]
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
use App\Form\Actions\UpdateParticipantSearchIndexAction;
|
||||
use App\Form\Models\Form;
|
||||
use App\Lib\Sorting;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
foreach (Form::get() as $form) {
|
||||
UpdateParticipantSearchIndexAction::run($form);
|
||||
foreach ($form->participants as $participant) {
|
||||
$participant->searchable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
};
|
|
@ -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 () {
|
||||
|
|
Loading…
Reference in New Issue