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

View file

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