mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Task: Add tracking dashboard toolbar options (#77524)
* add tracking for toolbar * Add favorite * add timepicker * add reusable analytics file * change the refresh and zoom click prop function * add interaction for timepicker * decouple tracking code * update naming of function * Update packages/grafana-ui/src/components/DateTimePickers/TimeRangePicker.tsx Co-authored-by: Juan Cabanas <juan.cabanas@grafana.com> * use useEffect * remove prop from useEffect * destructure prop * add dependency on useEffect --------- Co-authored-by: Juan Cabanas <juan.cabanas@grafana.com>
This commit is contained in:
@@ -2,7 +2,7 @@ import { css, cx } from '@emotion/css';
|
|||||||
import { useDialog } from '@react-aria/dialog';
|
import { useDialog } from '@react-aria/dialog';
|
||||||
import { FocusScope } from '@react-aria/focus';
|
import { FocusScope } from '@react-aria/focus';
|
||||||
import { useOverlay } from '@react-aria/overlays';
|
import { useOverlay } from '@react-aria/overlays';
|
||||||
import React, { memo, createRef, useState } from 'react';
|
import React, { memo, createRef, useState, useEffect } from 'react';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
isDateTime,
|
isDateTime,
|
||||||
@@ -44,6 +44,7 @@ export interface TimeRangePickerProps {
|
|||||||
hideQuickRanges?: boolean;
|
hideQuickRanges?: boolean;
|
||||||
widthOverride?: number;
|
widthOverride?: number;
|
||||||
isOnCanvas?: boolean;
|
isOnCanvas?: boolean;
|
||||||
|
onToolbarTimePickerClick?: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface State {
|
export interface State {
|
||||||
@@ -68,6 +69,7 @@ export function TimeRangePicker(props: TimeRangePickerProps) {
|
|||||||
hideQuickRanges,
|
hideQuickRanges,
|
||||||
widthOverride,
|
widthOverride,
|
||||||
isOnCanvas,
|
isOnCanvas,
|
||||||
|
onToolbarTimePickerClick,
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
const onChange = (timeRange: TimeRange) => {
|
const onChange = (timeRange: TimeRange) => {
|
||||||
@@ -75,6 +77,12 @@ export function TimeRangePicker(props: TimeRangePickerProps) {
|
|||||||
setOpen(false);
|
setOpen(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isOpen && onToolbarTimePickerClick) {
|
||||||
|
onToolbarTimePickerClick();
|
||||||
|
}
|
||||||
|
}, [isOpen, onToolbarTimePickerClick]);
|
||||||
|
|
||||||
const onToolbarButtonSwitch = () => {
|
const onToolbarButtonSwitch = () => {
|
||||||
setOpen((prevState) => !prevState);
|
setOpen((prevState) => !prevState);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -35,6 +35,13 @@ import { DashboardMetaChangedEvent, ShowModalReactEvent } from 'app/types/events
|
|||||||
import { DashNavButton } from './DashNavButton';
|
import { DashNavButton } from './DashNavButton';
|
||||||
import { DashNavTimeControls } from './DashNavTimeControls';
|
import { DashNavTimeControls } from './DashNavTimeControls';
|
||||||
import { ShareButton } from './ShareButton';
|
import { ShareButton } from './ShareButton';
|
||||||
|
import {
|
||||||
|
trackToolbarFavoritesClick,
|
||||||
|
trackToolbarRefreshClick,
|
||||||
|
trackToolbarSettingsClick,
|
||||||
|
trackToolbarTimePickerClick,
|
||||||
|
trackToolbarZoomClick,
|
||||||
|
} from './analytics';
|
||||||
|
|
||||||
const mapDispatchToProps = {
|
const mapDispatchToProps = {
|
||||||
setStarred,
|
setStarred,
|
||||||
@@ -122,6 +129,7 @@ export const DashNav = React.memo<Props>((props) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onStarDashboard = () => {
|
const onStarDashboard = () => {
|
||||||
|
trackToolbarFavoritesClick();
|
||||||
const dashboardSrv = getDashboardSrv();
|
const dashboardSrv = getDashboardSrv();
|
||||||
const { dashboard, setStarred } = props;
|
const { dashboard, setStarred } = props;
|
||||||
|
|
||||||
@@ -133,6 +141,7 @@ export const DashNav = React.memo<Props>((props) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onOpenSettings = () => {
|
const onOpenSettings = () => {
|
||||||
|
trackToolbarSettingsClick();
|
||||||
locationService.partial({ editview: 'settings' });
|
locationService.partial({ editview: 'settings' });
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -242,9 +251,15 @@ export const DashNav = React.memo<Props>((props) => {
|
|||||||
if (hideTimePicker) {
|
if (hideTimePicker) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DashNavTimeControls dashboard={dashboard} onChangeTimeZone={updateTimeZoneForSession} key="time-controls" />
|
<DashNavTimeControls
|
||||||
|
dashboard={dashboard}
|
||||||
|
onChangeTimeZone={updateTimeZoneForSession}
|
||||||
|
onToolbarRefreshClick={trackToolbarRefreshClick}
|
||||||
|
onToolbarZoomClick={trackToolbarZoomClick}
|
||||||
|
onToolbarTimePickerClick={trackToolbarTimePickerClick}
|
||||||
|
key="time-controls"
|
||||||
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ export interface Props {
|
|||||||
dashboard: DashboardModel;
|
dashboard: DashboardModel;
|
||||||
onChangeTimeZone: (timeZone: TimeZone) => void;
|
onChangeTimeZone: (timeZone: TimeZone) => void;
|
||||||
isOnCanvas?: boolean;
|
isOnCanvas?: boolean;
|
||||||
|
onToolbarRefreshClick?: () => void;
|
||||||
|
onToolbarZoomClick?: () => void;
|
||||||
|
onToolbarTimePickerClick?: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class DashNavTimeControls extends Component<Props> {
|
export class DashNavTimeControls extends Component<Props> {
|
||||||
@@ -75,9 +78,19 @@ export class DashNavTimeControls extends Component<Props> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
onZoom = () => {
|
onZoom = () => {
|
||||||
|
if (this.props.onToolbarZoomClick) {
|
||||||
|
this.props.onToolbarZoomClick();
|
||||||
|
}
|
||||||
appEvents.publish(new ZoomOutEvent({ scale: 2 }));
|
appEvents.publish(new ZoomOutEvent({ scale: 2 }));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
onRefreshClick = () => {
|
||||||
|
if (this.props.onToolbarRefreshClick) {
|
||||||
|
this.props.onToolbarRefreshClick();
|
||||||
|
}
|
||||||
|
this.onRefresh();
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { dashboard, isOnCanvas } = this.props;
|
const { dashboard, isOnCanvas } = this.props;
|
||||||
const { refresh_intervals } = dashboard.timepicker;
|
const { refresh_intervals } = dashboard.timepicker;
|
||||||
@@ -106,10 +119,11 @@ export class DashNavTimeControls extends Component<Props> {
|
|||||||
onChangeTimeZone={this.onChangeTimeZone}
|
onChangeTimeZone={this.onChangeTimeZone}
|
||||||
onChangeFiscalYearStartMonth={this.onChangeFiscalYearStartMonth}
|
onChangeFiscalYearStartMonth={this.onChangeFiscalYearStartMonth}
|
||||||
isOnCanvas={isOnCanvas}
|
isOnCanvas={isOnCanvas}
|
||||||
|
onToolbarTimePickerClick={this.props.onToolbarTimePickerClick}
|
||||||
/>
|
/>
|
||||||
<RefreshPicker
|
<RefreshPicker
|
||||||
onIntervalChanged={this.onChangeRefreshInterval}
|
onIntervalChanged={this.onChangeRefreshInterval}
|
||||||
onRefresh={this.onRefresh}
|
onRefresh={this.onRefreshClick}
|
||||||
value={dashboard.refresh}
|
value={dashboard.refresh}
|
||||||
intervals={intervals}
|
intervals={intervals}
|
||||||
isOnCanvas={isOnCanvas}
|
isOnCanvas={isOnCanvas}
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
import { reportInteraction } from '@grafana/runtime';
|
||||||
|
|
||||||
|
export const shareAnalyticsEventNames: {
|
||||||
|
[key: string]: string;
|
||||||
|
} = {
|
||||||
|
dashboardsToolbarActionsClicked: 'dashboards_toolbar_actions_clicked',
|
||||||
|
};
|
||||||
|
|
||||||
|
export function trackToolbarFavoritesClick() {
|
||||||
|
reportInteraction(shareAnalyticsEventNames.dashboardsToolbarActionsClicked, { item: 'favorites' });
|
||||||
|
}
|
||||||
|
|
||||||
|
export function trackToolbarSettingsClick() {
|
||||||
|
reportInteraction(shareAnalyticsEventNames.dashboardsToolbarActionsClicked, { item: 'settings' });
|
||||||
|
}
|
||||||
|
|
||||||
|
export function trackToolbarRefreshClick() {
|
||||||
|
reportInteraction(shareAnalyticsEventNames.dashboardsToolbarActionsClicked, { item: 'refresh' });
|
||||||
|
}
|
||||||
|
|
||||||
|
export function trackToolbarTimePickerClick() {
|
||||||
|
reportInteraction(shareAnalyticsEventNames.dashboardsToolbarActionsClicked, { item: 'time_picker' });
|
||||||
|
}
|
||||||
|
|
||||||
|
export function trackToolbarZoomClick() {
|
||||||
|
reportInteraction(shareAnalyticsEventNames.dashboardsToolbarActionsClicked, { item: 'zoom_out_time_range' });
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user