mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
Co-authored-by: Alexandra Vargas <alexa1866@gmail.com> Co-authored-by: Ivan Ortega Alba <ivanortegaalba@gmail.com>
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import React, { FC } from 'react';
|
|
|
|
import { Menu, Dropdown, Button, Icon } from '@grafana/ui';
|
|
|
|
export interface Props {
|
|
folderId?: number;
|
|
canCreateFolders?: boolean;
|
|
canCreateDashboards?: boolean;
|
|
}
|
|
|
|
export const DashboardActions: FC<Props> = ({ folderId, canCreateFolders = false, canCreateDashboards = false }) => {
|
|
const actionUrl = (type: string) => {
|
|
let url = `dashboard/${type}`;
|
|
|
|
if (folderId) {
|
|
url += `?folderId=${folderId}`;
|
|
}
|
|
|
|
return url;
|
|
};
|
|
|
|
const MenuActions = () => {
|
|
return (
|
|
<Menu>
|
|
{canCreateDashboards && <Menu.Item url={actionUrl('new')} label="New Dashboard" />}
|
|
{!folderId && canCreateFolders && <Menu.Item url="dashboards/folder/new" label="New Folder" />}
|
|
{canCreateDashboards && <Menu.Item url={actionUrl('import')} label="Import" />}
|
|
</Menu>
|
|
);
|
|
};
|
|
|
|
return (
|
|
<div>
|
|
<Dropdown overlay={MenuActions} placement="bottom-start">
|
|
<Button variant="primary">
|
|
New
|
|
<Icon name="angle-down" />
|
|
</Button>
|
|
</Dropdown>
|
|
</div>
|
|
);
|
|
};
|