Skip to content

Commit

Permalink
PB-951: after set value in abstract param config
Browse files Browse the repository at this point in the history
  • Loading branch information
sommerfe committed Oct 16, 2024
1 parent 8860d8b commit 4757612
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/modules/menu/components/search/SearchBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ watch(
// if an entry has been selected from the list, do not show the list again
// because the list has been hidden by onEntrySelected.
if (!selectedEntry.value) {
// if (!selectedEntry.value) {
log.debug(
`Search has result changed to ${newValue}, change the show result to ${newValue}`
)
Expand Down
3 changes: 2 additions & 1 deletion src/router/storeSync/SearchParamConfig.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function dispatchSearchFromUrl(to, store, urlParamValue) {
/**
* 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
* the value from the store.
*
* @param {Object} key The key to remove from the URL
*/
Expand All @@ -47,6 +47,7 @@ export default class SearchParamConfig extends AbstractParamConfig {
constructor() {
super({
urlParamName: URL_PARAM_NAME,
mutationsToWatch: [],
setValuesInStore: dispatchSearchFromUrl,
afterSetValuesInStore: () => removeQueryParamFromHref(URL_PARAM_NAME),
keepInUrlWhenDefault: false,
Expand Down
23 changes: 12 additions & 11 deletions src/router/storeSync/abstractParamConfig.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ export default class AbstractParamConfig {
* added to the URL even though its value is set to the default value of the param.
* @param {NumberConstructor | StringConstructor | BooleanConstructor, ObjectConstructor} valueType
* @param {Boolean | Number | String | null} defaultValue
* @param {Function} afterSetValuesInStore A function that will be called after the store values
* have been set
*/
constructor({
urlParamName,
mutationsToWatch,
setValuesInStore,
extractValueFromStore,
extractValueFromStore = (_) => '',
keepInUrlWhenDefault = true,
valueType = String,
defaultValue = null,
Expand Down Expand Up @@ -210,18 +212,17 @@ export default class AbstractParamConfig {
* @returns {Promise<any>}
*/
afterPopulateStore() {
return new Promise((resolve, reject) => {
if (this.afterSetValuesInStore) {
const promiseAfterSetValuesInStore = this.afterSetValuesInStore()
if (promiseAfterSetValuesInStore) {
promiseAfterSetValuesInStore.then(() => {
resolve()
})
} else {
return new Promise((resolve) => {
if (!this.afterSetValuesInStore) {
resolve()
}
const promiseAfterSetValuesInStore = this.afterSetValuesInStore()
if (promiseAfterSetValuesInStore) {
promiseAfterSetValuesInStore.then(() => {
resolve()
}
})
} else {
reject('After query, store or setter functions is not set')
resolve()
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/router/storeSync/storeSync.routerPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function urlQueryWatcher(store, to, from) {

const setValueInStore = async (paramConfig, store, value) => {
await paramConfig.populateStoreWithQueryValue(to, store, value)
await paramConfig.afterPopulateStoreWithQueryValue()
await paramConfig.afterPopulateStore()
}

if (
Expand Down

0 comments on commit 4757612

Please sign in to comment.