Skip to content

Commit

Permalink
Filters urgent fixes - correct Filter Default QueryString (#2188)
Browse files Browse the repository at this point in the history
* Fixes for QueryString & Centralising Methods

* Tweaks for Filters
  • Loading branch information
lrljoe authored Jan 26, 2025
1 parent 424ab84 commit 3f18055
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 89 deletions.
36 changes: 15 additions & 21 deletions src/Traits/Filters/HasFilterQueryString.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@

trait HasFilterQueryString
{
#[Locked]
public ?bool $queryStringStatusForFilter;

protected ?string $queryStringAliasForFilter;

protected function queryStringHasFilterQueryString(): array
{
return ($this->queryStringForFilterIsEnabled()) ?
Expand All @@ -20,6 +15,11 @@ protected function queryStringHasFilterQueryString(): array
] : [];
}

public function queryStringForFilterIsEnabled(): bool
{
return $this->getQueryStringStatusForFilter() && $this->filtersAreEnabled();
}

public function hasQueryStringStatusForFilter(): bool
{
return $this->hasQueryStringConfigStatus('filters');
Expand All @@ -30,38 +30,32 @@ public function getQueryStringStatusForFilter(): bool
return $this->getQueryStringConfigStatus('filters');
}

public function queryStringForFilterIsEnabled(): bool
public function hasQueryStringAliasForFilter(): bool
{
return $this->hasQueryStringConfigAlias('filters');
}

return $this->getQueryStringStatusForFilter() && $this->filtersAreEnabled();
public function getQueryStringAliasForFilter(): string
{
return $this->getQueryStringConfigAlias('filters');
}

public function setQueryStringStatusForFilter(bool $status): self
protected function setQueryStringStatusForFilter(bool $status): self
{
return $this->setQueryStringConfigStatus('filters', $status);
}

public function setQueryStringForFilterEnabled(): self
protected function setQueryStringForFilterEnabled(): self
{
return $this->setQueryStringStatusForFilter(true);
}

public function setQueryStringForFilterDisabled(): self
protected function setQueryStringForFilterDisabled(): self
{
return $this->setQueryStringStatusForFilter(false);
}

public function hasQueryStringAliasForFilter(): bool
{
return $this->hasQueryStringConfigAlias('filters');
}

public function getQueryStringAliasForFilter(): string
{
return $this->getQueryStringConfigAlias('filters');
}

public function setQueryStringAliasForFilter(string $alias): self
protected function setQueryStringAliasForFilter(string $alias): self
{
return $this->setQueryStringConfigAlias('filters', $alias);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

namespace Rappasoft\LaravelLivewireTables\Traits\Filters;

use Illuminate\Database\Eloquent\Builder;
use Rappasoft\LaravelLivewireTables\Traits\Filters\Configuration\FilterConfiguration;
use Rappasoft\LaravelLivewireTables\Traits\Filters\Helpers\FilterHelpers;

trait ManagesFilters
trait HasFiltersCore
{
use FilterConfiguration,
FilterHelpers;

/**
* Sets Filter Default Values
*/
public function mountManagesFilters(): void
public function mountHasFiltersCore(): void
{
$this->restoreFilterValues();

Expand All @@ -26,7 +30,7 @@ public function mountManagesFilters(): void
}
}

public function bootedManagesFilters(): void
public function bootedHasFiltersCore(): void
{
$this->setBuilder($this->builder());

Expand Down
8 changes: 3 additions & 5 deletions src/Traits/WithFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@

use Illuminate\Support\Collection;
use Livewire\Attributes\Locked;
use Rappasoft\LaravelLivewireTables\Traits\Filters\{Configuration\FilterConfiguration, HasFilterGenericData, HasFilterMenu, HasFilterPills, HasFilterQueryString, HasFiltersStatus, HasFiltersVisibility, Helpers\FilterHelpers, ManagesFilters};
use Rappasoft\LaravelLivewireTables\Traits\Filters\{HasFilterGenericData, HasFilterMenu, HasFilterPills, HasFilterQueryString, HasFiltersCore, HasFiltersStatus, HasFiltersVisibility};

trait WithFilters
{
use FilterConfiguration,
FilterHelpers,
HasFiltersStatus,
use HasFiltersStatus,
HasFilterGenericData,
HasFilterMenu,
HasFilterPills,
HasFilterQueryString,
HasFiltersVisibility,
ManagesFilters;
HasFiltersCore;

// Set in JS
public array $filterComponents = [];
Expand Down
55 changes: 3 additions & 52 deletions tests/Http/Livewire/BaseTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,60 +3,11 @@
namespace Rappasoft\LaravelLivewireTables\Tests\Http\Livewire;

use Rappasoft\LaravelLivewireTables\DataTableComponent;
use Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\Traits\TestHelpers;

abstract class BaseTable extends DataTableComponent
{
public string $paginationTest = 'standard';

public function enableDetailedPagination(string $type = 'standard')
{
$this->setPerPageAccepted([1, 3, 5, 10, 15, 25, 50])->setPerPage(3);
$this->setPaginationMethod($type);
$this->setDisplayPaginationDetailsEnabled();

}

public function disableDetailedPagination(string $type = 'standard')
{
$this->setPerPageAccepted([1, 3, 5, 10, 15, 25, 50])->setPerPage(3);
$this->setPaginationMethod($type);
$this->setDisplayPaginationDetailsDisabled();
}

public function setPaginationTest(string $type)
{
$this->paginationTest = $type;
}
use TestHelpers;

public function bootAll()
{
$view = view('livewire-tables::datatable');

$this->boot();
$this->bootedComponentUtilities();
$this->bootedManagesFilters();
$this->bootedWithColumns();
$this->bootedWithColumnSelect();
$this->booted();
$this->mountManagesFilters();
$this->mountComponentUtilities();
$this->mountWithSorting();
$this->renderAll($view);
}

public function renderAll($view = null)
{
if (is_null($view)) {
$view = view('livewire-tables::datatable');
}
$this->renderingWithColumns($view, $view->getData());
$this->renderingWithColumnSelect($view, $view->getData());
$this->renderingWithCustomisations($view, $view->getData());
$this->renderingWithData($view, $view->getData());
$this->renderingWithReordering($view, $view->getData());
$this->renderingWithPagination($view, $view->getData());
$this->render();

return $view;
}
public string $paginationTest = 'standard';
}
40 changes: 40 additions & 0 deletions tests/Http/Livewire/Traits/TestHelpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\Traits;

trait TestHelpers
{
use TestPaginationHelpers;

public function bootAll()
{
$view = view('livewire-tables::datatable');

$this->boot();
$this->bootedComponentUtilities();
$this->bootedHasFiltersCore();
$this->bootedWithColumns();
$this->bootedWithColumnSelect();
$this->booted();
$this->mountHasFiltersCore();
$this->mountComponentUtilities();
$this->mountWithSorting();
$this->renderAll($view);
}

public function renderAll($view = null)
{
if (is_null($view)) {
$view = view('livewire-tables::datatable');
}
$this->renderingWithColumns($view, $view->getData());
$this->renderingWithColumnSelect($view, $view->getData());
$this->renderingWithCustomisations($view, $view->getData());
$this->renderingWithData($view, $view->getData());
$this->renderingWithReordering($view, $view->getData());
$this->renderingWithPagination($view, $view->getData());
$this->render();

return $view;
}
}
26 changes: 26 additions & 0 deletions tests/Http/Livewire/Traits/TestPaginationHelpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\Traits;

trait TestPaginationHelpers
{
public function enableDetailedPagination(string $type = 'standard')
{
$this->setPerPageAccepted([1, 3, 5, 10, 15, 25, 50])->setPerPage(3);
$this->setPaginationMethod($type);
$this->setDisplayPaginationDetailsEnabled();

}

public function disableDetailedPagination(string $type = 'standard')
{
$this->setPerPageAccepted([1, 3, 5, 10, 15, 25, 50])->setPerPage(3);
$this->setPaginationMethod($type);
$this->setDisplayPaginationDetailsDisabled();
}

public function setPaginationTest(string $type)
{
$this->paginationTest = $type;
}
}
4 changes: 2 additions & 2 deletions tests/Unit/DataTableComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ public function test_minimum_one_column_expected(): void
{
$this->expectException(\Rappasoft\LaravelLivewireTables\Exceptions\NoColumnsException::class);
$table = new NoColumnsTable;
$table->mountManagesFilters();
$table->mountHasFiltersCore();
$table->boot();
$table->bootedManagesFilters();
$table->bootedHasFiltersCore();
$table->bootedComponentUtilities();
$table->bootedWithColumns();
$table->bootedWithColumnSelect();
Expand Down
15 changes: 15 additions & 0 deletions tests/Unit/Traits/Core/QueryStrings/QueryStringTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ public function configure(): void
{
$this->setDataTableFingerprint('test');
}

public function setQueryStringAliasForFilter(string $alias): self
{
return parent::setQueryStringAliasForFilter($alias);
}

public function setQueryStringForFilterEnabled(): self
{
return parent::setQueryStringForFilterEnabled();
}

public function setQueryStringForFilterDisabled(): self
{
return parent::setQueryStringForFilterDisabled();
}
};
}
}
10 changes: 5 additions & 5 deletions tests/Unit/Traits/WithMountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function test_mounttable_gets_correct_first_item(): void
$table = new PetsTableMount;
$table->boot();
$table->mount(102);
$table->mountManagesFilters();
$table->mountHasFiltersCore();
$table->bootedComponentUtilities();
$table->bootedWithColumns();
$table->bootedWithColumnSelect();
Expand All @@ -30,9 +30,9 @@ public function test_mounttable_gets_correct_first_item(): void
$table2 = new PetsTableMount;
$table2->boot();
$table2->mount(202);
$table2->mountManagesFilters();
$table2->mountHasFiltersCore();
$table2->bootedComponentUtilities();
$table2->bootedManagesFilters();
$table2->bootedHasFiltersCore();
$table2->bootedWithColumns();
$table2->bootedWithColumnSelect();
$table2->booted();
Expand All @@ -46,8 +46,8 @@ public function test_mounttable_gets_correct_first_item(): void
$table3 = new PetsTableMount;
$table3->boot();
$table3->mount();
$table3->mountManagesFilters();
$table3->bootedManagesFilters();
$table3->mountHasFiltersCore();
$table3->bootedHasFiltersCore();
$table3->bootedComponentUtilities();
$table3->bootedWithColumns();
$table3->bootedWithColumnSelect();
Expand Down

0 comments on commit 3f18055

Please sign in to comment.