2023-02-10 11:26:57 +00:00
|
|
|
import { Menu, Icon, Text, PopupTrigger, Popup, Item, Button } from 'react-basics';
|
|
|
|
|
import Icons from 'components/icons';
|
2022-08-04 10:56:30 +00:00
|
|
|
import { saveDashboard } from 'store/dashboard';
|
2023-03-22 21:05:55 +00:00
|
|
|
import useMessages from 'hooks/useMessages';
|
2022-03-02 07:03:50 +00:00
|
|
|
|
|
|
|
|
export default function DashboardSettingsButton() {
|
2023-03-22 21:05:55 +00:00
|
|
|
const { formatMessage, labels } = useMessages();
|
2022-03-02 07:03:50 +00:00
|
|
|
|
|
|
|
|
const menuOptions = [
|
|
|
|
|
{
|
2023-03-22 21:05:55 +00:00
|
|
|
label: formatMessage(labels.toggleCharts),
|
2022-03-02 07:03:50 +00:00
|
|
|
value: 'charts',
|
|
|
|
|
},
|
2022-07-25 06:25:04 +00:00
|
|
|
{
|
2023-03-22 21:05:55 +00:00
|
|
|
label: formatMessage(labels.editDashboard),
|
2022-07-25 06:25:04 +00:00
|
|
|
value: 'order',
|
|
|
|
|
},
|
2022-03-02 07:03:50 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
function handleSelect(value) {
|
|
|
|
|
if (value === 'charts') {
|
2022-08-05 04:37:18 +00:00
|
|
|
saveDashboard(state => ({ showCharts: !state.showCharts }));
|
2022-03-02 07:03:50 +00:00
|
|
|
}
|
2022-07-25 06:25:04 +00:00
|
|
|
if (value === 'order') {
|
2022-08-04 10:56:30 +00:00
|
|
|
saveDashboard({ editing: true });
|
2022-07-25 06:25:04 +00:00
|
|
|
}
|
2022-03-02 07:03:50 +00:00
|
|
|
}
|
|
|
|
|
|
2022-12-27 00:57:59 +00:00
|
|
|
return (
|
2023-02-10 11:26:57 +00:00
|
|
|
<PopupTrigger>
|
|
|
|
|
<Button>
|
|
|
|
|
<Icon>
|
|
|
|
|
<Icons.Edit />
|
|
|
|
|
</Icon>
|
|
|
|
|
<Text>{formatMessage(labels.edit)}</Text>
|
|
|
|
|
</Button>
|
|
|
|
|
<Popup alignment="end">
|
|
|
|
|
<Menu variant="popup" items={menuOptions} onSelect={handleSelect}>
|
|
|
|
|
{({ label, value }) => <Item key={value}>{label}</Item>}
|
|
|
|
|
</Menu>
|
|
|
|
|
</Popup>
|
|
|
|
|
</PopupTrigger>
|
2022-12-27 00:57:59 +00:00
|
|
|
);
|
2022-03-02 07:03:50 +00:00
|
|
|
}
|