Checks query before reloading filters facets.

This commit is contained in:
mateuswetah 2021-06-18 16:38:25 -03:00
parent 98f083ac77
commit d23f153570
4 changed files with 38 additions and 13 deletions

View File

@ -78,21 +78,22 @@
if (!isEqual)
this.onSelect();
},
'query'() {
if (!this.isUsingElasticSearch)
this.loadOptions();
},
facetsFromItemSearch: {
handler() {
if (this.isUsingElasticSearch)
this.loadOptions();
},
immediate: true
}
},
},
mounted() {
if (!this.isUsingElasticSearch && !this.filtersAsModal)
this.loadOptions();
this.$eventBusSearch.$on('has-to-reload-facets', (shouldReload) => {
if ( !this.isUsingElasticSearch && shouldReload )
this.loadOptions();
});
},
methods: {
loadOptions() {

View File

@ -37,10 +37,6 @@
}
},
watch: {
'query'() {
if (!this.isUsingElasticSearch)
this.loadOptions();
},
facetsFromItemSearch: {
handler() {
if (this.isUsingElasticSearch)
@ -49,9 +45,14 @@
immediate: true
}
},
mounted(){
mounted() {
if (!this.isUsingElasticSearch)
this.loadOptions();
this.$eventBusSearch.$on('has-to-reload-facets', (shouldReload) => {
if ( !this.isUsingElasticSearch && shouldReload )
this.loadOptions();
});
},
methods: {
loadOptions(){

View File

@ -111,9 +111,6 @@
this.isLoadingOptions = this.isLoadingItems;
},
immediate: true
},
'query'() {
this.loadOptions();
}
},
created() {
@ -129,6 +126,11 @@
mounted(){
if (!this.filtersAsModal)
this.loadOptions();
this.$eventBusSearch.$on('has-to-reload-facets', (shouldReload) => {
if ( !this.isUsingElasticSearch && shouldReload )
this.loadOptions();
});
},
beforeDestroy() {

View File

@ -160,7 +160,28 @@ export default {
} else {
this.$store.dispatch('search/set_postquery', this.$route.query);
}
// Checks current metaqueries and taxqueries to alert filters that should reload
// For some reason, this process is not working accessing to.query, so we need to check the path string.
const oldQueryString = from.fullPath.replace(from.path + '?', '');
const newQueryString = to.fullPath.replace(from.path + '?', '');
const oldQueryArray = oldQueryString.split('&');
const newQueryArray = newQueryString.split('&');
const oldMetaQueryArray = oldQueryArray.filter(queryItem => queryItem.startsWith('metaquery'));
const newMetaQueryArray = newQueryArray.filter(queryItem => queryItem.startsWith('metaquery'));
const oldTaxQueryArray = oldQueryArray.filter(queryItem => queryItem.startsWith('taxquery'));
const newTaxQueryArray = newQueryArray.filter(queryItem => queryItem.startsWith('taxquery'));
if (
JSON.stringify(oldMetaQueryArray) != JSON.stringify(newMetaQueryArray) ||
JSON.stringify(oldTaxQueryArray) != JSON.stringify(newTaxQueryArray)
) {
this.$emit('has-to-reload-facets', true);
}
// Finally, loads items
if (to.fullPath != from.fullPath) {
this.loadItems(to);
}