ui: reset autocomplete values with project change

This commit is contained in:
nick-delirium 2025-02-17 14:47:56 +01:00
parent 9949928335
commit adb359b3bf
No known key found for this signature in database
GPG key ID: 93ABD695DF5FDBA0
2 changed files with 10 additions and 1 deletions

View file

@ -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);

View file

@ -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]);