Skip to content

Commit 50e2a06

Browse files
rebenitez1802sadpandajoe
authored andcommitted
fix(explore): close unsaved changes modal when discarding changes (#35307)
(cherry picked from commit d8688cf)
1 parent e80f447 commit 50e2a06

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

superset-frontend/src/hooks/useUnsavedChangesPrompt/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export const useUnsavedChangesPrompt = ({
4141
const manualSaveRef = useRef(false); // Track if save was user-initiated (not via navigation)
4242

4343
const handleConfirmNavigation = useCallback(() => {
44+
setShowModal(false);
4445
confirmNavigationRef.current?.();
4546
}, []);
4647

superset-frontend/src/hooks/useUnsavedChangesPrompt/useUnsavedChangesPrompt.test.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,33 @@ describe('useUnsavedChangesPrompt', () => {
103103
expect(onSave).toHaveBeenCalled();
104104
expect(result.current.showModal).toBe(false);
105105
});
106+
107+
it('should close modal when handleConfirmNavigation is called', () => {
108+
const onSave = jest.fn();
109+
110+
const { result } = renderHook(
111+
() =>
112+
useUnsavedChangesPrompt({
113+
hasUnsavedChanges: true,
114+
onSave,
115+
}),
116+
{ wrapper },
117+
);
118+
119+
// First, trigger navigation to show the modal
120+
act(() => {
121+
const unblock = history.block((tx: any) => tx);
122+
unblock();
123+
history.push('/another-page');
124+
});
125+
126+
expect(result.current.showModal).toBe(true);
127+
128+
// Then call handleConfirmNavigation to discard changes
129+
act(() => {
130+
result.current.handleConfirmNavigation();
131+
});
132+
133+
expect(result.current.showModal).toBe(false);
134+
});
106135
});

0 commit comments

Comments
 (0)