mirror of https://github.com/buster-so/buster.git
pass prevent
This commit is contained in:
parent
d255c5a719
commit
81a59370d4
|
@ -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,8 +22,11 @@ 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 (
|
||||||
|
<React.Fragment>
|
||||||
<div className="flex w-full items-center space-x-2.5">
|
<div className="flex w-full items-center space-x-2.5">
|
||||||
<div className="flex items-center space-x-1">
|
<div className="flex items-center space-x-1">
|
||||||
<TriangleWarning />
|
<TriangleWarning />
|
||||||
|
@ -50,6 +54,21 @@ const SplitterContent: React.FC<{
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<PreventNavigation
|
||||||
|
title="Unsaved changes"
|
||||||
|
isDirty={open}
|
||||||
|
description="Are you sure you want to leave this page?"
|
||||||
|
onOk={() => {
|
||||||
|
onSave();
|
||||||
|
return Promise.resolve();
|
||||||
|
}}
|
||||||
|
onCancel={() => {
|
||||||
|
onReset();
|
||||||
|
return Promise.resolve();
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</React.Fragment>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -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,
|
||||||
|
|
Loading…
Reference in New Issue