-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1098 from geoadmin/feat-pb-877-add-swisssearch-le…
…gacy-url-limit-attribute PB-877: add swisssearch legacy url limit attribute
- Loading branch information
Showing
9 changed files
with
207 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import AbstractParamConfig, { | ||
STORE_DISPATCHER_ROUTER_PLUGIN, | ||
} from '@/router/storeSync/abstractParamConfig.class' | ||
import { URL_PARAM_NAME_SWISSSEARCH } from '@/router/storeSync/SearchParamConfig.class' | ||
import { removeQueryParamFromHref } from '@/utils/searchParamUtils' | ||
|
||
const URL_PARAM_NAME = 'swisssearch_autoselect' | ||
/** | ||
* Dispatches the 'setAutoSelect' action to the store if the URL parameter for swisssearch is | ||
* present. | ||
* | ||
* @param {Object} to - The target route object. | ||
* @param {Object} store - The Vuex store instance. | ||
* @param {string} urlParamValue - The value of the URL parameter to be dispatched. | ||
*/ | ||
function dispatchAutoSelect(to, store, urlParamValue) { | ||
// avoiding setting the swisssearch autoselect to the store when there is nothing to autoselect because there is no swisssearch query | ||
if (urlParamValue && to.query[URL_PARAM_NAME_SWISSSEARCH]) { | ||
store.dispatch('setAutoSelect', { | ||
value: urlParamValue, | ||
dispatcher: STORE_DISPATCHER_ROUTER_PLUGIN, | ||
}) | ||
} | ||
} | ||
|
||
export default class SearchAutoSelectConfig extends AbstractParamConfig { | ||
constructor() { | ||
super({ | ||
urlParamName: URL_PARAM_NAME, | ||
mutationsToWatch: ['setAutoSelect'], | ||
setValuesInStore: dispatchAutoSelect, | ||
afterSetValuesInStore: () => removeQueryParamFromHref(URL_PARAM_NAME), | ||
extractValueFromStore: (store) => store.state.search.autoSelect, | ||
keepInUrlWhenDefault: false, | ||
valueType: Boolean, | ||
defaultValue: false, | ||
validateUrlInput: null, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* This will remove the query param from the URL It is necessary to do this in vanilla JS because | ||
* the router does not provide a way to remove a query without reloading the page which then removes | ||
* the value from the store. | ||
* | ||
* @param {Object} key The key to remove from the URL | ||
*/ | ||
export function removeQueryParamFromHref(key) { | ||
const [baseUrl, queryString] = window.location.href.split('?') | ||
if (!queryString) { | ||
return | ||
} | ||
|
||
const params = new URLSearchParams(queryString) | ||
if (!params.has(key)) { | ||
return | ||
} | ||
params.delete(key) | ||
|
||
const newQueryString = params.toString() | ||
const newUrl = newQueryString ? `${baseUrl}?${newQueryString}` : baseUrl | ||
window.history.replaceState({}, document.title, newUrl) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.