Saved Queries: Context State Migration (#112018)
* wip: moving saved queries items to context * more wip * Tidying up unused types
This commit is contained in:
@@ -4,7 +4,7 @@ import { CoreApp } from '@grafana/data';
|
||||
import { DataQuery } from '@grafana/schema';
|
||||
import { SavedQuery } from 'app/features/explore/QueryLibrary/types';
|
||||
|
||||
import { OnSelectQueryType, QueryLibraryEventsPropertyMap } from './types';
|
||||
import { OnSelectQueryType, QueryLibraryEventsPropertyMap, QueryLibraryTab } from './types';
|
||||
|
||||
export type QueryLibraryDrawerOptions = {
|
||||
datasourceFilters?: string[];
|
||||
@@ -30,7 +30,7 @@ export type QueryLibraryContextType = {
|
||||
* @param newQuery New query to be added to the library.
|
||||
*/
|
||||
openDrawer: (options: QueryLibraryDrawerOptions) => void;
|
||||
closeDrawer: (isSelectingQuery?: boolean, isEditingQuery?: boolean) => void;
|
||||
closeDrawer: (isSelectingQuery?: boolean) => void;
|
||||
isDrawerOpen: boolean;
|
||||
onSave?: () => void;
|
||||
|
||||
@@ -73,6 +73,18 @@ export type QueryLibraryContextType = {
|
||||
) => void;
|
||||
setNewQuery: (query?: SavedQuery) => void;
|
||||
onSelectQuery: (query: DataQuery) => void;
|
||||
onFavorite: (uid: string) => void;
|
||||
onUnfavorite: (uid: string) => void;
|
||||
userFavorites: { [key: string]: boolean };
|
||||
isEditingQuery: boolean;
|
||||
setIsEditingQuery: (isEditingQuery: boolean) => void;
|
||||
onAddHistoryQueryToLibrary: (newQuery: SavedQuery) => void;
|
||||
activeTab: QueryLibraryTab;
|
||||
setActiveTab: (activeTab: QueryLibraryTab) => void;
|
||||
onTabChange: (activeTab: QueryLibraryTab) => void;
|
||||
highlightedQuery: string | undefined;
|
||||
newQuery: SavedQuery | undefined;
|
||||
activeDatasources: string[];
|
||||
/** Set a guard function that returns true to allow closing, false to prevent closing */
|
||||
setCloseGuard: (shouldAllowClose: () => boolean) => void;
|
||||
};
|
||||
@@ -97,6 +109,18 @@ export const QueryLibraryContext = createContext<QueryLibraryContextType>({
|
||||
context: 'unknown',
|
||||
triggerAnalyticsEvent: () => {},
|
||||
onSelectQuery: () => {},
|
||||
onFavorite: () => {},
|
||||
onUnfavorite: () => {},
|
||||
userFavorites: {},
|
||||
isEditingQuery: false,
|
||||
setIsEditingQuery: () => {},
|
||||
onAddHistoryQueryToLibrary: () => {},
|
||||
activeTab: QueryLibraryTab.ALL,
|
||||
setActiveTab: () => {},
|
||||
onTabChange: () => {},
|
||||
highlightedQuery: undefined,
|
||||
newQuery: undefined,
|
||||
activeDatasources: [],
|
||||
setCloseGuard: () => {},
|
||||
});
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { PropsWithChildren } from 'react';
|
||||
|
||||
import { QueryLibraryContext } from './QueryLibraryContext';
|
||||
import { QueryLibraryTab } from './types';
|
||||
|
||||
type Props = {
|
||||
queryLibraryEnabled?: boolean;
|
||||
@@ -20,6 +21,18 @@ export function QueryLibraryContextProviderMock(props: PropsWithChildren<Props>)
|
||||
triggerAnalyticsEvent: jest.fn(),
|
||||
setNewQuery: jest.fn(),
|
||||
onSelectQuery: jest.fn(),
|
||||
onFavorite: jest.fn(),
|
||||
onUnfavorite: jest.fn(),
|
||||
userFavorites: {},
|
||||
isEditingQuery: false,
|
||||
activeTab: QueryLibraryTab.ALL,
|
||||
activeDatasources: [],
|
||||
setActiveTab: jest.fn(),
|
||||
onTabChange: jest.fn(),
|
||||
setIsEditingQuery: jest.fn(),
|
||||
onAddHistoryQueryToLibrary: jest.fn(),
|
||||
highlightedQuery: undefined,
|
||||
newQuery: undefined,
|
||||
setCloseGuard: jest.fn(),
|
||||
}}
|
||||
>
|
||||
|
||||
@@ -33,3 +33,10 @@ export type SavedQuery = {
|
||||
datasourceRef?: DataSourceRef | null;
|
||||
datasourceType?: string;
|
||||
} & Omit<Partial<SavedQueryBase>, 'targets'>;
|
||||
|
||||
export enum QueryLibraryTab {
|
||||
ALL = 'all',
|
||||
FAVORITES = 'favorites',
|
||||
RECENT = 'history',
|
||||
FEEDBACK = 'feedback',
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user