umami/components/pages/reports/FieldAggregateForm.js

42 lines
1.1 KiB
JavaScript
Raw Normal View History

2023-07-02 07:02:49 +02:00
import { Form, FormRow, Menu, Item } from 'react-basics';
2023-07-05 07:51:23 +02:00
import { useMessages } from 'hooks';
2023-07-02 07:02:49 +02:00
export default function FieldAggregateForm({ name, type, onSelect }) {
2023-07-05 07:51:23 +02:00
const { formatMessage, labels } = useMessages();
const options = {
number: [
{ label: formatMessage(labels.sum), value: 'sum' },
{ label: formatMessage(labels.average), value: 'average' },
{ label: formatMessage(labels.min), value: 'min' },
{ label: formatMessage(labels.max), value: 'max' },
],
date: [
{ label: formatMessage(labels.min), value: 'min' },
{ label: formatMessage(labels.max), value: 'max' },
],
string: [
{ label: formatMessage(labels.total), value: 'total' },
{ label: formatMessage(labels.unique), value: 'unique' },
],
};
2023-07-02 07:02:49 +02:00
const items = options[type];
const handleSelect = value => {
2023-07-05 07:51:23 +02:00
onSelect({ name, type, value });
2023-07-02 07:02:49 +02:00
};
return (
<Form>
<FormRow label={name}>
<Menu onSelect={handleSelect}>
{items.map(({ label, value }) => {
return <Item key={value}>{label}</Item>;
})}
</Menu>
</FormRow>
</Form>
);
}