From 5c9a45977d076ba2d06a752ac74e9e40d15e0de5 Mon Sep 17 00:00:00 2001 From: Nate Kelley Date: Tue, 15 Apr 2025 22:46:59 -0600 Subject: [PATCH] fixed broken exit button --- .../helpers/assetParamsToRoute.test.ts | 20 +++++++++++++++++++ .../helpers/assetParamsToRoute.ts | 13 +++++++++--- .../useCloseVersionHistory.ts | 17 +++++++++++++--- .../routes/busterRoutes/busterAppRoutes.ts | 3 ++- 4 files changed, 46 insertions(+), 7 deletions(-) diff --git a/web/src/layouts/ChatLayout/ChatLayoutContext/helpers/assetParamsToRoute.test.ts b/web/src/layouts/ChatLayout/ChatLayoutContext/helpers/assetParamsToRoute.test.ts index 6cdaf605e..419261db4 100644 --- a/web/src/layouts/ChatLayout/ChatLayoutContext/helpers/assetParamsToRoute.test.ts +++ b/web/src/layouts/ChatLayout/ChatLayoutContext/helpers/assetParamsToRoute.test.ts @@ -467,4 +467,24 @@ describe('assetParamsToRoute', () => { }) ); }); + + test('no chat id, metric with version number', () => { + const test = { + assetId: '06d9d8b7-eb96-59af-9a03-0436205b60a9', + type: 'metric', + versionNumber: 1, + chatId: undefined, + secondaryView: 'version-history' + } as const; + + const result = assetParamsToRoute(test); + expect(result).toBe( + createBusterRoute({ + route: BusterRoutes.APP_METRIC_ID_VERSION_NUMBER, + metricId: test.assetId, + versionNumber: test.versionNumber, + secondaryView: 'version-history' + }) + ); + }); }); diff --git a/web/src/layouts/ChatLayout/ChatLayoutContext/helpers/assetParamsToRoute.ts b/web/src/layouts/ChatLayout/ChatLayoutContext/helpers/assetParamsToRoute.ts index d6b2c5b8b..f3879915a 100644 --- a/web/src/layouts/ChatLayout/ChatLayoutContext/helpers/assetParamsToRoute.ts +++ b/web/src/layouts/ChatLayout/ChatLayoutContext/helpers/assetParamsToRoute.ts @@ -27,7 +27,7 @@ const createMetricRoute = ({ secondaryView, versionNumber }: MetricRouteParams) => { - const baseParams = { metricId, secondaryView }; + const baseParams = { versionNumber, metricId, secondaryView }; if (chatId) { if (versionNumber) { @@ -69,6 +69,14 @@ const createMetricRoute = ({ } // Non-chat metric routes + + if (versionNumber) { + return createBusterRoute({ + route: BusterRoutes.APP_METRIC_ID_VERSION_NUMBER, + ...baseParams + }); + } + switch (secondaryView) { case 'chart-edit': return createBusterRoute({ @@ -81,9 +89,8 @@ const createMetricRoute = ({ ...baseParams }); case 'version-history': + // default: - const test: never | undefined = - secondaryView === 'version-history' ? undefined : secondaryView; return createBusterRoute({ route: BusterRoutes.APP_METRIC_ID_CHART, metricId diff --git a/web/src/layouts/ChatLayout/FileContainer/FileContainerHeader/FileContainerHeaderVersionHistory/useCloseVersionHistory.ts b/web/src/layouts/ChatLayout/FileContainer/FileContainerHeader/FileContainerHeaderVersionHistory/useCloseVersionHistory.ts index 8fcf67066..cca494a39 100644 --- a/web/src/layouts/ChatLayout/FileContainer/FileContainerHeader/FileContainerHeaderVersionHistory/useCloseVersionHistory.ts +++ b/web/src/layouts/ChatLayout/FileContainer/FileContainerHeader/FileContainerHeaderVersionHistory/useCloseVersionHistory.ts @@ -1,7 +1,10 @@ import { useAppLayoutContextSelector } from '@/context/BusterAppLayout'; import { useMemoizedFn } from '@/hooks'; import { useGetInitialChatFile } from '@/layouts/ChatLayout/ChatContext/useGetInitialChatFile'; -import { useChatLayoutContextSelector } from '@/layouts/ChatLayout/ChatLayoutContext'; +import { + assetParamsToRoute, + useChatLayoutContextSelector +} from '@/layouts/ChatLayout/ChatLayoutContext'; import { useMemo } from 'react'; export const useCloseVersionHistory = () => { @@ -13,16 +16,24 @@ export const useCloseVersionHistory = () => { const getInitialChatFileHref = useGetInitialChatFile(); const href = useMemo(() => { + if (!chatId) { + return assetParamsToRoute({ + assetId: metricId!, + type: 'metric', + chatId + }); + } + return ( getInitialChatFileHref({ metricId, dashboardId, - chatId: chatId!, + chatId, secondaryView: null, dashboardVersionNumber: undefined, metricVersionNumber: undefined, messageId - }) || '' + }) || 'error' ); }, [chatId, messageId, metricId, dashboardId]); diff --git a/web/src/routes/busterRoutes/busterAppRoutes.ts b/web/src/routes/busterRoutes/busterAppRoutes.ts index 865fdaf3a..fa22efc95 100644 --- a/web/src/routes/busterRoutes/busterAppRoutes.ts +++ b/web/src/routes/busterRoutes/busterAppRoutes.ts @@ -57,12 +57,13 @@ export type BusterAppRoutesWithArgs = { [BusterAppRoutes.APP_METRIC_ID_CHART]: { route: BusterAppRoutes.APP_METRIC_ID_CHART; metricId: string; + versionNumber?: number; secondaryView?: MetricFileViewSecondary; }; [BusterAppRoutes.APP_METRIC_ID_VERSION_NUMBER]: { route: BusterAppRoutes.APP_METRIC_ID_VERSION_NUMBER; metricId: string; - versionNumber: number; + versionNumber?: number; secondaryView?: MetricFileViewSecondary; }; [BusterAppRoutes.APP_METRIC_ID_FILE]: {