From d62e3b3e641c5d3de41e4110ce22d86abfeab149 Mon Sep 17 00:00:00 2001 From: James Brunskill Date: Thu, 9 Nov 2023 15:09:52 +1300 Subject: [PATCH] Helper function for relative time range selection --- .../system/src/NotificationEvents/ListView/FilterBar.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/frontend/packages/system/src/NotificationEvents/ListView/FilterBar.tsx b/frontend/packages/system/src/NotificationEvents/ListView/FilterBar.tsx index eed6c30b..347e9c6d 100644 --- a/frontend/packages/system/src/NotificationEvents/ListView/FilterBar.tsx +++ b/frontend/packages/system/src/NotificationEvents/ListView/FilterBar.tsx @@ -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', @@ -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) || ''; @@ -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) ); } }}