Skip to content

Commit f17ffe2

Browse files
committed
WIP
1 parent 5587fa8 commit f17ffe2

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

packages/viewer/src/store/plugins/storeSync/params/swisssearch.param.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,18 @@ const swisssearchParamConfig = new UrlParamConfig<string>({
1212
urlParamName: URL_PARAM_NAME_SWISSSEARCH,
1313
// no mutation to watch, we only react to this param if it is there at app start-up
1414
actionsToWatch: [],
15-
extractValueFromStore: () => useSearchStore().query,
15+
// Always return default value so this param never gets re-added to URL by storeToUrl plugin
16+
extractValueFromStore: () => '',
1617
setValuesInStore: (_: RouteLocationNormalizedGeneric, urlParamValue?: string) => {
1718
if (urlParamValue) {
1819
useSearchStore().setSearchQuery(urlParamValue, STORE_DISPATCHER_ROUTER_PLUGIN)
1920
}
2021
},
21-
afterSetValuesInStore: () => removeQueryParamFromHref(URL_PARAM_NAME_SWISSSEARCH),
22+
afterSetValuesInStore: () => {
23+
// Defer removal to next event loop tick to ensure all URL params are processed
24+
// and router state is stable before manually modifying the URL
25+
setTimeout(() => removeQueryParamFromHref(URL_PARAM_NAME_SWISSSEARCH), 0)
26+
},
2227
keepInUrlWhenDefault: false,
2328
valueType: String,
2429
defaultValue: '',

packages/viewer/src/store/plugins/storeSync/params/swisssearchAutoSelect.param.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const swisssearchAutoSelectParam = new UrlParamConfig<boolean>({
1313
urlParamName: URL_PARAM_NAME,
1414
actionsToWatch: ['setAutoSelect'],
1515
setValuesInStore: (to: RouteLocationNormalizedGeneric, urlParamValue?: boolean) => {
16+
console.log('[swisssearchAutoSelectParam] setValuesInStore swisssearchAutoSelectParam', urlParamValue)
1617
const searchStore = useSearchStore()
1718
// avoiding setting the swisssearch autoselect to the store when there is nothing to autoselect because there is no swisssearch query
1819
if (typeof urlParamValue === 'boolean') {
@@ -23,8 +24,14 @@ const swisssearchAutoSelectParam = new UrlParamConfig<boolean>({
2324
searchStore.setAutoSelect(false, STORE_DISPATCHER_ROUTER_PLUGIN)
2425
}
2526
},
26-
afterSetValuesInStore: () => removeQueryParamFromHref(URL_PARAM_NAME),
27-
extractValueFromStore: () => useSearchStore().autoSelect,
27+
afterSetValuesInStore: () => {
28+
console.log('[swisssearchAutoSelectParam] afterSetValuesInStore swisssearchAutoSelectParam')
29+
// Defer removal to next event loop tick to ensure all URL params are processed
30+
// and router state is stable before manually modifying the URL
31+
setTimeout(() => removeQueryParamFromHref(URL_PARAM_NAME), 0)
32+
},
33+
// Always return default value so this param never gets re-added to URL by storeToUrl plugin
34+
extractValueFromStore: () => false,
2835
keepInUrlWhenDefault: false,
2936
valueType: Boolean,
3037
defaultValue: false,

packages/viewer/src/utils/searchParamUtils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
*/
88
export function removeQueryParamFromHref(key: string): void {
99
const [baseUrl, queryString] = window.location.href.split('?')
10+
console.log('[removeQueryParamFromHref] baseUrl', baseUrl)
11+
console.log('[removeQueryParamFromHref] queryString', queryString)
12+
1013
if (!queryString) {
1114
return
1215
}
@@ -16,8 +19,11 @@ export function removeQueryParamFromHref(key: string): void {
1619
return
1720
}
1821
params.delete(key)
22+
console.log('[removeQueryParamFromHref] replaced key', key)
1923

2024
const newQueryString = params.toString()
25+
console.log('[removeQueryParamFromHref] newQueryString', newQueryString)
2126
const newUrl = newQueryString ? `${baseUrl}?${newQueryString}` : baseUrl
27+
console.log('[removeQueryParamFromHref] newUrl', newUrl)
2228
window.history.replaceState({}, document.title, newUrl)
2329
}

packages/viewer/tests/cypress/tests-e2e/search/search-results.cy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ describe('Test the search bar result handling', () => {
527527
})
528528
cy.get('@locationSearchResults').should('not.exist')
529529
})
530-
it('autoselects the first swisssearch result when swisssearch_autoselect is true', () => {
530+
it.only('autoselects the first swisssearch result when swisssearch_autoselect is true', () => {
531531
cy.intercept('**/rest/services/ech/SearchServer*?type=layers*', {
532532
body: { results: [] },
533533
}).as('search-layers')

0 commit comments

Comments
 (0)