mirror of https://github.com/buster-so/buster.git
reset file popup changes
This commit is contained in:
parent
0648f2929a
commit
7f2ae891fa
|
@ -25,6 +25,7 @@ export const SaveResetFilePopup: React.FC<{
|
||||||
open={open}
|
open={open}
|
||||||
showHotsKeys={showHotsKeys}
|
showHotsKeys={showHotsKeys}
|
||||||
/>
|
/>
|
||||||
|
</PopupContainer>
|
||||||
|
|
||||||
<PreventNavigation
|
<PreventNavigation
|
||||||
title="Unsaved changes"
|
title="Unsaved changes"
|
||||||
|
@ -33,7 +34,6 @@ export const SaveResetFilePopup: React.FC<{
|
||||||
onOk={onSave}
|
onOk={onSave}
|
||||||
onCancel={onReset}
|
onCancel={onReset}
|
||||||
/>
|
/>
|
||||||
</PopupContainer>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useMemoizedFn, useMount } from '@/hooks';
|
import { useMemoizedFn, useMount, useUnmount } from '@/hooks';
|
||||||
import { useRouter } from 'next/navigation';
|
import { useRouter } from 'next/navigation';
|
||||||
import { useState, useRef, useEffect, useMemo } from 'react';
|
import { useState, useRef, useEffect, useMemo } from 'react';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
@ -190,6 +190,7 @@ export const PreventNavigation: React.FC<PreventNavigationProps> = React.memo(
|
||||||
if (!isDirty) return null;
|
if (!isDirty) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<>
|
||||||
<LeavingDialog
|
<LeavingDialog
|
||||||
{...props}
|
{...props}
|
||||||
canceling={canceling}
|
canceling={canceling}
|
||||||
|
@ -201,6 +202,7 @@ export const PreventNavigation: React.FC<PreventNavigationProps> = React.memo(
|
||||||
noCallback={noCallback}
|
noCallback={noCallback}
|
||||||
yesCallback={yesCallback}
|
yesCallback={yesCallback}
|
||||||
/>
|
/>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -5,6 +5,7 @@ import { metricsQueryKeys } from '@/api/query_keys/metric';
|
||||||
import { useGetMetric } from '@/api/buster_rest/metrics';
|
import { useGetMetric } from '@/api/buster_rest/metrics';
|
||||||
import { compareObjectsByKeys } from '@/lib/objects';
|
import { compareObjectsByKeys } from '@/lib/objects';
|
||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
|
import last from 'lodash/last';
|
||||||
|
|
||||||
export const useIsMetricChanged = ({ metricId }: { metricId: string | undefined }) => {
|
export const useIsMetricChanged = ({ metricId }: { metricId: string | undefined }) => {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
@ -23,10 +24,14 @@ export const useIsMetricChanged = ({ metricId }: { metricId: string | undefined
|
||||||
description: x.description,
|
description: x.description,
|
||||||
chart_config: x.chart_config,
|
chart_config: x.chart_config,
|
||||||
file: x.file,
|
file: x.file,
|
||||||
version_number: x.version_number
|
version_number: x.version_number,
|
||||||
|
versions: x.versions
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
const isLatestVersion = useMemo(() => {
|
||||||
|
return currentMetric?.version_number === last(currentMetric?.versions)?.version_number;
|
||||||
|
}, [currentMetric]);
|
||||||
|
|
||||||
const onResetMetricToOriginal = useMemoizedFn(() => {
|
const onResetMetricToOriginal = useMemoizedFn(() => {
|
||||||
const options = metricsQueryKeys.metricsGetMetric(
|
const options = metricsQueryKeys.metricsGetMetric(
|
||||||
|
@ -39,9 +44,10 @@ export const useIsMetricChanged = ({ metricId }: { metricId: string | undefined
|
||||||
refetchCurrentMetric();
|
refetchCurrentMetric();
|
||||||
});
|
});
|
||||||
|
|
||||||
const isMetricChanged = useMemo(
|
const isMetricChanged = useMemo(() => {
|
||||||
() =>
|
if (!originalMetric || !isLatestVersion) return false;
|
||||||
!originalMetric ||
|
|
||||||
|
return (
|
||||||
!currentMetric ||
|
!currentMetric ||
|
||||||
!compareObjectsByKeys(originalMetric, currentMetric, [
|
!compareObjectsByKeys(originalMetric, currentMetric, [
|
||||||
'name',
|
'name',
|
||||||
|
@ -49,9 +55,9 @@ export const useIsMetricChanged = ({ metricId }: { metricId: string | undefined
|
||||||
'chart_config',
|
'chart_config',
|
||||||
'file',
|
'file',
|
||||||
'version_number'
|
'version_number'
|
||||||
]),
|
])
|
||||||
[originalMetric, currentMetric]
|
|
||||||
);
|
);
|
||||||
|
}, [originalMetric, currentMetric, isLatestVersion]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
onResetMetricToOriginal,
|
onResetMetricToOriginal,
|
||||||
|
|
|
@ -117,5 +117,8 @@ export const useChatInputFlow = ({
|
||||||
textAreaRef.current?.select();
|
textAreaRef.current?.select();
|
||||||
});
|
});
|
||||||
|
|
||||||
return { onSubmitPreflight, onStopChat };
|
return useMemo(
|
||||||
|
() => ({ onSubmitPreflight, onStopChat, isFileChanged }),
|
||||||
|
[onSubmitPreflight, onStopChat, isFileChanged]
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue