Skip to content

Commit 9fc1b65

Browse files
committed
feat(search): merge query params
1 parent ab53f7b commit 9fc1b65

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

datagouv-components/src/composables/useStableQueryParams.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface StableQueryParamsOptions {
1414

1515
/**
1616
* Creates a stable ref for query params that only updates when content actually changes.
17-
* Applies hiddenFilters first, then user filters (which can override hiddenFilters).
17+
* Applies hiddenFilters first, then merges user filters (colliding keys are combined into arrays).
1818
*/
1919
export function useStableQueryParams(options: StableQueryParamsOptions) {
2020
const { typeConfig, allFilters, q, sort, page, pageSize } = options
@@ -40,12 +40,14 @@ export function useStableQueryParams(options: StableQueryParamsOptions) {
4040

4141
// 3. Apply user filter values (only enabled ones)
4242
// Skip undefined/null/empty values so they're not sent to the API
43+
// If a key was already set by hiddenFilters, merge values (additive) rather than override
4344
for (const filterName of enabledFilters) {
4445
const filterRef = allFilters[filterName as string]
4546
if (filterRef) {
4647
const value = filterRef.value
4748
if (value !== undefined && value !== '' && value !== null) {
48-
params[filterName as string] = value
49+
const key = filterName as string
50+
params[key] = key in params ? Array.of(params[key], value).flat() : value
4951
}
5052
}
5153
}

0 commit comments

Comments
 (0)