Ensured the 'all' item is selected when custom date ranges are unselected

This commit is contained in:
Alejandro Celaya 2021-10-03 21:09:48 +02:00
parent c71e0919e9
commit 4c1d285d04

View file

@ -29,7 +29,7 @@ export const DateRangeSelector = (
!rangeIsInterval(initialDateRange) ? initialDateRange : undefined, !rangeIsInterval(initialDateRange) ? initialDateRange : undefined,
); );
const updateDateRange = (dateRange: DateRange) => { const updateDateRange = (dateRange: DateRange) => {
setActiveInterval(undefined); setActiveInterval(dateRangeIsEmpty(dateRange) ? 'all' : undefined);
setActiveDateRange(dateRange); setActiveDateRange(dateRange);
onDatesChange(dateRange); onDatesChange(dateRange);
}; };
@ -43,7 +43,7 @@ export const DateRangeSelector = (
<DropdownBtn disabled={disabled} text={rangeOrIntervalToString(activeInterval ?? activeDateRange) ?? defaultText}> <DropdownBtn disabled={disabled} text={rangeOrIntervalToString(activeInterval ?? activeDateRange) ?? defaultText}>
<DateIntervalDropdownItems <DateIntervalDropdownItems
allText={defaultText} allText={defaultText}
active={!dateRangeIsEmpty(activeDateRange) ? undefined : activeInterval} active={activeInterval}
onChange={(interval) => updateInterval(interval)()} onChange={(interval) => updateInterval(interval)()}
/> />
<DropdownItem divider /> <DropdownItem divider />