Skip to content

Commit

Permalink
feat(admin-ui): Preset filters should preserve query parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
taxilian committed Nov 9, 2024
1 parent 19d9f2a commit d41f30a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</div>
<a
[routerLink]="['./']"
[queryParams]="preset.value === serializedActiveFilters ? {} : { filters: preset.value, page: 1 }"
[queryParams]="getQueryParamsForPreset(preset.value, serializedActiveFilters)"
>
<div>{{ preset.name }}</div>
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,23 @@ export class DataTableFilterPresetsComponent implements OnInit, OnDestroy {
);
}

getQueryParamsForPreset(preset: string, serializedActiveFilters: string): Record<string, string> {
// Clone the current query params to avoid mutating them directly
const currentParams = { ...this.route.snapshot.queryParams };

if (preset === serializedActiveFilters) {
// Toggling off: remove 'filters' and 'page' params
delete currentParams['filters'];
delete currentParams['page'];
} else {
// Toggling on: set 'filters' and 'page' params
currentParams['filters'] = preset;
currentParams['page'] = 1;
}

return currentParams;
}

ngOnDestroy() {
this.destroy$.next();
this.destroy$.complete();
Expand Down

0 comments on commit d41f30a

Please sign in to comment.