Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Query String + Filters not clearing and duplicated filter button #1568

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions src/Concerns/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@ public function clearFilter(string $field = '', bool $emit = true): void
{
collect($this->filters())
->each(function ($filter) use ($field) {
/**
* Filter Number will generate FIELD_start and FIELD_end fields,
* and both fields should also be cleaned.
* Here we verify if there are filter numbers and their fields.
*/

$extraFieldsToClear = [];

if (!empty($this->filters['number'])) {
$numberField = str($field)->beforeLast('_start')->beforeLast('_end')->append('')->toString();

if (isset($this->filters['number'][$numberField])) {
$field = $numberField;
$extraFieldsToClear = [$numberField . '_start', $numberField . '_end'];
}
}

if (isset($this->filters['multi_select'][$field])) {
$this->dispatch('pg:clear_multi_select::' . $this->tableName . ':' . $field);
}
Expand Down Expand Up @@ -55,6 +72,10 @@ public function clearFilter(string $field = '', bool $emit = true): void

if ($field === data_get($filter, 'field')) {
$unset($filter, $field, null);

foreach ($extraFieldsToClear as $fieldToClear) {
$unset($filter, $fieldToClear, null);
}
};
});

Expand Down Expand Up @@ -383,25 +404,30 @@ protected function powerGridQueryString(string $prefix = ''): array
}

if ($filter->key === 'number') {
$_start = $as->append('_start')->toString();
$_end = $as->append('_end')->toString();
$_start = $as->append('_start')->toString();
$_end = $as->append('_end')->toString();
$fieldProcessed = false;

$queryString['filters.number.' . $filter->field . '.start'] = [
'as' => $_start,
'except' => '',
];

if (!is_null(request()->get($_start))) {
if ($fieldProcessed === false && !is_null(request()->get($_start))) {
$this->addEnabledFilters($filter->field . '_start', strval($columns->get($filter->field, $filter->field)));

$fieldProcessed = true;
}

$queryString['filters.number.' . $filter->field . '.end'] = [
'as' => $_end,
'except' => '',
];

if (!is_null(request()->get($_end))) {
if ($fieldProcessed === false && !is_null(request()->get($_end))) {
$this->addEnabledFilters($filter->field . '_end', strval($columns->get($filter->field, $filter->field)));

$fieldProcessed = true;
}

continue;
Expand Down
2 changes: 1 addition & 1 deletion src/Concerns/ToggleDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function toggleDetail(string $id): void
/** @var \Illuminate\Support\Enumerable<(int|string), (int|string)> $except */
$except = $id;
collect($detailStates)->except($except)
->filter(fn ($state) => $state)->keys()
->filter(fn ($state) => boolval($state))->keys()
->each(
fn ($key) => data_set($this->setUp, "detail.state.$key", false)
);
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/ExportableJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private function prepareToExport(array $properties = []): Eloquent\Collection|Co

$sortField = Str::of($processDataSource->component->sortField)->contains('.') ? $processDataSource->component->sortField : $currentTable . '.' . $processDataSource->component->sortField;

$results = $processDataSource->prepareDataSource()
$results = $processDataSource->prepareDataSource() // @phpstan-ignore-line
->where(
fn ($query) => Builder::make($query, $this->componentTable)
->filterContains()
Expand Down