fix(ui): omnisearch call

This commit is contained in:
Shekar Siri 2024-11-18 17:01:47 +01:00
parent 4db693a6b2
commit ebdc2bd08c
3 changed files with 44 additions and 23 deletions

View file

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

View file

@ -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<string, { projectId: number; value: string }[]>, 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) {

View file

@ -72,20 +72,27 @@ class SearchStoreLive {
return generateFilterOptions(liveFiltersMap);
}
fetchFilterSearch(params: any) {
fetchFilterSearch = async (params: any): Promise<void> => {
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<string, { projectId: number; value: string }[]>, 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<Search>) {
this.instance = new Search(Object.assign({ ...this.instance }, instance));