diff --git a/frontend/app/components/shared/SessionSearchField/SessionSearchField.tsx b/frontend/app/components/shared/SessionSearchField/SessionSearchField.tsx index 22f7f77bc..29469d8b9 100644 --- a/frontend/app/components/shared/SessionSearchField/SessionSearchField.tsx +++ b/frontend/app/components/shared/SessionSearchField/SessionSearchField.tsx @@ -17,8 +17,13 @@ function SessionSearchField(props: Props) { const isLive = isRoute(ASSIST_ROUTE, window.location.pathname) || window.location.pathname.includes('multiview'); + + const fetchFilterSearch = isLive + ? searchStoreLive.fetchFilterSearch.bind(searchStoreLive) + : searchStore.fetchFilterSearch.bind(searchStore); + const debounceFetchFilterSearch = React.useCallback( - debounce(isLive ? searchStoreLive.fetchFilterSearch : searchStore.fetchFilterSearch, 1000), + debounce(fetchFilterSearch, 1000), [] ); const [showModal, setShowModal] = useState(false); diff --git a/frontend/app/mstore/searchStore.ts b/frontend/app/mstore/searchStore.ts index e24ca6f70..8ce0a0c14 100644 --- a/frontend/app/mstore/searchStore.ts +++ b/frontend/app/mstore/searchStore.ts @@ -140,17 +140,26 @@ class SearchStore { fetchFilterSearch(params: any) { this.loadingFilterSearch = true; - searchService.fetchFilterSearch(params).then((response: any) => { - this.filterSearchList = response.reduce((acc: any, item: any) => { - const { projectId, type, value } = item; - const key = type; - if (!acc[key]) acc[key] = []; - acc[key].push({ projectId, value }); - return acc; - }, {}).finally(() => { + + searchService + .fetchFilterSearch(params) + .then((response: any[]) => { + this.filterSearchList = response.reduce( + (acc: Record, item: any) => { + const { projectId, type, value } = item; + if (!acc[type]) acc[type] = []; + acc[type].push({ projectId, value }); + return acc; + }, + {} + ); + }) + .catch((error: any) => { + console.error('Error fetching filter search:', error); + }) + .finally(() => { this.loadingFilterSearch = false; }); - }); } updateCurrentPage(page: number) { diff --git a/frontend/app/mstore/searchStoreLive.ts b/frontend/app/mstore/searchStoreLive.ts index 7285f6fd9..0a4125cb8 100644 --- a/frontend/app/mstore/searchStoreLive.ts +++ b/frontend/app/mstore/searchStoreLive.ts @@ -72,20 +72,27 @@ class SearchStoreLive { return generateFilterOptions(liveFiltersMap); } - fetchFilterSearch(params: any) { + fetchFilterSearch = async (params: any): Promise => { this.loadingFilterSearch = true; - searchService.fetchFilterSearch(params).then((response: any) => { - this.filterSearchList = response.reduce((acc: any, item: any) => { - const { projectId, type, value } = item; - const key = type; - if (!acc[key]) acc[key] = []; - acc[key].push({ projectId, value }); - return acc; - }, {}).finally(() => { - this.loadingFilterSearch = false; - }); - }); - } + + try { + const response: any[] = await searchService.fetchFilterSearch(params); + + this.filterSearchList = response.reduce( + (acc: Record, item: any) => { + const { projectId, type, value } = item; + if (!acc[type]) acc[type] = []; + acc[type].push({ projectId, value }); + return acc; + }, + {} + ); + } catch (error) { + console.error('Error fetching filter search:', error); + } finally { + this.loadingFilterSearch = false; + } + }; edit(instance: Partial) { this.instance = new Search(Object.assign({ ...this.instance }, instance));