From 72bb2b5180daf030f3ebae9e40f973a5f437d112 Mon Sep 17 00:00:00 2001 From: Joe Bacal Date: Tue, 23 Jul 2024 15:10:07 -0400 Subject: [PATCH] Adjust date-range related status message logic - Do not show station active message when no date range is selected - In cases where user requests data from before a station existed, show station inactive warning --- src/components/App.tsx | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/components/App.tsx b/src/components/App.tsx index a97670e..b0b880a 100755 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -159,7 +159,24 @@ export const App = () => { const maxDate = endDate || new Date(Date.now()); guaranteeGlobal(globalMinDate, Number(minDate)/1000); guaranteeGlobal(globalMaxDate, Number(maxDate)/1000); - }, [endDate, startDate, weatherStations]); + if (weatherStation && (!startDate || !endDate)) { + setStatus({ + status: "error", + message: "Select a date range", + icon: + }); + } + // if the start date of the weather station is after the user's requested end date, then the station is inactive + const stationMinDate = new Date(weatherStation?.mindate || globalMinDate); + const stationNotActiveYet = stationMinDate > maxDate; + if (stationNotActiveYet) { + setStatus({ + status: "station-error", + message: "Station was inactive for date range", + icon: + }); + } + }, [endDate, startDate, weatherStations, weatherStation]); const stationSelectionHandler = async(req: any) =>{ if (req.values.operation === "selectCases") { @@ -237,7 +254,7 @@ export const App = () => { setIsFetching(false); setStatus({ status: "error", - message: "No data retrieved. Try different frequency or station.", + message: "No data retrieved. Change frequency or station.", icon: }); }