2020-07-31 05:11:43 +02:00
|
|
|
import React from 'react';
|
2020-07-28 10:17:45 +02:00
|
|
|
import { getDateRange } from 'lib/date';
|
2020-07-31 05:11:43 +02:00
|
|
|
import DropDown from './DropDown';
|
2020-09-06 02:27:01 +02:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2020-07-28 10:17:45 +02:00
|
|
|
|
2020-07-31 05:11:43 +02:00
|
|
|
const filterOptions = [
|
2020-09-06 02:27:01 +02:00
|
|
|
{
|
|
|
|
label: (
|
|
|
|
<FormattedMessage id="label.last-hours" defaultMessage="Last {x} hours" values={{ x: 24 }} />
|
|
|
|
),
|
|
|
|
value: '24hour',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: (
|
|
|
|
<FormattedMessage id="label.last-days" defaultMessage="Last {x} days" values={{ x: 7 }} />
|
|
|
|
),
|
|
|
|
value: '7day',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: (
|
|
|
|
<FormattedMessage id="label.last-days" defaultMessage="Last {x} days" values={{ x: 30 }} />
|
|
|
|
),
|
|
|
|
value: '30day',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: (
|
|
|
|
<FormattedMessage id="label.last-days" defaultMessage="Last {x} days" values={{ x: 90 }} />
|
|
|
|
),
|
|
|
|
value: '90day',
|
|
|
|
},
|
|
|
|
{ label: <FormattedMessage id="label.today" defaultMessage="Today" />, value: '1day' },
|
|
|
|
{ label: <FormattedMessage id="label.this-week" defaultMessage="This week" />, value: '1week' },
|
|
|
|
{
|
|
|
|
label: <FormattedMessage id="label.this-month" defaultMessage="This month" />,
|
|
|
|
value: '1month',
|
|
|
|
},
|
|
|
|
{ label: <FormattedMessage id="label.this-year" defaultMessage="This year" />, value: '1year' },
|
2020-07-31 05:11:43 +02:00
|
|
|
];
|
2020-07-28 10:17:45 +02:00
|
|
|
|
2020-08-02 06:20:52 +02:00
|
|
|
export default function DateFilter({ value, onChange, className }) {
|
2020-07-31 05:11:43 +02:00
|
|
|
function handleChange(value) {
|
2020-07-28 10:17:45 +02:00
|
|
|
onChange(getDateRange(value));
|
|
|
|
}
|
|
|
|
|
2020-08-02 06:20:52 +02:00
|
|
|
return (
|
|
|
|
<DropDown className={className} value={value} options={filterOptions} onChange={handleChange} />
|
|
|
|
);
|
2020-07-28 10:17:45 +02:00
|
|
|
}
|