From 2fe071e128c70882f13aa6883e8bdd8ec5ca94a8 Mon Sep 17 00:00:00 2001 From: Nate Kelley Date: Tue, 8 Apr 2025 22:28:32 -0600 Subject: [PATCH] pass version ids better --- web/src/app/embed/metrics/[metricId]/page.tsx | 16 +------- .../versionHistory/VersionHistoryPanel.tsx | 4 +- .../useListVersionHistories.tsx | 40 +++++++++++-------- .../DashboardContentController.tsx | 2 - .../MetricViewChart/MetricViewChart.tsx | 2 - 5 files changed, 26 insertions(+), 38 deletions(-) diff --git a/web/src/app/embed/metrics/[metricId]/page.tsx b/web/src/app/embed/metrics/[metricId]/page.tsx index 5872cfc56..36075b9e8 100644 --- a/web/src/app/embed/metrics/[metricId]/page.tsx +++ b/web/src/app/embed/metrics/[metricId]/page.tsx @@ -1,21 +1,7 @@ -'use client'; - -import { useGetMetric } from '@/api/buster_rest/metrics'; import { MetricViewChart } from '@/controllers/MetricController/MetricViewChart/MetricViewChart'; -export default function EmbedMetricsPage({ - params, - searchParams -}: { - params: { metricId: string }; - searchParams: { version_number?: string }; -}) { +export default function EmbedMetricsPage({ params }: { params: { metricId: string } }) { const { metricId } = params; - const { version_number } = searchParams; - const { isFetched } = useGetMetric({ - id: metricId, - version_number: version_number ? parseInt(version_number) : undefined - }); return ; } diff --git a/web/src/components/features/versionHistory/VersionHistoryPanel.tsx b/web/src/components/features/versionHistory/VersionHistoryPanel.tsx index 5d728427c..36972a0ed 100644 --- a/web/src/components/features/versionHistory/VersionHistoryPanel.tsx +++ b/web/src/components/features/versionHistory/VersionHistoryPanel.tsx @@ -18,7 +18,7 @@ export const VersionHistoryPanel = React.memo( ({ assetId, type }: { assetId: string; type: 'metric' | 'dashboard' }) => { const chatId = useChatLayoutContextSelector((x) => x.chatId); const onCloseVersionHistory = useCloseVersionHistory(); - const { listItems, selectedVersion, selectedQueryVersion, onClickRestoreVersion } = + const { listItems, currentVersionNumber, selectedQueryVersion, onClickRestoreVersion } = useListVersionHistories({ assetId, type @@ -55,7 +55,7 @@ export const VersionHistoryPanel = React.memo( key={item.version_number} {...item} selected={item.version_number === selectedQueryVersion} - showRestoreButton={item.version_number !== selectedVersion} + showRestoreButton={item.version_number !== currentVersionNumber} onClickRestoreVersion={onClickRestoreVersion} link={ getFileLink({ diff --git a/web/src/components/features/versionHistory/useListVersionHistories.tsx b/web/src/components/features/versionHistory/useListVersionHistories.tsx index a48caf977..5aec3d33d 100644 --- a/web/src/components/features/versionHistory/useListVersionHistories.tsx +++ b/web/src/components/features/versionHistory/useListVersionHistories.tsx @@ -23,7 +23,7 @@ export const useListVersionHistories = ({ const { dashboardVersions, selectedQueryVersion: dashboardSelectedQueryVersion, - selectedVersion: dashboardSelectedVersion, + currentVersionNumber: dashboardCurrentVersionNumber, onRestoreVersion: onRestoreDashboardVersion, isSavingDashboard } = useListDashboardVersions({ @@ -33,7 +33,7 @@ export const useListVersionHistories = ({ const { metricVersions, selectedQueryVersion: metricSelectedQueryVersion, - selectedVersion: metricSelectedVersion, + currentVersionNumber: metricCurrentVersionNumber, onRestoreVersion: onRestoreMetricVersion, isSavingMetric } = useListMetricVersions({ @@ -46,9 +46,9 @@ export const useListVersionHistories = ({ return items ? [...items].reverse() : undefined; }, [type, dashboardVersions, metricVersions]); - const selectedVersion = useMemo(() => { - return type === 'metric' ? metricSelectedVersion : dashboardSelectedVersion; - }, [type, dashboardSelectedVersion, metricSelectedVersion]); + const currentVersionNumber = useMemo(() => { + return type === 'metric' ? metricCurrentVersionNumber : dashboardCurrentVersionNumber; + }, [type, dashboardCurrentVersionNumber, metricCurrentVersionNumber]); const selectedQueryVersion = useMemo(() => { return type === 'metric' ? metricSelectedQueryVersion : dashboardSelectedQueryVersion; @@ -86,14 +86,14 @@ export const useListVersionHistories = ({ return useMemo(() => { return { listItems, - selectedVersion, + currentVersionNumber, selectedQueryVersion, onClickRestoreVersion, isRestoringVersion: isSavingDashboard || isSavingMetric }; }, [ listItems, - selectedVersion, + currentVersionNumber, selectedQueryVersion, onClickRestoreVersion, isSavingDashboard, @@ -113,10 +113,10 @@ const useListDashboardVersions = ({ saveToServer: true, updateVersion: true }); - const { data: dashData } = useGetDashboard( + const { data: dashboardData } = useGetDashboard( { id: type === 'dashboard' ? assetId : undefined, - version_number: null + versionNumber: null }, { select: (x) => ({ @@ -126,8 +126,8 @@ const useListDashboardVersions = ({ } ); - const dashboardVersions = dashData?.versions; - const selectedVersion = dashboardVersionNumber || dashData?.version_number; + const dashboardVersions = dashboardData?.versions; + const currentVersionNumber = dashboardData?.version_number; const selectedQueryVersion = useMemo(() => { if (dashboardVersionNumber) return dashboardVersionNumber; @@ -146,12 +146,12 @@ const useListDashboardVersions = ({ dashboardVersions, selectedQueryVersion, onRestoreVersion, - selectedVersion, + currentVersionNumber, isSavingDashboard }; }, [ dashboardVersions, - selectedVersion, + currentVersionNumber, onRestoreVersion, selectedQueryVersion, isSavingDashboard @@ -174,7 +174,7 @@ const useListMetricVersions = ({ const { data: metricData } = useGetMetric( { id: type === 'metric' ? assetId : undefined, - version_number: null + versionNumber: null }, { select: (x) => ({ @@ -184,7 +184,7 @@ const useListMetricVersions = ({ } ); const metricVersions = metricData?.versions; - const selectedVersion = metricVersionNumber || metricData?.version_number; + const currentVersionNumber = metricVersionNumber || metricData?.version_number; const onRestoreVersion = useMemoizedFn(async (versionNumber: number) => { await updateMetric({ @@ -203,8 +203,14 @@ const useListMetricVersions = ({ metricVersions, selectedQueryVersion, onRestoreVersion, - selectedVersion, + currentVersionNumber, isSavingMetric }; - }, [metricVersions, onRestoreVersion, selectedQueryVersion, selectedVersion, isSavingMetric]); + }, [ + metricVersions, + onRestoreVersion, + selectedQueryVersion, + currentVersionNumber, + isSavingMetric + ]); }; diff --git a/web/src/controllers/DashboardController/DashboardViewDashboardController/DashboardContentController/DashboardContentController.tsx b/web/src/controllers/DashboardController/DashboardViewDashboardController/DashboardContentController/DashboardContentController.tsx index 12b1ce83f..cb8613bcd 100644 --- a/web/src/controllers/DashboardController/DashboardViewDashboardController/DashboardContentController/DashboardContentController.tsx +++ b/web/src/controllers/DashboardController/DashboardViewDashboardController/DashboardContentController/DashboardContentController.tsx @@ -112,8 +112,6 @@ export const DashboardContentController: React.FC<{ } }, [dashboard?.id, remapMetrics]); - console.log(hasMetrics, dashboardRows, dashboard); - return (
{hasMetrics && !!dashboardRows.length && !!dashboard ? ( diff --git a/web/src/controllers/MetricController/MetricViewChart/MetricViewChart.tsx b/web/src/controllers/MetricController/MetricViewChart/MetricViewChart.tsx index d710575d5..4ea6a125c 100644 --- a/web/src/controllers/MetricController/MetricViewChart/MetricViewChart.tsx +++ b/web/src/controllers/MetricController/MetricViewChart/MetricViewChart.tsx @@ -10,8 +10,6 @@ import { MetricChartEvaluation } from './MetricChartEvaluation'; import { ChartType } from '@/api/asset_interfaces/metric/charts/enum'; import { AnimatePresence, motion } from 'framer-motion'; import { cn } from '@/lib/classMerge'; -import { canEdit } from '@/lib/share'; -import { useChatLayoutContextSelector } from '@/layouts/ChatLayout'; import { SaveResetFilePopup } from '@/components/features/popups/SaveResetFilePopup'; import { useIsMetricChanged } from '@/context/Metrics/useIsMetricChanged'; import { useUpdateMetricChart } from '@/context/Metrics';