pass prevent

This commit is contained in:
Nate Kelley 2025-04-01 13:32:27 -06:00
parent d255c5a719
commit 81a59370d4
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
4 changed files with 47 additions and 36 deletions

View File

@ -3,6 +3,7 @@ import React from 'react';
import { Text } from '@/components/ui/typography'; import { Text } from '@/components/ui/typography';
import { Button } from '@/components/ui/buttons'; import { Button } from '@/components/ui/buttons';
import { Command, ReturnKey, TriangleWarning } from '@/components/ui/icons'; import { Command, ReturnKey, TriangleWarning } from '@/components/ui/icons';
import { PreventNavigation } from '@/components/ui/layouts/PreventNavigation';
export const SaveResetFilePopup: React.FC<{ export const SaveResetFilePopup: React.FC<{
open: boolean; open: boolean;
@ -12,7 +13,7 @@ export const SaveResetFilePopup: React.FC<{
}> = React.memo(({ open, onReset, onSave, isSaving = false }) => { }> = React.memo(({ open, onReset, onSave, isSaving = false }) => {
return ( return (
<PopupContainer show={open}> <PopupContainer show={open}>
<SplitterContent onReset={onReset} onSave={onSave} isSaving={isSaving} /> <SplitterContent onReset={onReset} onSave={onSave} isSaving={isSaving} open={open} />
</PopupContainer> </PopupContainer>
); );
}); });
@ -21,35 +22,53 @@ const SplitterContent: React.FC<{
onReset: () => void; onReset: () => void;
onSave: () => void; onSave: () => void;
isSaving: boolean; isSaving: boolean;
}> = React.memo(({ onReset, onSave, isSaving }) => { open: boolean;
}> = React.memo(({ onReset, onSave, isSaving, open }) => {
console.log(open);
return ( return (
<div className="flex w-full items-center space-x-2.5"> <React.Fragment>
<div className="flex items-center space-x-1"> <div className="flex w-full items-center space-x-2.5">
<TriangleWarning /> <div className="flex items-center space-x-1">
<Text>Unsaved changes</Text> <TriangleWarning />
<Text>Unsaved changes</Text>
</div>
<PopupSplitter />
<div className="flex items-center space-x-2">
<Button variant={'default'} onClick={onReset}>
Reset
</Button>
<Button
className="flex items-center"
variant="black"
onClick={onSave}
loading={isSaving}
suffix={
<div className="flex space-x-1">
<Command />
<ReturnKey />
</div>
}>
Save
</Button>
</div>
</div> </div>
<PopupSplitter /> <PreventNavigation
title="Unsaved changes"
<div className="flex items-center space-x-2"> isDirty={open}
<Button variant={'default'} onClick={onReset}> description="Are you sure you want to leave this page?"
Reset onOk={() => {
</Button> onSave();
<Button return Promise.resolve();
className="flex items-center" }}
variant="black" onCancel={() => {
onClick={onSave} onReset();
loading={isSaving} return Promise.resolve();
suffix={ }}
<div className="flex space-x-1"> />
<Command /> </React.Fragment>
<ReturnKey />
</div>
}>
Save
</Button>
</div>
</div>
); );
}); });

View File

@ -48,6 +48,7 @@ export const PreventNavigation: React.FC<PreventNavigationProps> = React.memo(
if (isDirty) { if (isDirty) {
event.preventDefault(); event.preventDefault();
event.stopPropagation();
confirmationFn.current = () => { confirmationFn.current = () => {
router.push(target.href); router.push(target.href);

View File

@ -25,8 +25,6 @@ export const MetricViewResults: React.FC<{ metricId: string }> = React.memo(({ m
saveSQL, saveSQL,
saveMetricError, saveMetricError,
runSQLError, runSQLError,
warnBeforeNavigating,
setWarnBeforeNavigating,
isSavingMetric, isSavingMetric,
isRunningSQL isRunningSQL
} = useMetricRunSQL(); } = useMetricRunSQL();

View File

@ -29,8 +29,6 @@ export const useMetricRunSQL = () => {
} = useRunSQLQuery(); } = useRunSQLQuery();
const { openSuccessNotification } = useBusterNotifications(); const { openSuccessNotification } = useBusterNotifications();
const [warnBeforeNavigating, setWarnBeforeNavigating] = useState(false);
const getDataByMetricIdMemoized = useMemoizedFn( const getDataByMetricIdMemoized = useMemoizedFn(
(metricId: string): BusterMetricData | undefined => { (metricId: string): BusterMetricData | undefined => {
const options = queryKeys.metricsGetData(metricId); const options = queryKeys.metricsGetData(metricId);
@ -126,7 +124,6 @@ export const useMetricRunSQL = () => {
); );
const resetRunSQLData = useMemoizedFn(({ metricId }: { metricId: string }) => { const resetRunSQLData = useMemoizedFn(({ metricId }: { metricId: string }) => {
setWarnBeforeNavigating(false);
if (!originalConfigs.current) return; if (!originalConfigs.current) return;
const oldConfig = originalConfigs.current?.chartConfig; const oldConfig = originalConfigs.current?.chartConfig;
updateMetricMutation({ updateMetricMutation({
@ -173,8 +170,6 @@ export const useMetricRunSQL = () => {
sql sql
}); });
setWarnBeforeNavigating(false);
if (originalConfigs.current) { if (originalConfigs.current) {
onSetDataForMetric({ onSetDataForMetric({
metricId, metricId,
@ -198,8 +193,6 @@ export const useMetricRunSQL = () => {
return { return {
runSQL, runSQL,
resetRunSQLData, resetRunSQLData,
warnBeforeNavigating,
setWarnBeforeNavigating,
saveSQL, saveSQL,
saveMetricError: saveMetricError?.message, saveMetricError: saveMetricError?.message,
runSQLError: runSQLError?.message, runSQLError: runSQLError?.message,