From 6a5166be9f0848bbc7c1cd94b85f896f54c7ddb2 Mon Sep 17 00:00:00 2001 From: miles-grant-ibigroup Date: Tue, 3 Dec 2024 14:27:28 -0500 Subject: [PATCH] auto-set sort direction on sort type change --- lib/components/form/call-taker/date-time-picker.tsx | 7 ++++++- lib/components/form/date-time-modal.tsx | 13 +++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/components/form/call-taker/date-time-picker.tsx b/lib/components/form/call-taker/date-time-picker.tsx index 96292df86..f2304a5fb 100644 --- a/lib/components/form/call-taker/date-time-picker.tsx +++ b/lib/components/form/call-taker/date-time-picker.tsx @@ -8,7 +8,11 @@ import coreUtils from '@opentripplanner/core-utils' import React, { useEffect, useRef, useState } from 'react' import { AppReduxState, FilterType, SortType } from '../../../util/state-types' -import { DepartArriveTypeMap, DepartArriveValue } from '../date-time-modal' +import { + DepartArriveDirectionMap, + DepartArriveTypeMap, + DepartArriveValue +} from '../date-time-modal' import { updateItineraryFilter } from '../../../actions/narrative' const { getCurrentDate, OTP_API_DATE_FORMAT, OTP_API_TIME_FORMAT } = @@ -205,6 +209,7 @@ const DateTimeOptions = ({ importedUpdateItineraryFilter({ sort: { ...sort, + direction: DepartArriveDirectionMap[departArrive] || sort.direction, type: DepartArriveTypeMap[departArrive] } }) diff --git a/lib/components/form/date-time-modal.tsx b/lib/components/form/date-time-modal.tsx index bd7082eef..cf0f26337 100644 --- a/lib/components/form/date-time-modal.tsx +++ b/lib/components/form/date-time-modal.tsx @@ -32,6 +32,15 @@ export const DepartArriveTypeMap: Record< NOW: 'DURATION' } +export const DepartArriveDirectionMap: Record< + DepartArriveValue, + FilterType['sort']['direction'] +> = { + ARRIVE: 'ASC', + DEPART: 'DESC', + NOW: 'DESC' +} + function DateTimeModal({ config, date, @@ -57,6 +66,10 @@ function DateTimeModal({ updateItineraryFilter({ sort: { ...sort, + direction: + DepartArriveDirectionMap[ + params.departArrive as DepartArriveValue + ] || sort.direction, type: DepartArriveTypeMap[params.departArrive as DepartArriveValue] } })