mirror of https://github.com/buster-so/buster.git
search update
This commit is contained in:
parent
b4d0020947
commit
912d0e855d
|
@ -4,7 +4,7 @@ import type { BusterSearchResult } from '@/api/asset_interfaces';
|
|||
export const getSearchResult = (searchTerm: string) =>
|
||||
queryOptions<BusterSearchResult[]>({
|
||||
queryKey: ['search', 'results', searchTerm] as const,
|
||||
staleTime: 1000 * 20 // 20 seconds
|
||||
staleTime: 1000 * 15 // 15 seconds
|
||||
});
|
||||
|
||||
export const searchQueryKeys = {
|
||||
|
|
|
@ -36,7 +36,6 @@ export const AddTypeModal: React.FC<{
|
|||
collection?: BusterCollection;
|
||||
}> = React.memo(({ type = 'collection', open, onClose, collection, dashboardResponse }) => {
|
||||
const onBusterSearch = useBusterSearchContextSelector((state) => state.onBusterSearch);
|
||||
const refreshDashboard = useBusterDashboardContextSelector((state) => state.refreshDashboard);
|
||||
const onBulkAddRemoveToDashboard = useBusterDashboardContextSelector(
|
||||
(state) => state.onBulkAddRemoveToDashboard
|
||||
);
|
||||
|
@ -159,14 +158,12 @@ export const AddTypeModal: React.FC<{
|
|||
}
|
||||
|
||||
results = await onBusterSearch({
|
||||
query,
|
||||
include
|
||||
query
|
||||
});
|
||||
} else if (type === 'dashboard') {
|
||||
include = ['exclude_metrics'];
|
||||
results = await onBusterSearch({
|
||||
query,
|
||||
include
|
||||
query
|
||||
});
|
||||
}
|
||||
if (isEmpty(initialSearchItems) && !query) {
|
||||
|
@ -226,7 +223,6 @@ export const AddTypeModal: React.FC<{
|
|||
dashboardId: dashboard!.id,
|
||||
metricIds: selectedIds
|
||||
});
|
||||
await refreshDashboard(dashboard!.id);
|
||||
}
|
||||
setSubmitting(false);
|
||||
return;
|
||||
|
|
|
@ -62,8 +62,7 @@ export const NewChatModal = React.memo<{
|
|||
|
||||
const getSuggestedChatPrompts = useMemoizedFn(async (prompt: string) => {
|
||||
const res = await onBusterSearch({
|
||||
query: prompt,
|
||||
include: ['exclude_metrics']
|
||||
query: prompt
|
||||
});
|
||||
return res;
|
||||
});
|
||||
|
|
|
@ -106,17 +106,12 @@ export const useDashboardUpdateConfig = ({
|
|||
}
|
||||
);
|
||||
|
||||
const refreshDashboard = useMemoizedFn((dashboardId: string) => {
|
||||
busterSocket.emit({ route: '/dashboards/get', payload: { id: dashboardId } });
|
||||
});
|
||||
|
||||
return {
|
||||
isUpdatingDashboard,
|
||||
updateDashboardMutation,
|
||||
onShareDashboard,
|
||||
onUpdateDashboardConfig,
|
||||
onUpdateDashboard,
|
||||
onVerifiedDashboard,
|
||||
refreshDashboard
|
||||
onVerifiedDashboard
|
||||
};
|
||||
};
|
||||
|
|
|
@ -13,43 +13,13 @@ import {
|
|||
export const useBusterSearch = () => {
|
||||
const busterSocket = useBusterWebSocket();
|
||||
|
||||
const onBusterSearch = useMemoizedFn(
|
||||
async ({
|
||||
query,
|
||||
include,
|
||||
exclude
|
||||
}: {
|
||||
include?: (keyof BusterSearchRequest['payload'])[];
|
||||
exclude?: (keyof BusterSearchRequest['payload'])[];
|
||||
query: string;
|
||||
}) => {
|
||||
const reducedParams = allBusterSearchRequestKeys.reduce((acc, curr) => {
|
||||
const value = include?.includes(curr) && !exclude?.includes(curr) ? true : false;
|
||||
return { ...acc, [curr]: !value };
|
||||
}, {});
|
||||
const payload: BusterSearchRequest['payload'] = {
|
||||
query,
|
||||
...reducedParams
|
||||
};
|
||||
const onBusterSearch = useMemoizedFn(async ({ query }: { query: string }) => {
|
||||
const payload: BusterSearchRequest['payload'] = {
|
||||
query
|
||||
};
|
||||
|
||||
const callback = (d: BusterSearchResult[]) => {
|
||||
return d || [];
|
||||
};
|
||||
|
||||
const res = await busterSocket.emitAndOnce({
|
||||
emitEvent: {
|
||||
route: '/search',
|
||||
payload
|
||||
},
|
||||
responseEvent: {
|
||||
route: '/search:search',
|
||||
callback,
|
||||
onError: (e) => {}
|
||||
}
|
||||
});
|
||||
return res as BusterSearchResult[];
|
||||
}
|
||||
);
|
||||
return [];
|
||||
});
|
||||
|
||||
return { onBusterSearch };
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue