Skip to content

Commit

Permalink
Start removal of appliedFilters
Browse files Browse the repository at this point in the history
  • Loading branch information
lrljoe authored Sep 29, 2024
1 parent 6bf0d09 commit 7ec1ce3
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
x-ref="dateRangeInput"
x-on:click="init"
x-on:change="changedValue($refs.dateRangeInput.value)"
value="{{ $filter->getDateString(isset($this->appliedFilters[$filterKey]) ? $this->appliedFilters[$filterKey] : '') }}"
value="{{ $filter->getDateString(isset($this->filterComponents[$filterKey]) ? $this->filterComponents[$filterKey] : '') }}"
wire:key="{{ $filter->generateWireKey($tableName, 'dateRange') }}"
id="{{ $tableName }}-filter-dateRange-{{ $filterKey }}"
@class([
Expand Down
8 changes: 4 additions & 4 deletions src/Traits/Helpers/FilterHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ public function mountFilterHelpers(): void
$this->restoreFilterValues();

foreach ($this->getFilters() as $filter) {
if (! isset($this->appliedFilters[$filter->getKey()])) {
if (! isset($this->filterComponents[$filter->getKey()])) {
if ($filter->hasFilterDefaultValue()) {
$this->setFilter($filter->getKey(), $filter->getFilterDefaultValue());
} else {
$this->resetFilter($filter);
}
} else {
$this->setFilter($filter->getKey(), $this->appliedFilters[$filter->getKey()]);
$this->setFilter($filter->getKey(), $this->filterComponents[$filter->getKey()]);
}
}
}
Expand Down Expand Up @@ -139,7 +139,7 @@ public function getFilterByKey(string $key)
#[On('set-filter')]
public function setFilter(string $filterKey, string|array|null $value): void
{
$this->appliedFilters[$filterKey] = $this->filterComponents[$filterKey] = $value;
$this->filterComponents[$filterKey] = $value;

$this->callHook('filterSet', ['filter' => $filterKey, 'value' => $value]);
$this->callTraitHook('filterSet', ['filter' => $filterKey, 'value' => $value]);
Expand Down Expand Up @@ -228,7 +228,7 @@ public function hasAppliedVisibleFiltersForPills(): bool
*/
public function getAppliedFiltersWithValues(): array
{
return $this->appliedFilters = array_filter($this->getAppliedFilters(), function ($item, $key) {
return $this->filterComponents = array_filter($this->getAppliedFilters(), function ($item, $key) {
return ! $this->getFilterByKey($key)->isEmpty($item) && (is_array($item) ? count($item) : $item !== null);
}, ARRAY_FILTER_USE_BOTH);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Traits/Helpers/SessionStorageHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ public function storeFilterValues(): void
{
if ($this->shouldStoreFiltersInSession()) {
$this->clearStoredFilterValues();
session([$this->getFilterSessionKey() => $this->appliedFilters]);
session([$this->getFilterSessionKey() => $this->filterComponents]);
}
}

public function restoreFilterValues(): void
{
if (empty($this->filterComponents) || empty($this->appliedFilters)) {
$this->filterComponents = $this->appliedFilters = $this->getStoredFilterValues();
if (empty($this->filterComponents)) {
$this->filterComponents = $this->getStoredFilterValues();
}
}

Expand Down
4 changes: 0 additions & 4 deletions src/Traits/WithFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ trait WithFilters
// Set in JS
public array $filterComponents = [];

// Set in Frontend
public array $appliedFilters = [];

public array $filterGenericData = [];

protected ?Collection $filterCollection;
Expand All @@ -51,7 +48,6 @@ protected function queryStringWithFilters(): array
{
if ($this->queryStringIsEnabled() && $this->filtersAreEnabled()) {
return [
'appliedFilters' => ['except' => null, 'history' => false, 'keep' => false, 'as' => $this->getQueryStringAlias().'-filters'],
'filterComponents' => ['except' => null, 'history' => false, 'keep' => false, 'as' => $this->getQueryStringAlias().'-filters'],
];
}
Expand Down

0 comments on commit 7ec1ce3

Please sign in to comment.