mirror of https://github.com/buster-so/buster.git
metric version number update on file click
This commit is contained in:
parent
1f2e74b51d
commit
5e5c6c7175
|
@ -26,10 +26,10 @@ export const ChatResponseMessage_File: React.FC<ChatResponseMessageProps> = Reac
|
|||
|
||||
const { file_type, id } = responseMessage;
|
||||
|
||||
const isSelectedFile = useGetIsSelectedFile({ responseMessage });
|
||||
const { isSelectedFile, isLatestVersion } = useGetIsSelectedFile({ responseMessage });
|
||||
const onSetSelectedFile = useChatLayoutContextSelector((x) => x.onSetSelectedFile);
|
||||
|
||||
const href = useGetFileHref({ responseMessage, isSelectedFile, chatId });
|
||||
const href = useGetFileHref({ isLatestVersion, responseMessage, isSelectedFile, chatId });
|
||||
|
||||
useMount(() => {
|
||||
if (href) {
|
||||
|
|
|
@ -7,10 +7,12 @@ import { useMemo } from 'react';
|
|||
export const useGetFileHref = ({
|
||||
responseMessage,
|
||||
isSelectedFile,
|
||||
isLatestVersion,
|
||||
chatId
|
||||
}: {
|
||||
responseMessage: BusterChatResponseMessage_file;
|
||||
isSelectedFile: boolean;
|
||||
isLatestVersion: boolean;
|
||||
chatId: string;
|
||||
}) => {
|
||||
const { file_type, id, version_number } = responseMessage;
|
||||
|
@ -26,7 +28,7 @@ export const useGetFileHref = ({
|
|||
}
|
||||
|
||||
if (file_type === 'metric') {
|
||||
console.log(responseMessage);
|
||||
if (isLatestVersion) {
|
||||
return createBusterRoute({
|
||||
route: BusterRoutes.APP_CHAT_ID_METRIC_ID_CHART,
|
||||
chatId,
|
||||
|
@ -34,7 +36,16 @@ export const useGetFileHref = ({
|
|||
});
|
||||
}
|
||||
|
||||
return createBusterRoute({
|
||||
route: BusterRoutes.APP_CHAT_ID_METRIC_ID_VERSION_NUMBER,
|
||||
chatId,
|
||||
metricId: id,
|
||||
versionNumber: version_number.toString()
|
||||
});
|
||||
}
|
||||
|
||||
if (file_type === 'dashboard') {
|
||||
if (isLatestVersion) {
|
||||
return createBusterRoute({
|
||||
route: BusterRoutes.APP_CHAT_ID_DASHBOARD_ID,
|
||||
chatId,
|
||||
|
@ -42,6 +53,14 @@ export const useGetFileHref = ({
|
|||
});
|
||||
}
|
||||
|
||||
return createBusterRoute({
|
||||
route: BusterRoutes.APP_CHAT_ID_DASHBOARD_ID_VERSION_NUMBER,
|
||||
chatId,
|
||||
dashboardId: id,
|
||||
versionNumber: version_number.toString()
|
||||
});
|
||||
}
|
||||
|
||||
console.warn('Unknown file type', file_type);
|
||||
|
||||
return '';
|
||||
|
|
|
@ -7,7 +7,10 @@ export const useGetIsSelectedFile = ({
|
|||
responseMessage
|
||||
}: {
|
||||
responseMessage: Pick<BusterChatResponseMessage_file, 'file_type' | 'id' | 'version_number'>;
|
||||
}) => {
|
||||
}): {
|
||||
isSelectedFile: boolean;
|
||||
isLatestVersion: boolean;
|
||||
} => {
|
||||
const queryClient = useQueryClient();
|
||||
const isSelectedFile = useChatIndividualContextSelector(
|
||||
(x) => x.selectedFileId === responseMessage.id
|
||||
|
@ -20,20 +23,22 @@ export const useGetIsSelectedFile = ({
|
|||
const options = queryKeys.metricsGetMetric(responseMessage.id);
|
||||
const data = queryClient.getQueryData(options.queryKey);
|
||||
const lastVersion = data?.versions[data.versions.length - 1];
|
||||
return isSelectedFile && lastVersion?.version_number === versionNumber;
|
||||
const isLatestVersion = lastVersion?.version_number === versionNumber;
|
||||
return { isSelectedFile: isSelectedFile && isLatestVersion, isLatestVersion };
|
||||
}
|
||||
case 'dashboard': {
|
||||
const options = queryKeys.dashboardGetDashboard(responseMessage.id);
|
||||
const data = queryClient.getQueryData(options.queryKey)?.dashboard;
|
||||
const lastVersion = data?.versions[data.versions.length - 1];
|
||||
return isSelectedFile && lastVersion?.version_number === versionNumber;
|
||||
const isLatestVersion = lastVersion?.version_number === versionNumber;
|
||||
return { isSelectedFile: isSelectedFile && isLatestVersion, isLatestVersion };
|
||||
}
|
||||
case 'reasoning': {
|
||||
return false;
|
||||
return { isSelectedFile: false, isLatestVersion: false };
|
||||
}
|
||||
default: {
|
||||
const exhaustiveCheck: never = responseMessage.file_type;
|
||||
return false;
|
||||
return { isSelectedFile: false, isLatestVersion: false };
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -29,10 +29,12 @@ export enum BusterAppRoutes {
|
|||
APP_CHAT_ID_REASONING_ID = '/app/chats/:chatId/reasoning/:messageId',
|
||||
APP_CHAT_ID_METRIC_ID = '/app/chats/:chatId/metrics/:metricId',
|
||||
APP_CHAT_ID_METRIC_ID_CHART = '/app/chats/:chatId/metrics/:metricId/chart',
|
||||
APP_CHAT_ID_METRIC_ID_VERSION_NUMBER = '/app/chats/:chatId/metrics/:metricId/chart?metric_version_number=:versionNumber',
|
||||
APP_CHAT_ID_METRIC_ID_FILE = '/app/chats/:chatId/metrics/:metricId/file',
|
||||
APP_CHAT_ID_METRIC_ID_RESULTS = '/app/chats/:chatId/metrics/:metricId/results',
|
||||
APP_CHAT_ID_COLLECTION_ID = '/app/chats/:chatId/collections/:collectionId',
|
||||
APP_CHAT_ID_DASHBOARD_ID = '/app/chats/:chatId/dashboards/:dashboardId',
|
||||
APP_CHAT_ID_DASHBOARD_ID_VERSION_NUMBER = '/app/chats/:chatId/dashboards/:dashboardId?dashboard_version_number=:versionNumber',
|
||||
APP_CHAT_ID_DASHBOARD_ID_FILE = '/app/chats/:chatId/dashboards/:dashboardId/file',
|
||||
APP_CHAT_ID_DATASET_ID = '/app/chats/:chatId/datasets/:datasetId',
|
||||
APP_CHAT_ID_TERM_ID = '/app/chats/:chatId/term/:termId',
|
||||
|
@ -118,6 +120,12 @@ export type BusterAppRoutesWithArgs = {
|
|||
chatId: string;
|
||||
metricId: string;
|
||||
};
|
||||
[BusterAppRoutes.APP_CHAT_ID_METRIC_ID_VERSION_NUMBER]: {
|
||||
route: BusterAppRoutes.APP_CHAT_ID_METRIC_ID_VERSION_NUMBER;
|
||||
chatId: string;
|
||||
metricId: string;
|
||||
versionNumber: string;
|
||||
};
|
||||
[BusterAppRoutes.APP_CHAT_ID_METRIC_ID_FILE]: {
|
||||
route: BusterAppRoutes.APP_CHAT_ID_METRIC_ID_FILE;
|
||||
chatId: string;
|
||||
|
|
Loading…
Reference in New Issue