2022-03-02 08:03:50 +01:00
|
|
|
import React from 'react';
|
2022-08-04 12:56:30 +02:00
|
|
|
import { defineMessages, useIntl } from 'react-intl';
|
2022-03-02 08:03:50 +01:00
|
|
|
import MenuButton from 'components/common/MenuButton';
|
|
|
|
import Gear from 'assets/gear.svg';
|
2022-08-04 12:56:30 +02:00
|
|
|
import { saveDashboard } from 'store/dashboard';
|
2022-12-27 01:57:59 +01:00
|
|
|
import { Icon } from 'react-basics';
|
2022-03-02 08:03:50 +01:00
|
|
|
|
2022-08-04 12:56:30 +02:00
|
|
|
const messages = defineMessages({
|
|
|
|
toggleCharts: { id: 'message.toggle-charts', defaultMessage: 'Toggle charts' },
|
|
|
|
editDashboard: { id: 'message.edit-dashboard', defaultMessage: 'Edit dashboard' },
|
|
|
|
});
|
2022-03-02 08:03:50 +01:00
|
|
|
|
|
|
|
export default function DashboardSettingsButton() {
|
2022-08-04 12:56:30 +02:00
|
|
|
const { formatMessage } = useIntl();
|
2022-03-02 08:03:50 +01:00
|
|
|
|
|
|
|
const menuOptions = [
|
|
|
|
{
|
2022-08-04 12:56:30 +02:00
|
|
|
label: formatMessage(messages.toggleCharts),
|
2022-03-02 08:03:50 +01:00
|
|
|
value: 'charts',
|
|
|
|
},
|
2022-07-25 08:25:04 +02:00
|
|
|
{
|
2022-08-04 12:56:30 +02:00
|
|
|
label: formatMessage(messages.editDashboard),
|
2022-07-25 08:25:04 +02:00
|
|
|
value: 'order',
|
|
|
|
},
|
2022-03-02 08:03:50 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
function handleSelect(value) {
|
|
|
|
if (value === 'charts') {
|
2022-08-05 06:37:18 +02:00
|
|
|
saveDashboard(state => ({ showCharts: !state.showCharts }));
|
2022-03-02 08:03:50 +01:00
|
|
|
}
|
2022-07-25 08:25:04 +02:00
|
|
|
if (value === 'order') {
|
2022-08-04 12:56:30 +02:00
|
|
|
saveDashboard({ editing: true });
|
2022-07-25 08:25:04 +02:00
|
|
|
}
|
2022-03-02 08:03:50 +01:00
|
|
|
}
|
|
|
|
|
2022-12-27 01:57:59 +01:00
|
|
|
return (
|
|
|
|
<MenuButton options={menuOptions} onSelect={handleSelect} hideLabel>
|
|
|
|
<Icon>
|
|
|
|
<Gear />
|
|
|
|
</Icon>
|
|
|
|
</MenuButton>
|
|
|
|
);
|
2022-03-02 08:03:50 +01:00
|
|
|
}
|