Fix date filter.

This commit is contained in:
Brian Cao 2023-08-22 12:32:36 -07:00
parent f62d23c9bc
commit 84236c0cd9
2 changed files with 23 additions and 13 deletions

View File

@ -9,7 +9,8 @@ export function WebsiteDateFilter({ websiteId }) {
const [dateRange, setDateRange] = useDateRange(websiteId);
const { value, startDate, endDate, selectedUnit } = dateRange;
const isFutureDate = isAfter(incrementDateRange(dateRange, -1).startDate, new Date());
const isFutureDate =
value !== 'all' && isAfter(incrementDateRange(dateRange, -1).startDate, new Date());
const handleChange = async value => {
setDateRange(value);
@ -32,19 +33,21 @@ export function WebsiteDateFilter({ websiteId }) {
onChange={handleChange}
showAllTime={true}
/>
<Flexbox justifyContent="center" gap={10} className={styles.container}>
<Button onClick={() => handleIncrement(1)}>
<Icon rotate={90}>
<Icons.ChevronDown />
</Icon>
</Button>
{value !== 'all' && (
<Flexbox justifyContent="center" gap={10} className={styles.container}>
<Button onClick={() => handleIncrement(1)}>
<Icon rotate={90}>
<Icons.ChevronDown />
</Icon>
</Button>
<Button onClick={() => handleIncrement(-1)} disabled={isFutureDate}>
<Icon rotate={270}>
<Icons.ChevronDown />
</Icon>
</Button>
</Flexbox>
<Button onClick={() => handleIncrement(-1)} disabled={isFutureDate}>
<Icon rotate={270}>
<Icons.ChevronDown />
</Icon>
</Button>
</Flexbox>
)}
</>
);
}

View File

@ -195,6 +195,13 @@ export function incrementDateRange(value, increment) {
const sub = num * increment;
switch (unit) {
case 'hour':
return {
...value,
startDate: subHours(startDate, sub),
endDate: subHours(endDate, sub),
value: 'range',
};
case 'day':
return {
...value,