minor structural changes

This commit is contained in:
Nate Kelley 2025-04-02 22:24:37 -06:00
parent 1c00f1df62
commit 0ebfd60e84
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
3 changed files with 12 additions and 6 deletions

View File

@ -147,6 +147,7 @@ export const useSaveMetric = (params?: { updateOnSave?: boolean }) => {
mutationFn: updateMetric,
onMutate: async ({ id, restore_to_version }) => {
const isRestoringVersion = restore_to_version !== undefined;
//set the current metric to the previous it is being restored to
if (isRestoringVersion) {
const oldMetric = queryClient.getQueryData(metricsQueryKeys.metricsGetMetric(id).queryKey);
const newMetric = queryClient.getQueryData(
@ -347,12 +348,18 @@ export const useUpdateMetric = (params?: {
wait?: number;
updateOnSave?: boolean;
updateVersion?: boolean;
saveToServer?: boolean;
}) => {
const { wait = 650, updateOnSave = false, updateVersion = true } = params || {};
const {
wait = 650,
updateOnSave = false,
updateVersion = false,
saveToServer = true
} = params || {};
const queryClient = useQueryClient();
const { mutateAsync: saveMetric } = useSaveMetric({ updateOnSave });
const { run: saveMetricDebounced } = useDebounceFn(
const { run: saveMetricToServerDebounced } = useDebounceFn(
useMemoizedFn((newMetric: IBusterMetric, prevMetric: IBusterMetric) => {
const changedValues = prepareMetricUpdateMetric(newMetric, prevMetric);
if (changedValues) {
@ -383,8 +390,8 @@ export const useUpdateMetric = (params?: {
async (newMetricPartial: Partial<IBusterMetric> & { id: string }) => {
const { newMetric, prevMetric } = await combineAndSaveMetric(newMetricPartial);
if (newMetric && prevMetric) {
saveMetricDebounced(newMetric, prevMetric);
if (newMetric && prevMetric && saveToServer) {
saveMetricToServerDebounced(newMetric, prevMetric);
}
return newMetric;

View File

@ -57,7 +57,7 @@ export const MetricViewChart: React.FC<{
const showEvaluation = !!evaluation_score && !!evaluation_summary;
const onSetTitle = useMemoizedFn((title: string) => {
if (updateMetric && inputHasText(title)) {
if (inputHasText(title)) {
updateMetric({
id: metricId,
name: title

View File

@ -18,7 +18,6 @@ import type {
ScatterAxis
} from '@/api/asset_interfaces/metric/charts';
import { type updateMetric } from '@/api/buster_rest/metrics';
import { create } from 'mutative';
import { createDefaultChartConfig } from './messageAutoChartHandler';
const DEFAULT_COLUMN_SETTINGS_ENTRIES = Object.entries(DEFAULT_COLUMN_SETTINGS);