Skip to content

Commit

Permalink
Helper function for relative time range selection
Browse files Browse the repository at this point in the history
  • Loading branch information
jmbrunskill committed Nov 9, 2023
1 parent d4681ca commit d62e3b3
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import {
EventStatus,
} from '@notify-frontend/common';

function relativeStartTime(hoursAgo: string) {
return new Date(Date.now() - parseInt(hoursAgo) * 60 * 60 * 1000);
}

export const FilterBar = ({
filter,
searchFilterKey = 'search',
Expand All @@ -17,7 +21,7 @@ export const FilterBar = ({
searchFilterKey?: string;
ActionButtons?: () => JSX.Element;
}) => {
const t = useTranslation(['system']);
const t = useTranslation('system');
const [timeRange, setTimeRange] = React.useState('all');

const filterString = (filter.filterBy?.[searchFilterKey] as string) || '';
Expand Down Expand Up @@ -112,7 +116,7 @@ export const FilterBar = ({
filter.onChangeDateFilterRule(
'createdAt',
'afterOrEqualTo',
new Date(Date.now() - parseInt(e.target.value) * 60 * 60 * 1000)
relativeStartTime(e.target.value)
);
}
}}
Expand Down

0 comments on commit d62e3b3

Please sign in to comment.