Disable all-time filter as default date range
parent
4947509cb4
commit
95380a9844
|
@ -1,4 +1,4 @@
|
||||||
import React, { useState } from 'react';
|
import React, { useMemo, useState } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { useSelector } from 'react-redux';
|
import { useSelector } from 'react-redux';
|
||||||
import { FormattedMessage } from 'react-intl';
|
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 { locale } = useLocale();
|
||||||
const [showPicker, setShowPicker] = useState(false);
|
const [showPicker, setShowPicker] = useState(false);
|
||||||
const createdAt = useSelector(state => state.websites[websiteId]?.createdAt);
|
const createdAt = useSelector(state => state.websites[websiteId]?.createdAt);
|
||||||
|
@ -71,6 +79,15 @@ function DateFilter({ value, startDate, endDate, onChange, className, websiteId
|
||||||
value
|
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) {
|
function handleChange(value) {
|
||||||
if (value === 'custom') {
|
if (value === 'custom') {
|
||||||
setShowPicker(true);
|
setShowPicker(true);
|
||||||
|
@ -89,7 +106,7 @@ function DateFilter({ value, startDate, endDate, onChange, className, websiteId
|
||||||
<DropDown
|
<DropDown
|
||||||
className={className}
|
className={className}
|
||||||
value={displayValue}
|
value={displayValue}
|
||||||
options={filterOptions}
|
options={filteredOptions}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
/>
|
/>
|
||||||
{showPicker && (
|
{showPicker && (
|
||||||
|
|
|
@ -19,7 +19,13 @@ export default function DateRangeSetting() {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<DateFilter value={value} startDate={startDate} endDate={endDate} onChange={setDateRange} />
|
<DateFilter
|
||||||
|
value={value}
|
||||||
|
startDate={startDate}
|
||||||
|
endDate={endDate}
|
||||||
|
onChange={setDateRange}
|
||||||
|
disableOptions={['all']}
|
||||||
|
/>
|
||||||
<Button className={styles.button} size="small" onClick={handleReset}>
|
<Button className={styles.button} size="small" onClick={handleReset}>
|
||||||
<FormattedMessage id="label.reset" defaultMessage="Reset" />
|
<FormattedMessage id="label.reset" defaultMessage="Reset" />
|
||||||
</Button>
|
</Button>
|
||||||
|
|
Loading…
Reference in New Issue