From 32f1912311286fc1fd93d93877b6a1d91fd087cc Mon Sep 17 00:00:00 2001 From: Alexa Vargas <239999+axelavargas@users.noreply.github.com> Date: Mon, 13 Oct 2025 13:47:12 +0200 Subject: [PATCH] Saved Query: Add closeGuard function to support modal warning for unsaved changes (#111940) * Saved Query: Add closeGuard function to support modal warning for unsaved changes * fix signature --- .../app/features/explore/QueryLibrary/QueryLibraryContext.tsx | 3 +++ public/app/features/explore/QueryLibrary/mocks.tsx | 1 + 2 files changed, 4 insertions(+) diff --git a/public/app/features/explore/QueryLibrary/QueryLibraryContext.tsx b/public/app/features/explore/QueryLibrary/QueryLibraryContext.tsx index db9e131b771..4d72a56f1a1 100644 --- a/public/app/features/explore/QueryLibrary/QueryLibraryContext.tsx +++ b/public/app/features/explore/QueryLibrary/QueryLibraryContext.tsx @@ -73,6 +73,8 @@ export type QueryLibraryContextType = { ) => void; setNewQuery: (query?: SavedQuery) => void; onSelectQuery: (query: DataQuery) => void; + /** Set a guard function that returns true to allow closing, false to prevent closing */ + setCloseGuard: (shouldAllowClose: () => boolean) => void; }; export const QueryLibraryContext = createContext({ @@ -95,6 +97,7 @@ export const QueryLibraryContext = createContext({ context: 'unknown', triggerAnalyticsEvent: () => {}, onSelectQuery: () => {}, + setCloseGuard: () => {}, }); export function useQueryLibraryContext() { diff --git a/public/app/features/explore/QueryLibrary/mocks.tsx b/public/app/features/explore/QueryLibrary/mocks.tsx index a2af3c29278..bbac5371e3b 100644 --- a/public/app/features/explore/QueryLibrary/mocks.tsx +++ b/public/app/features/explore/QueryLibrary/mocks.tsx @@ -20,6 +20,7 @@ export function QueryLibraryContextProviderMock(props: PropsWithChildren) triggerAnalyticsEvent: jest.fn(), setNewQuery: jest.fn(), onSelectQuery: jest.fn(), + setCloseGuard: jest.fn(), }} > {props.children}