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

View File

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

View File

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

View File

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