Disable all-time filter as default date range

This commit is contained in:
Chris Walsh 2021-12-04 15:32:25 -08:00
parent 4947509cb4
commit 95380a9844
No known key found for this signature in database
GPG key ID: 28EE0CCA6032019E
2 changed files with 27 additions and 4 deletions

View file

@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useMemo, useState } from 'react';
import PropTypes from 'prop-types';
import { useSelector } from 'react-redux';
import { FormattedMessage } from 'react-intl';
@ -60,7 +60,15 @@ const filterOptions = [
},
];
function DateFilter({ value, startDate, endDate, onChange, className, websiteId = null }) {
function DateFilter({
value,
startDate,
endDate,
onChange,
className,
websiteId = null,
disableOptions = [],
}) {
const { locale } = useLocale();
const [showPicker, setShowPicker] = useState(false);
const createdAt = useSelector(state => state.websites[websiteId]?.createdAt);
@ -71,6 +79,15 @@ function DateFilter({ value, startDate, endDate, onChange, className, websiteId
value
);
const filteredOptions = useMemo(() => {
const clone = [...filterOptions];
for (const option of disableOptions) {
const index = clone.findIndex(a => a.value == option);
if (index >= 0) clone.splice(index, 1);
}
return clone;
}, [disableOptions]);
function handleChange(value) {
if (value === 'custom') {
setShowPicker(true);
@ -89,7 +106,7 @@ function DateFilter({ value, startDate, endDate, onChange, className, websiteId
<DropDown
className={className}
value={displayValue}
options={filterOptions}
options={filteredOptions}
onChange={handleChange}
/>
{showPicker && (