Files
grafana/public/app/features/dashboard/components/AddPanelButton/AddPanelButton.tsx
Polina Boneva 4db6679460 [Chore] Dashboard: Tests for dashboard's add content buttons and menu (#66233)
* add tests for empty dashboard page

* add tests for AddPanelButton

* export default components

* test +Add menu in dashboard page

* use userEvent instead of firing an event on the DOM itself

* fix test to match new analytic events
2023-06-08 11:16:08 +01:00

65 lines
1.8 KiB
TypeScript

import { css, cx } from '@emotion/css';
import React, { useState } from 'react';
import { GrafanaTheme2 } from '@grafana/data';
import { selectors } from '@grafana/e2e-selectors';
import { Dropdown, Button, useTheme2, Icon } from '@grafana/ui';
import { Trans } from 'app/core/internationalization';
import { DashboardModel } from 'app/features/dashboard/state';
import AddPanelMenu from './AddPanelMenu';
export interface Props {
dashboard: DashboardModel;
}
const AddPanelButton = ({ dashboard }: Props) => {
const styles = getStyles(useTheme2());
const [isMenuOpen, setIsMenuOpen] = useState(false);
return (
<Dropdown
overlay={() => <AddPanelMenu dashboard={dashboard} />}
placement="bottom"
offset={[0, 6]}
onVisibleChange={setIsMenuOpen}
>
<Button
icon="panel-add"
size="lg"
fill="text"
className={cx(styles.button, styles.buttonIcon, styles.buttonText)}
data-testid={selectors.components.PageToolbar.itemButton('Add button')}
>
<Trans i18nKey="dashboard.toolbar.add">Add</Trans>
<Icon name={isMenuOpen ? 'angle-up' : 'angle-down'} size="lg" />
</Button>
</Dropdown>
);
};
export default AddPanelButton;
function getStyles(theme: GrafanaTheme2) {
return {
button: css({
label: 'add-panel-button',
padding: theme.spacing(0.5, 0.5, 0.5, 0.75),
height: theme.spacing((theme.components.height.sm + theme.components.height.md) / 2),
borderRadius: theme.shape.radius.default,
}),
buttonIcon: css({
svg: {
margin: 0,
},
}),
buttonText: css({
label: 'add-panel-button-text',
fontSize: theme.typography.body.fontSize,
span: {
marginLeft: theme.spacing(0.67),
},
}),
};
}