ui: reset autocomplete values with project change
This commit is contained in:
parent
9949928335
commit
adb359b3bf
2 changed files with 10 additions and 1 deletions
|
|
@ -60,11 +60,16 @@ const FilterAutoComplete = observer(
|
|||
);
|
||||
const [initialFocus, setInitialFocus] = useState(false);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const { filterStore } = useStore();
|
||||
const { filterStore, projectsStore } = useStore();
|
||||
const _params = processKey(params);
|
||||
const filterKey = `${_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);
|
||||
|
|
|
|||
|
|
@ -23,6 +23,10 @@ export default class FilterStore {
|
|||
this.topValues[key] = vals?.filter((value) => value !== null && value.value !== '');
|
||||
};
|
||||
|
||||
resetValues = () => {
|
||||
this.topValues = {};
|
||||
}
|
||||
|
||||
fetchTopValues = async (key: string, source?: string) => {
|
||||
if (this.topValues.hasOwnProperty(key)) {
|
||||
return Promise.resolve(this.topValues[key]);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue