QueryLibrary: Added new way to trigger events w/ context (#109637)

This commit is contained in:
Collin Fingar
2025-08-18 10:13:04 -04:00
committed by GitHub
parent 87e8c92aa4
commit 828c2b6612
3 changed files with 10 additions and 1 deletions
@@ -3,7 +3,7 @@ import { createContext, ReactNode, useContext } from 'react';
import { CoreApp } from '@grafana/data';
import { DataQuery } from '@grafana/schema';
import { OnSelectQueryType, QueryTemplate } from './types';
import { OnSelectQueryType, QueryTemplate, QueryLibraryEventsPropertyMap } from './types';
export type QueryLibraryDrawerOptions = {
datasourceFilters?: string[];
@@ -46,6 +46,11 @@ export type QueryLibraryContextType = {
) => ReactNode;
queryLibraryEnabled: boolean;
context: string;
triggerAnalyticsEvent: (
handleAnalyticEvent: (properties?: QueryLibraryEventsPropertyMap) => void,
properties?: QueryLibraryEventsPropertyMap,
contextOverride?: string
) => void;
setNewQuery: (query?: QueryTemplate) => void;
};
@@ -63,6 +68,7 @@ export const QueryLibraryContext = createContext<QueryLibraryContextType>({
queryLibraryEnabled: false,
context: 'unknown',
triggerAnalyticsEvent: () => {},
});
export function useQueryLibraryContext() {
@@ -16,6 +16,7 @@ export function QueryLibraryContextProviderMock(props: PropsWithChildren<Props>)
renderSaveQueryButton: jest.fn(),
queryLibraryEnabled: Boolean(props.queryLibraryEnabled),
context: 'explore',
triggerAnalyticsEvent: jest.fn(),
setNewQuery: jest.fn(),
}}
>
@@ -8,6 +8,8 @@ export type User = {
export type OnSelectQueryType = (query: DataQuery) => void;
export type QueryLibraryEventsPropertyMap = Record<string, string | boolean | undefined>;
export type QueryTemplate = {
query: DataQuery;
datasourceName?: string;