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