grafana/public/app/features/search/page/reporting.ts
Torkel Ödegaard 915ebcf832
Search: Refactor state and logic to be less fragmented and spread out (#57973)
* Started search state refactor

* Things are working

* Move more to statemanger

* minor tweaks

* Fixed name of hook

* revert yarn.lock changes

* Harderning StateManagerBase

* More tests and refinements

* Fixed unit test

* More polish

* fixing tests

* fixed test

* Fixed test
2022-11-03 08:29:39 +01:00

57 lines
2.0 KiB
TypeScript

import { config, reportInteraction } from '@grafana/runtime';
import { InspectTab } from 'app/features/inspector/types';
import { EventTrackingNamespace, SearchLayout } from '../types';
interface QueryProps {
layout: SearchLayout;
starred: boolean;
sortValue: string;
query: string;
tagCount: number;
includePanels?: boolean;
}
export const reportDashboardListViewed = (eventTrackingNamespace: EventTrackingNamespace, query: QueryProps) => {
reportInteraction(`${eventTrackingNamespace}_viewed`, getQuerySearchContext(query));
};
export const reportSearchResultInteraction = (eventTrackingNamespace: EventTrackingNamespace, query: QueryProps) => {
reportInteraction(`${eventTrackingNamespace}_result_clicked`, getQuerySearchContext(query));
};
export const reportSearchQueryInteraction = (eventTrackingNamespace: EventTrackingNamespace, query: QueryProps) => {
reportInteraction(`${eventTrackingNamespace}_query_submitted`, getQuerySearchContext(query));
};
export const reportSearchFailedQueryInteraction = (
eventTrackingNamespace: EventTrackingNamespace,
{ error, ...query }: QueryProps & { error?: string }
) => {
reportInteraction(`${eventTrackingNamespace}_query_failed`, { ...getQuerySearchContext(query), error });
};
export const reportPanelInspectInteraction = (
PanelInspectType: InspectTab,
name: string,
properties?: Record<string, boolean | string>
) => {
reportInteraction(`grafana_panel_inspect_${PanelInspectType}_${name}_clicked`, properties);
};
const getQuerySearchContext = (query: QueryProps) => {
const showPreviews = query.layout === SearchLayout.Grid;
const previewsEnabled = Boolean(config.featureToggles.panelTitleSearch);
const previews = previewsEnabled ? (showPreviews ? 'on' : 'off') : 'feature_disabled';
return {
previews,
layout: query.layout,
starredFilter: query.starred ?? false,
sort: query.sortValue ?? '',
tagCount: query.tagCount ?? 0,
queryLength: query.query?.length ?? 0,
includePanels: query.includePanels ?? false,
};
};