ui: fix caching for autocomplete values
This commit is contained in:
parent
1146900dc0
commit
11a2ea48bc
2 changed files with 9 additions and 7 deletions
|
|
@ -62,17 +62,18 @@ const FilterAutoComplete = observer(
|
|||
const [loading, setLoading] = useState(false);
|
||||
const { filterStore, projectsStore } = useStore();
|
||||
const _params = processKey(params);
|
||||
const filterKey = `${_params.type}${_params.key || ''}`;
|
||||
const filterKey = `${projectsStore.siteId}_${_params.type}${_params.key || ''}`;
|
||||
const topValues = filterStore.topValues[filterKey] || [];
|
||||
|
||||
React.useEffect(() => {
|
||||
filterStore.resetValues()
|
||||
setOptions([])
|
||||
}, [projectsStore.siteId])
|
||||
|
||||
const loadTopValues = async () => {
|
||||
setLoading(true)
|
||||
await filterStore.fetchTopValues(_params.type, _params.key);
|
||||
if (projectsStore.siteId) {
|
||||
await filterStore.fetchTopValues(_params.type, projectsStore.siteId, _params.key);
|
||||
}
|
||||
setLoading(false)
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -27,12 +27,13 @@ export default class FilterStore {
|
|||
this.topValues = {};
|
||||
}
|
||||
|
||||
fetchTopValues = async (key: string, source?: string) => {
|
||||
if (this.topValues.hasOwnProperty(key)) {
|
||||
return Promise.resolve(this.topValues[key]);
|
||||
fetchTopValues = async (key: string, siteId: string, source?: string) => {
|
||||
const valKey = `${siteId}_${key}${source || ''}`
|
||||
if (this.topValues[valKey] && this.topValues[valKey].length) {
|
||||
return Promise.resolve(this.topValues[valKey]);
|
||||
}
|
||||
return filterService.fetchTopValues(key, source).then((response: []) => {
|
||||
this.setTopValues(`${key}${source || ''}`, response);
|
||||
this.setTopValues(valKey, response);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue