From bd1a770f9c51f5bb8fba0be977515f3e61ffc871 Mon Sep 17 00:00:00 2001 From: Rafael Benitez Date: Fri, 26 Sep 2025 00:44:00 -0300 Subject: [PATCH 1/2] fix discard button not closing the modal --- superset-frontend/src/hooks/useUnsavedChangesPrompt/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/superset-frontend/src/hooks/useUnsavedChangesPrompt/index.ts b/superset-frontend/src/hooks/useUnsavedChangesPrompt/index.ts index b09adece6afa..172e389c249d 100644 --- a/superset-frontend/src/hooks/useUnsavedChangesPrompt/index.ts +++ b/superset-frontend/src/hooks/useUnsavedChangesPrompt/index.ts @@ -41,6 +41,7 @@ export const useUnsavedChangesPrompt = ({ const manualSaveRef = useRef(false); // Track if save was user-initiated (not via navigation) const handleConfirmNavigation = useCallback(() => { + setShowModal(false); confirmNavigationRef.current?.(); }, []); From bfb8540b9f3981f0f8492527bd61c9431a5f160f Mon Sep 17 00:00:00 2001 From: Rafael Benitez Date: Fri, 26 Sep 2025 15:18:39 -0300 Subject: [PATCH 2/2] test added --- .../useUnsavedChangesPrompt.test.tsx | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/superset-frontend/src/hooks/useUnsavedChangesPrompt/useUnsavedChangesPrompt.test.tsx b/superset-frontend/src/hooks/useUnsavedChangesPrompt/useUnsavedChangesPrompt.test.tsx index bc42cdcfc91d..9e70ee2648e8 100644 --- a/superset-frontend/src/hooks/useUnsavedChangesPrompt/useUnsavedChangesPrompt.test.tsx +++ b/superset-frontend/src/hooks/useUnsavedChangesPrompt/useUnsavedChangesPrompt.test.tsx @@ -103,4 +103,33 @@ describe('useUnsavedChangesPrompt', () => { expect(onSave).toHaveBeenCalled(); expect(result.current.showModal).toBe(false); }); + + it('should close modal when handleConfirmNavigation is called', () => { + const onSave = jest.fn(); + + const { result } = renderHook( + () => + useUnsavedChangesPrompt({ + hasUnsavedChanges: true, + onSave, + }), + { wrapper }, + ); + + // First, trigger navigation to show the modal + act(() => { + const unblock = history.block((tx: any) => tx); + unblock(); + history.push('/another-page'); + }); + + expect(result.current.showModal).toBe(true); + + // Then call handleConfirmNavigation to discard changes + act(() => { + result.current.handleConfirmNavigation(); + }); + + expect(result.current.showModal).toBe(false); + }); });