umami/components/pages/dashboard/DashboardSettingsButton.js

43 lines
1.1 KiB
JavaScript
Raw Normal View History

2022-08-04 12:56:30 +02:00
import { defineMessages, useIntl } from 'react-intl';
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';
import { Icon } from 'react-basics';
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' },
});
export default function DashboardSettingsButton() {
2022-08-04 12:56:30 +02:00
const { formatMessage } = useIntl();
const menuOptions = [
{
2022-08-04 12:56:30 +02:00
label: formatMessage(messages.toggleCharts),
value: 'charts',
},
{
2022-08-04 12:56:30 +02:00
label: formatMessage(messages.editDashboard),
value: 'order',
},
];
function handleSelect(value) {
if (value === 'charts') {
2022-08-05 06:37:18 +02:00
saveDashboard(state => ({ showCharts: !state.showCharts }));
}
if (value === 'order') {
2022-08-04 12:56:30 +02:00
saveDashboard({ editing: true });
}
}
return (
<MenuButton options={menuOptions} onSelect={handleSelect} hideLabel>
<Icon>
<Gear />
</Icon>
</MenuButton>
);
}