grafana/public/app/features/dashboard/components/AddPanelButton/AddPanelMenu.tsx
Polina Boneva 2f0f5ca09e
[Chore] Dashboard: Add i18n for creating a panel, row, library panel, and pasted panel (#66234)
* add translation keys for empty dashboard redesign

* run yarn i18n:extract; rephrase one trans key because of [warning] Found translation key already mapped to a map or parent of new key already mapped to a string: dashboard.toolbar.add.visualization

* reduce to 3-step locale phrase IDs

* extract phrase IDs
2023-04-20 10:35:29 -04:00

66 lines
2.2 KiB
TypeScript

import React, { useMemo } from 'react';
import { selectors } from '@grafana/e2e-selectors';
import { locationService, reportInteraction } from '@grafana/runtime';
import { Menu } from '@grafana/ui';
import { t } from 'app/core/internationalization';
import { DashboardModel } from 'app/features/dashboard/state';
import {
getCopiedPanelPlugin,
onAddLibraryPanel,
onCreateNewPanel,
onCreateNewRow,
onPasteCopiedPanel,
} from 'app/features/dashboard/utils/dashboard';
interface Props {
dashboard: DashboardModel;
}
export const AddPanelMenu = ({ dashboard }: Props) => {
const copiedPanelPlugin = useMemo(() => getCopiedPanelPlugin(), []);
return (
<Menu>
<Menu.Item
key="add-visualisation"
label={t('dashboard.add-menu.visualization', 'Visualization')}
testId={selectors.components.PageToolbar.itemButton('Add new visualization menu item')}
onClick={() => {
reportInteraction('Create new panel');
const id = onCreateNewPanel(dashboard);
locationService.partial({ editPanel: id });
}}
/>
<Menu.Item
key="add-row"
label={t('dashboard.add-menu.row', 'Row')}
testId={selectors.components.PageToolbar.itemButton('Add new row menu item')}
onClick={() => {
reportInteraction('Create new row');
onCreateNewRow(dashboard);
}}
/>
<Menu.Item
key="add-panel-lib"
label={t('dashboard.add-menu.import', 'Import from library')}
testId={selectors.components.PageToolbar.itemButton('Add new panel from panel library menu item')}
onClick={() => {
reportInteraction('Add a panel from the panel library');
onAddLibraryPanel(dashboard);
}}
/>
<Menu.Item
key="add-panel-clipboard"
label={t('dashboard.add-menu.paste-panel', 'Paste panel')}
testId={selectors.components.PageToolbar.itemButton('Add new panel from clipboard menu item')}
onClick={() => {
reportInteraction('Paste panel from clipboard');
onPasteCopiedPanel(dashboard, copiedPanelPlugin);
}}
disabled={!copiedPanelPlugin}
/>
</Menu>
);
};