Add all-time to date filter

pull/882/head
Chris Walsh 2021-12-04 02:01:17 -08:00
parent 9efd3eaa6a
commit 51bf300eb4
No known key found for this signature in database
GPG Key ID: 28EE0CCA6032019E
1 changed files with 9 additions and 2 deletions

View File

@ -1,5 +1,6 @@
import React, { useState } from 'react'; import React, { useState } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { useSelector } from 'react-redux';
import { FormattedMessage } from 'react-intl'; import { FormattedMessage } from 'react-intl';
import { endOfYear, isSameDay } from 'date-fns'; import { endOfYear, isSameDay } from 'date-fns';
import Modal from './Modal'; import Modal from './Modal';
@ -47,6 +48,11 @@ const filterOptions = [
value: '90day', value: '90day',
}, },
{ label: <FormattedMessage id="label.this-year" defaultMessage="This year" />, value: '1year' }, { label: <FormattedMessage id="label.this-year" defaultMessage="This year" />, value: '1year' },
{
label: <FormattedMessage id="label.all-time" defaultMessage="All Time" />,
value: 'all',
divider: true,
},
{ {
label: <FormattedMessage id="label.custom-range" defaultMessage="Custom range" />, label: <FormattedMessage id="label.custom-range" defaultMessage="Custom range" />,
value: 'custom', value: 'custom',
@ -54,9 +60,10 @@ const filterOptions = [
}, },
]; ];
function DateFilter({ value, startDate, endDate, onChange, className }) { function DateFilter({ value, startDate, endDate, onChange, className, websiteId = null }) {
const { locale } = useLocale(); const { locale } = useLocale();
const [showPicker, setShowPicker] = useState(false); const [showPicker, setShowPicker] = useState(false);
const createdAt = useSelector(state => state.websites[websiteId]?.createdAt);
const displayValue = const displayValue =
value === 'custom' ? ( value === 'custom' ? (
<CustomRange startDate={startDate} endDate={endDate} onClick={() => handleChange('custom')} /> <CustomRange startDate={startDate} endDate={endDate} onClick={() => handleChange('custom')} />
@ -69,7 +76,7 @@ function DateFilter({ value, startDate, endDate, onChange, className }) {
setShowPicker(true); setShowPicker(true);
return; return;
} }
onChange(getDateRange(value, locale)); onChange(getDateRange(value, locale, createdAt));
} }
function handlePickerChange(value) { function handlePickerChange(value) {