mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
[Navigation] Add user events for quick actions/dashboard actions (#62220)
Add fe events for quick actions/dashboard actions
This commit is contained in:
@@ -4,10 +4,18 @@ import React from 'react';
|
||||
import { Provider } from 'react-redux';
|
||||
|
||||
import { NavModelItem, NavSection } from '@grafana/data';
|
||||
import { reportInteraction } from '@grafana/runtime';
|
||||
import { configureStore } from 'app/store/configureStore';
|
||||
|
||||
import { QuickAdd } from './QuickAdd';
|
||||
|
||||
jest.mock('@grafana/runtime', () => {
|
||||
return {
|
||||
...jest.requireActual('@grafana/runtime'),
|
||||
reportInteraction: jest.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
const setup = () => {
|
||||
const navBarTree: NavModelItem[] = [
|
||||
{
|
||||
@@ -16,7 +24,7 @@ const setup = () => {
|
||||
id: 'section1',
|
||||
url: 'section1',
|
||||
children: [
|
||||
{ text: 'New child 1', id: 'child1', url: 'section1/child1', isCreateAction: true },
|
||||
{ text: 'New child 1', id: 'child1', url: '#', isCreateAction: true },
|
||||
{ text: 'Child2', id: 'child2', url: 'section1/child2' },
|
||||
],
|
||||
},
|
||||
@@ -50,4 +58,15 @@ describe('QuickAdd', () => {
|
||||
expect(screen.getByRole('link', { name: 'New child 1' })).toBeInTheDocument();
|
||||
expect(screen.getByRole('link', { name: 'New child 3' })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('reports interaction when a menu item is clicked', async () => {
|
||||
setup();
|
||||
await userEvent.click(screen.getByRole('button', { name: 'New' }));
|
||||
await userEvent.click(screen.getByRole('link', { name: 'New child 1' }));
|
||||
|
||||
expect(reportInteraction).toHaveBeenCalledWith('grafana_menu_item_clicked', {
|
||||
url: '#',
|
||||
from: 'quickadd',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,6 +2,7 @@ import { css } from '@emotion/css';
|
||||
import React, { useMemo, useState } from 'react';
|
||||
|
||||
import { GrafanaTheme2 } from '@grafana/data';
|
||||
import { reportInteraction } from '@grafana/runtime';
|
||||
import { Menu, Dropdown, useStyles2, useTheme2, ToolbarButton } from '@grafana/ui';
|
||||
import { useMediaQueryChange } from 'app/core/hooks/useMediaQueryChange';
|
||||
import { useSelector } from 'app/types';
|
||||
@@ -32,7 +33,12 @@ export const QuickAdd = ({}: Props) => {
|
||||
return (
|
||||
<Menu>
|
||||
{createActions.map((createAction, index) => (
|
||||
<Menu.Item key={index} url={createAction.url} label={createAction.text} />
|
||||
<Menu.Item
|
||||
key={index}
|
||||
url={createAction.url}
|
||||
label={createAction.text}
|
||||
onClick={() => reportInteraction('grafana_menu_item_clicked', { url: createAction.url, from: 'quickadd' })}
|
||||
/>
|
||||
))}
|
||||
</Menu>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user