diff --git a/public/app/features/explore/QueryLibrary/QueryLibraryContext.tsx b/public/app/features/explore/QueryLibrary/QueryLibraryContext.tsx index 1e0e571f8e4..1ac7ef7cd97 100644 --- a/public/app/features/explore/QueryLibrary/QueryLibraryContext.tsx +++ b/public/app/features/explore/QueryLibrary/QueryLibraryContext.tsx @@ -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({ queryLibraryEnabled: false, context: 'unknown', + triggerAnalyticsEvent: () => {}, }); export function useQueryLibraryContext() { diff --git a/public/app/features/explore/QueryLibrary/mocks.tsx b/public/app/features/explore/QueryLibrary/mocks.tsx index ccb6b1c6b99..2c25a64e0bc 100644 --- a/public/app/features/explore/QueryLibrary/mocks.tsx +++ b/public/app/features/explore/QueryLibrary/mocks.tsx @@ -16,6 +16,7 @@ export function QueryLibraryContextProviderMock(props: PropsWithChildren) renderSaveQueryButton: jest.fn(), queryLibraryEnabled: Boolean(props.queryLibraryEnabled), context: 'explore', + triggerAnalyticsEvent: jest.fn(), setNewQuery: jest.fn(), }} > diff --git a/public/app/features/explore/QueryLibrary/types.ts b/public/app/features/explore/QueryLibrary/types.ts index 1877b30c3df..e8890c0b778 100644 --- a/public/app/features/explore/QueryLibrary/types.ts +++ b/public/app/features/explore/QueryLibrary/types.ts @@ -8,6 +8,8 @@ export type User = { export type OnSelectQueryType = (query: DataQuery) => void; +export type QueryLibraryEventsPropertyMap = Record; + export type QueryTemplate = { query: DataQuery; datasourceName?: string;