update saved version numbers

This commit is contained in:
Nate Kelley 2025-05-02 12:05:23 -06:00
parent 15fbca3251
commit a8eeec7414
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
5 changed files with 18 additions and 16 deletions

View File

@ -198,6 +198,7 @@ export const useUpdateDashboardConfig = () => {
export const useCreateDashboard = () => { export const useCreateDashboard = () => {
const queryClient = useQueryClient(); const queryClient = useQueryClient();
const setOriginalDashboard = useOriginalDashboardStore((x) => x.setOriginalDashboard); const setOriginalDashboard = useOriginalDashboardStore((x) => x.setOriginalDashboard);
const setLatestDashboardVersion = useDashboardQueryStore((x) => x.onSetLatestDashboardVersion);
return useMutation({ return useMutation({
mutationFn: dashboardsCreateDashboard, mutationFn: dashboardsCreateDashboard,
onSuccess: (originalData, variables) => { onSuccess: (originalData, variables) => {
@ -214,6 +215,7 @@ export const useCreateDashboard = () => {
data data
); );
setOriginalDashboard(data.dashboard); setOriginalDashboard(data.dashboard);
setLatestDashboardVersion(data.dashboard.id, data.dashboard.version_number);
setTimeout(() => { setTimeout(() => {
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: dashboardQueryKeys.dashboardGetList().queryKey, queryKey: dashboardQueryKeys.dashboardGetList().queryKey,
@ -426,6 +428,7 @@ export const useAddAndRemoveMetricsFromDashboard = () => {
const { openErrorMessage, openConfirmModal } = useBusterNotifications(); const { openErrorMessage, openConfirmModal } = useBusterNotifications();
const ensureDashboardConfig = useEnsureDashboardConfig(false); const ensureDashboardConfig = useEnsureDashboardConfig(false);
const setOriginalDashboard = useOriginalDashboardStore((x) => x.setOriginalDashboard); const setOriginalDashboard = useOriginalDashboardStore((x) => x.setOriginalDashboard);
const setLatestDashboardVersion = useDashboardQueryStore((x) => x.onSetLatestDashboardVersion);
const addAndRemoveMetrics = useMemoizedFn( const addAndRemoveMetrics = useMemoizedFn(
async ({ async ({
@ -456,7 +459,7 @@ export const useAddAndRemoveMetricsFromDashboard = () => {
const availableSlots = MAX_NUMBER_OF_ITEMS_ON_DASHBOARD - currentMetricCount; const availableSlots = MAX_NUMBER_OF_ITEMS_ON_DASHBOARD - currentMetricCount;
const metricsToActuallyAdd = metricsToAdd.slice(0, availableSlots); const metricsToActuallyAdd = metricsToAdd.slice(0, availableSlots);
const addMethod = () => { const addMethod = async () => {
// Create the final list of metrics to include // Create the final list of metrics to include
const finalMetricIds = [ const finalMetricIds = [
...Array.from(existingMetricIds).filter((id) => !metricsToRemove.includes(id)), ...Array.from(existingMetricIds).filter((id) => !metricsToRemove.includes(id)),
@ -468,10 +471,12 @@ export const useAddAndRemoveMetricsFromDashboard = () => {
dashboardResponse.dashboard.config dashboardResponse.dashboard.config
); );
return dashboardsUpdateDashboard({ const data = await dashboardsUpdateDashboard({
id: dashboardId, id: dashboardId,
config: newConfig config: newConfig
}); });
return data;
}; };
if (metricsToAdd.length > availableSlots) { if (metricsToAdd.length > availableSlots) {
@ -507,7 +512,7 @@ export const useAddAndRemoveMetricsFromDashboard = () => {
}); });
} }
return addMethod(); return await addMethod();
} }
openErrorMessage('Failed to save metrics to dashboard'); openErrorMessage('Failed to save metrics to dashboard');
@ -525,6 +530,7 @@ export const useAddAndRemoveMetricsFromDashboard = () => {
data data
); );
setOriginalDashboard(data.dashboard); setOriginalDashboard(data.dashboard);
setLatestDashboardVersion(data.dashboard.id, data.dashboard.version_number);
} }
} }
}); });
@ -536,6 +542,7 @@ export const useAddMetricsToDashboard = () => {
const ensureDashboardConfig = useEnsureDashboardConfig(false); const ensureDashboardConfig = useEnsureDashboardConfig(false);
const setOriginalDashboard = useOriginalDashboardStore((x) => x.setOriginalDashboard); const setOriginalDashboard = useOriginalDashboardStore((x) => x.setOriginalDashboard);
const getLatestMetricVersion = useGetLatestMetricVersionMemoized(); const getLatestMetricVersion = useGetLatestMetricVersionMemoized();
const setLatestDashboardVersion = useDashboardQueryStore((x) => x.onSetLatestDashboardVersion);
const addMetricToDashboard = useMemoizedFn( const addMetricToDashboard = useMemoizedFn(
async ({ metricIds, dashboardId }: { metricIds: string[]; dashboardId: string }) => { async ({ metricIds, dashboardId }: { metricIds: string[]; dashboardId: string }) => {
@ -614,6 +621,7 @@ export const useAddMetricsToDashboard = () => {
}); });
setOriginalDashboard(data.dashboard); setOriginalDashboard(data.dashboard);
setLatestDashboardVersion(data.dashboard.id, data.dashboard.version_number);
} }
} }
}); });
@ -625,6 +633,7 @@ export const useRemoveMetricsFromDashboard = () => {
const ensureDashboardConfig = useEnsureDashboardConfig(false); const ensureDashboardConfig = useEnsureDashboardConfig(false);
const setOriginalDashboard = useOriginalDashboardStore((x) => x.setOriginalDashboard); const setOriginalDashboard = useOriginalDashboardStore((x) => x.setOriginalDashboard);
const getLatestMetricVersion = useGetLatestMetricVersionMemoized(); const getLatestMetricVersion = useGetLatestMetricVersionMemoized();
const setLatestDashboardVersion = useDashboardQueryStore((x) => x.onSetLatestDashboardVersion);
const removeMetricFromDashboard = useMemoizedFn( const removeMetricFromDashboard = useMemoizedFn(
async ({ async ({
@ -710,7 +719,12 @@ export const useRemoveMetricsFromDashboard = () => {
); );
return useMutation({ return useMutation({
mutationFn: removeMetricFromDashboard mutationFn: removeMetricFromDashboard,
onSuccess: (data) => {
if (data) {
setLatestDashboardVersion(data.dashboard.id, data.dashboard.version_number);
}
}
}); });
}; };

View File

@ -109,12 +109,6 @@ describe('barAndLineTooltipHelper', () => {
const hasMultipleShownDatasets = true; const hasMultipleShownDatasets = true;
const mockDataPoint = createMockDataPoint(); const mockDataPoint = createMockDataPoint();
console.log(JSON.stringify(mockChart, null, 2));
console.log(JSON.stringify(mockColumnLabelFormats, null, 2));
console.log(JSON.stringify(mockDataPoint, null, 2));
const result = barAndLineTooltipHelper( const result = barAndLineTooltipHelper(
[mockDataPoint], [mockDataPoint],
mockChart, mockChart,
@ -124,8 +118,6 @@ describe('barAndLineTooltipHelper', () => {
undefined undefined
); );
console.log(JSON.stringify(result, null, 2));
expect(result).toHaveLength(2); expect(result).toHaveLength(2);
// Check the value item // Check the value item

View File

@ -307,9 +307,7 @@ describe('lineSeriesBuilder', () => {
} }
}; };
const labels = lineSeriesBuilder_labels(props); const labels = lineSeriesBuilder_labels(props);
console.log(props.datasetOptions.ticks);
expect(props.datasetOptions.ticks).toHaveLength(3); expect(props.datasetOptions.ticks).toHaveLength(3);
console.log(labels);
expect(labels).toHaveLength(3); expect(labels).toHaveLength(3);
expect(typeof labels[0]).not.toBe('string'); expect(typeof labels[0]).not.toBe('string');
expect(createDayjsDate).toHaveBeenCalledWith('2023-01-01'); expect(createDayjsDate).toHaveBeenCalledWith('2023-01-01');

View File

@ -25,7 +25,6 @@ export const addLegendHeadlines = (
// const canUseRange = !hasMultipleXAxisDimensions && xIsDate; // const canUseRange = !hasMultipleXAxisDimensions && xIsDate;
// let range: string; // let range: string;
// if (canUseRange) { // if (canUseRange) {
// console.log(columnMetadata, firstXAxisDimensionName);
// const firstXAxisDimensionMetadata = columnMetadata.find( // const firstXAxisDimensionMetadata = columnMetadata.find(
// (metadata) => metadata.name === firstXAxisDimensionName // (metadata) => metadata.name === firstXAxisDimensionName
// ); // );

View File

@ -222,7 +222,6 @@ describe('useGetFileLink', () => {
fileType: 'dashboard', fileType: 'dashboard',
versionNumber: mockDashboardVersionNumber versionNumber: mockDashboardVersionNumber
}); });
console.log(meta);
expect(meta).toEqual({ expect(meta).toEqual({
link: `/dashboards/${mockDashboardId}/v${mockDashboardVersionNumber}`, link: `/dashboards/${mockDashboardId}/v${mockDashboardVersionNumber}`,