From 8524da6810fc1ee09b7af58205d1cb3baad47b73 Mon Sep 17 00:00:00 2001 From: Mike Vesprini Date: Tue, 26 Nov 2024 20:15:24 -0800 Subject: [PATCH 1/4] Parse start and end date into state --- .../containers/complaints/complaint-filter.tsx | 2 +- frontend/src/app/providers/complaint-filter-provider.tsx | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/frontend/src/app/components/containers/complaints/complaint-filter.tsx b/frontend/src/app/components/containers/complaints/complaint-filter.tsx index bb080652a..48f66d3fd 100644 --- a/frontend/src/app/components/containers/complaints/complaint-filter.tsx +++ b/frontend/src/app/components/containers/complaints/complaint-filter.tsx @@ -82,7 +82,6 @@ export const ComplaintFilter: FC = ({ type }) => { const handleDateRangeChange = (dates: [Date, Date]) => { const [start, end] = dates; - setFilter("startDate", start); //set the time to be end of day to ensure that we also search for records after the beginning of the selected day. if (start) { start.setHours(0, 0, 0); @@ -93,6 +92,7 @@ export const ComplaintFilter: FC = ({ type }) => { end.setMilliseconds(999); } + setFilter("startDate", start); setFilter("endDate", end); }; diff --git a/frontend/src/app/providers/complaint-filter-provider.tsx b/frontend/src/app/providers/complaint-filter-provider.tsx index 309ba4aa4..6c8feed5b 100644 --- a/frontend/src/app/providers/complaint-filter-provider.tsx +++ b/frontend/src/app/providers/complaint-filter-provider.tsx @@ -52,13 +52,18 @@ const mapFilters = (complaintFilters: Partial) => { natureOfComplaintFilter, outcomeAnimalFilter, } = complaintFilters; + + // Parse the start and end date filters into Date objects if they exist. + const parsedStartDate = startDateFilter ? new Date(startDateFilter) : undefined; + const parsedEndDate = endDateFilter ? new Date(endDateFilter) : undefined; + const allFilters: Partial = { region: regionCodeFilter, zone: zoneCodeFilter, community: areaCodeFilter, officer: officerFilter, - startDate: startDateFilter, - endDate: endDateFilter, + startDate: parsedStartDate, + endDate: parsedEndDate, status: complaintStatusFilter, species: speciesCodeFilter, complaintMethod: complaintMethodFilter, From 0a246f7471b94470a95e830799c220655427da58 Mon Sep 17 00:00:00 2001 From: Mike Vesprini Date: Tue, 26 Nov 2024 20:15:47 -0800 Subject: [PATCH 2/4] Set complaint search params in map search --- frontend/src/app/store/reducers/complaints.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/src/app/store/reducers/complaints.ts b/frontend/src/app/store/reducers/complaints.ts index a782ed69c..ab21563ce 100644 --- a/frontend/src/app/store/reducers/complaints.ts +++ b/frontend/src/app/store/reducers/complaints.ts @@ -371,6 +371,7 @@ export const getMappedComplaints = try { dispatch(setComplaint(null)); + dispatch(setComplaintSearchParameters(payload)); let parameters = generateApiParameters(`${config.API_BASE_URL}/v1/complaint/map/search/${complaintType}`, { sortBy: sortColumn, From 832f3ab1c897905233ec73dadbaa7e069f41f25d Mon Sep 17 00:00:00 2001 From: Mike Vesprini Date: Wed, 27 Nov 2024 09:24:19 -0800 Subject: [PATCH 3/4] Set default end date to current date --- frontend/src/app/providers/complaint-filter-provider.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontend/src/app/providers/complaint-filter-provider.tsx b/frontend/src/app/providers/complaint-filter-provider.tsx index 6c8feed5b..1934b8c3a 100644 --- a/frontend/src/app/providers/complaint-filter-provider.tsx +++ b/frontend/src/app/providers/complaint-filter-provider.tsx @@ -55,7 +55,8 @@ const mapFilters = (complaintFilters: Partial) => { // Parse the start and end date filters into Date objects if they exist. const parsedStartDate = startDateFilter ? new Date(startDateFilter) : undefined; - const parsedEndDate = endDateFilter ? new Date(endDateFilter) : undefined; + // If start date is set and end date is not, default to current date for end date. + const parsedEndDate = endDateFilter ? new Date(endDateFilter) : parsedStartDate ? new Date() : undefined; const allFilters: Partial = { region: regionCodeFilter, From dc739ccbb1bfb05d6d86a0c36205dbefe9032e6e Mon Sep 17 00:00:00 2001 From: Mike Vesprini Date: Wed, 27 Nov 2024 10:33:29 -0800 Subject: [PATCH 4/4] Refactor nested ternary --- frontend/src/app/providers/complaint-filter-provider.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/frontend/src/app/providers/complaint-filter-provider.tsx b/frontend/src/app/providers/complaint-filter-provider.tsx index 1934b8c3a..9f4678565 100644 --- a/frontend/src/app/providers/complaint-filter-provider.tsx +++ b/frontend/src/app/providers/complaint-filter-provider.tsx @@ -56,7 +56,12 @@ const mapFilters = (complaintFilters: Partial) => { // Parse the start and end date filters into Date objects if they exist. const parsedStartDate = startDateFilter ? new Date(startDateFilter) : undefined; // If start date is set and end date is not, default to current date for end date. - const parsedEndDate = endDateFilter ? new Date(endDateFilter) : parsedStartDate ? new Date() : undefined; + let parsedEndDate = undefined; + if (endDateFilter) { + parsedEndDate = new Date(endDateFilter); + } else if (parsedStartDate) { + parsedEndDate = new Date(); + } const allFilters: Partial = { region: regionCodeFilter,