From 5166bef908e90bc9946f65797ba0acaae99922b1 Mon Sep 17 00:00:00 2001 From: Katie Rischpater <98350084+the-bay-kay@users.noreply.github.com> Date: Mon, 8 Jan 2024 16:00:51 -0800 Subject: [PATCH] Added to WSOD fix on metrics tab When selecting date, the following behavior occurs: - If 2+ days, behave as normal (Range of Day1 -> Day2) - If "open Ended" (i.e., only start is picked), fetch a range of days between that day and present (Day1 -> Today) - If 1 day, fetch range for 48 hours from that day TODO: The 1 day range going to 48 hours is meant as a patch, so that this WSOD fix can go to staging. To make a single day only fetch 24 hrs, some changes to the server may be needed. --- www/js/metrics/MetricsDateSelect.tsx | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/www/js/metrics/MetricsDateSelect.tsx b/www/js/metrics/MetricsDateSelect.tsx index ec6eed13e..014b5a00c 100644 --- a/www/js/metrics/MetricsDateSelect.tsx +++ b/www/js/metrics/MetricsDateSelect.tsx @@ -35,19 +35,24 @@ const MetricsDateSelect = ({ dateRange, setDateRange }: Props) => { const onChoose = useCallback( ({ startDate, endDate }) => { - const dtStartDate = DateTime.fromJSDate(startDate).startOf('day') + const dtStartDate = DateTime.fromJSDate(startDate).startOf('day'); let dtEndDate; - if(!endDate) { // For when only one day is selected - dtEndDate = dtStartDate.endOf('day').minus({minutes: 1}); - } - else { - dtEndDate = DateTime.fromJSDate(endDate).startOf('day') + + if (!endDate) { + // If no end date selected, pull range from then till present day + dtEndDate = DateTime.now(); + } else if ( + dtStartDate.toString() === DateTime.fromJSDate(endDate).startOf('day').toString() + ) { + // For when only one day is selected + // NOTE: As written, this technically timestamp will technically fetch _two_ days. + // For more info, see: https://github.com/e-mission/e-mission-docs/issues/1027 + dtEndDate = dtStartDate.endOf('day'); + } else { + dtEndDate = DateTime.fromJSDate(endDate).startOf('day'); } setOpen(false); - setDateRange([ - dtStartDate, - dtEndDate, - ]); + setDateRange([dtStartDate, dtEndDate]); }, [setOpen, setDateRange], );