metric version number update on file click

This commit is contained in:
Nate Kelley 2025-04-07 22:16:01 -06:00
parent 1f2e74b51d
commit 5e5c6c7175
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
4 changed files with 44 additions and 12 deletions

View File

@ -26,10 +26,10 @@ export const ChatResponseMessage_File: React.FC<ChatResponseMessageProps> = Reac
const { file_type, id } = responseMessage; const { file_type, id } = responseMessage;
const isSelectedFile = useGetIsSelectedFile({ responseMessage }); const { isSelectedFile, isLatestVersion } = useGetIsSelectedFile({ responseMessage });
const onSetSelectedFile = useChatLayoutContextSelector((x) => x.onSetSelectedFile); const onSetSelectedFile = useChatLayoutContextSelector((x) => x.onSetSelectedFile);
const href = useGetFileHref({ responseMessage, isSelectedFile, chatId }); const href = useGetFileHref({ isLatestVersion, responseMessage, isSelectedFile, chatId });
useMount(() => { useMount(() => {
if (href) { if (href) {

View File

@ -7,10 +7,12 @@ import { useMemo } from 'react';
export const useGetFileHref = ({ export const useGetFileHref = ({
responseMessage, responseMessage,
isSelectedFile, isSelectedFile,
isLatestVersion,
chatId chatId
}: { }: {
responseMessage: BusterChatResponseMessage_file; responseMessage: BusterChatResponseMessage_file;
isSelectedFile: boolean; isSelectedFile: boolean;
isLatestVersion: boolean;
chatId: string; chatId: string;
}) => { }) => {
const { file_type, id, version_number } = responseMessage; const { file_type, id, version_number } = responseMessage;
@ -26,19 +28,36 @@ export const useGetFileHref = ({
} }
if (file_type === 'metric') { if (file_type === 'metric') {
console.log(responseMessage); if (isLatestVersion) {
return createBusterRoute({
route: BusterRoutes.APP_CHAT_ID_METRIC_ID_CHART,
chatId,
metricId: id
});
}
return createBusterRoute({ return createBusterRoute({
route: BusterRoutes.APP_CHAT_ID_METRIC_ID_CHART, route: BusterRoutes.APP_CHAT_ID_METRIC_ID_VERSION_NUMBER,
chatId, chatId,
metricId: id metricId: id,
versionNumber: version_number.toString()
}); });
} }
if (file_type === 'dashboard') { if (file_type === 'dashboard') {
if (isLatestVersion) {
return createBusterRoute({
route: BusterRoutes.APP_CHAT_ID_DASHBOARD_ID,
chatId,
dashboardId: id
});
}
return createBusterRoute({ return createBusterRoute({
route: BusterRoutes.APP_CHAT_ID_DASHBOARD_ID, route: BusterRoutes.APP_CHAT_ID_DASHBOARD_ID_VERSION_NUMBER,
chatId, chatId,
dashboardId: id dashboardId: id,
versionNumber: version_number.toString()
}); });
} }

View File

@ -7,7 +7,10 @@ export const useGetIsSelectedFile = ({
responseMessage responseMessage
}: { }: {
responseMessage: Pick<BusterChatResponseMessage_file, 'file_type' | 'id' | 'version_number'>; responseMessage: Pick<BusterChatResponseMessage_file, 'file_type' | 'id' | 'version_number'>;
}) => { }): {
isSelectedFile: boolean;
isLatestVersion: boolean;
} => {
const queryClient = useQueryClient(); const queryClient = useQueryClient();
const isSelectedFile = useChatIndividualContextSelector( const isSelectedFile = useChatIndividualContextSelector(
(x) => x.selectedFileId === responseMessage.id (x) => x.selectedFileId === responseMessage.id
@ -20,20 +23,22 @@ export const useGetIsSelectedFile = ({
const options = queryKeys.metricsGetMetric(responseMessage.id); const options = queryKeys.metricsGetMetric(responseMessage.id);
const data = queryClient.getQueryData(options.queryKey); const data = queryClient.getQueryData(options.queryKey);
const lastVersion = data?.versions[data.versions.length - 1]; 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': { case 'dashboard': {
const options = queryKeys.dashboardGetDashboard(responseMessage.id); const options = queryKeys.dashboardGetDashboard(responseMessage.id);
const data = queryClient.getQueryData(options.queryKey)?.dashboard; const data = queryClient.getQueryData(options.queryKey)?.dashboard;
const lastVersion = data?.versions[data.versions.length - 1]; 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': { case 'reasoning': {
return false; return { isSelectedFile: false, isLatestVersion: false };
} }
default: { default: {
const exhaustiveCheck: never = responseMessage.file_type; const exhaustiveCheck: never = responseMessage.file_type;
return false; return { isSelectedFile: false, isLatestVersion: false };
} }
} }
}; };

View File

@ -29,10 +29,12 @@ export enum BusterAppRoutes {
APP_CHAT_ID_REASONING_ID = '/app/chats/:chatId/reasoning/:messageId', 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 = '/app/chats/:chatId/metrics/:metricId',
APP_CHAT_ID_METRIC_ID_CHART = '/app/chats/:chatId/metrics/:metricId/chart', 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_FILE = '/app/chats/:chatId/metrics/:metricId/file',
APP_CHAT_ID_METRIC_ID_RESULTS = '/app/chats/:chatId/metrics/:metricId/results', 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_COLLECTION_ID = '/app/chats/:chatId/collections/:collectionId',
APP_CHAT_ID_DASHBOARD_ID = '/app/chats/:chatId/dashboards/:dashboardId', 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_DASHBOARD_ID_FILE = '/app/chats/:chatId/dashboards/:dashboardId/file',
APP_CHAT_ID_DATASET_ID = '/app/chats/:chatId/datasets/:datasetId', APP_CHAT_ID_DATASET_ID = '/app/chats/:chatId/datasets/:datasetId',
APP_CHAT_ID_TERM_ID = '/app/chats/:chatId/term/:termId', APP_CHAT_ID_TERM_ID = '/app/chats/:chatId/term/:termId',
@ -118,6 +120,12 @@ export type BusterAppRoutesWithArgs = {
chatId: string; chatId: string;
metricId: 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]: { [BusterAppRoutes.APP_CHAT_ID_METRIC_ID_FILE]: {
route: BusterAppRoutes.APP_CHAT_ID_METRIC_ID_FILE; route: BusterAppRoutes.APP_CHAT_ID_METRIC_ID_FILE;
chatId: string; chatId: string;