From 5e5c6c7175810f9a1d84b5d00622c8567bf9f1f6 Mon Sep 17 00:00:00 2001 From: Nate Kelley Date: Mon, 7 Apr 2025 22:16:01 -0600 Subject: [PATCH] metric version number update on file click --- .../ChatResponseMessage_File.tsx | 4 +-- .../useGetFileHref.tsx | 29 +++++++++++++++---- .../useGetIsSelectedFile.tsx | 15 ++++++---- .../routes/busterRoutes/busterAppRoutes.ts | 8 +++++ 4 files changed, 44 insertions(+), 12 deletions(-) diff --git a/web/src/layouts/ChatLayout/ChatContainer/ChatContent/ChatResponseMessages/ChatResponseMessage_File/ChatResponseMessage_File.tsx b/web/src/layouts/ChatLayout/ChatContainer/ChatContent/ChatResponseMessages/ChatResponseMessage_File/ChatResponseMessage_File.tsx index ee2234183..499485e14 100644 --- a/web/src/layouts/ChatLayout/ChatContainer/ChatContent/ChatResponseMessages/ChatResponseMessage_File/ChatResponseMessage_File.tsx +++ b/web/src/layouts/ChatLayout/ChatContainer/ChatContent/ChatResponseMessages/ChatResponseMessage_File/ChatResponseMessage_File.tsx @@ -26,10 +26,10 @@ export const ChatResponseMessage_File: React.FC = 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) { diff --git a/web/src/layouts/ChatLayout/ChatContainer/ChatContent/ChatResponseMessages/ChatResponseMessage_File/useGetFileHref.tsx b/web/src/layouts/ChatLayout/ChatContainer/ChatContent/ChatResponseMessages/ChatResponseMessage_File/useGetFileHref.tsx index 898d9e608..d1d7107af 100644 --- a/web/src/layouts/ChatLayout/ChatContainer/ChatContent/ChatResponseMessages/ChatResponseMessage_File/useGetFileHref.tsx +++ b/web/src/layouts/ChatLayout/ChatContainer/ChatContent/ChatResponseMessages/ChatResponseMessage_File/useGetFileHref.tsx @@ -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,19 +28,36 @@ export const useGetFileHref = ({ } if (file_type === 'metric') { - console.log(responseMessage); + if (isLatestVersion) { + return createBusterRoute({ + route: BusterRoutes.APP_CHAT_ID_METRIC_ID_CHART, + chatId, + metricId: id + }); + } + return createBusterRoute({ - route: BusterRoutes.APP_CHAT_ID_METRIC_ID_CHART, + route: BusterRoutes.APP_CHAT_ID_METRIC_ID_VERSION_NUMBER, chatId, - metricId: id + metricId: id, + versionNumber: version_number.toString() }); } if (file_type === 'dashboard') { + if (isLatestVersion) { + return createBusterRoute({ + route: BusterRoutes.APP_CHAT_ID_DASHBOARD_ID, + chatId, + dashboardId: id + }); + } + return createBusterRoute({ - route: BusterRoutes.APP_CHAT_ID_DASHBOARD_ID, + route: BusterRoutes.APP_CHAT_ID_DASHBOARD_ID_VERSION_NUMBER, chatId, - dashboardId: id + dashboardId: id, + versionNumber: version_number.toString() }); } diff --git a/web/src/layouts/ChatLayout/ChatContainer/ChatContent/ChatResponseMessages/ChatResponseMessage_File/useGetIsSelectedFile.tsx b/web/src/layouts/ChatLayout/ChatContainer/ChatContent/ChatResponseMessages/ChatResponseMessage_File/useGetIsSelectedFile.tsx index 5b896924f..45a6feaec 100644 --- a/web/src/layouts/ChatLayout/ChatContainer/ChatContent/ChatResponseMessages/ChatResponseMessage_File/useGetIsSelectedFile.tsx +++ b/web/src/layouts/ChatLayout/ChatContainer/ChatContent/ChatResponseMessages/ChatResponseMessage_File/useGetIsSelectedFile.tsx @@ -7,7 +7,10 @@ export const useGetIsSelectedFile = ({ responseMessage }: { responseMessage: Pick; -}) => { +}): { + 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 }; } } }; diff --git a/web/src/routes/busterRoutes/busterAppRoutes.ts b/web/src/routes/busterRoutes/busterAppRoutes.ts index 9763829d1..1be43fa74 100644 --- a/web/src/routes/busterRoutes/busterAppRoutes.ts +++ b/web/src/routes/busterRoutes/busterAppRoutes.ts @@ -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;