From 3112eae8c3208d860f8ff9f4c0400971e8f9a796 Mon Sep 17 00:00:00 2001 From: miles-grant-ibigroup Date: Tue, 22 Oct 2024 10:18:36 -0400 Subject: [PATCH 1/4] sync departArrive in calltaker as well --- .../form/call-taker/date-time-picker.tsx | 35 +++++++++++++++++-- lib/components/form/date-time-modal.tsx | 4 +-- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/lib/components/form/call-taker/date-time-picker.tsx b/lib/components/form/call-taker/date-time-picker.tsx index 282c104cc..ea310ef99 100644 --- a/lib/components/form/call-taker/date-time-picker.tsx +++ b/lib/components/form/call-taker/date-time-picker.tsx @@ -7,6 +7,10 @@ import { OverlayTrigger, Tooltip } from 'react-bootstrap' import coreUtils from '@opentripplanner/core-utils' import React, { useEffect, useRef, useState } from 'react' +import * as narriativeActions from '../../../actions/narrative' +import { DepartArriveTypeMap, DepartArriveValue } from '../date-time-modal' +import { FilterType, SortType } from '../../../util/state-types' + const { getCurrentDate, OTP_API_DATE_FORMAT, OTP_API_TIME_FORMAT } = coreUtils.time @@ -80,8 +84,11 @@ type Props = { departArrive: string time: string }) => void + sort: SortType + syncSortWithDepartArrive?: boolean time?: string timeFormat: string + updateItineraryFilter: (payload: FilterType) => void } /** * Contains depart/arrive selector and time/date inputs for the admin-oriented @@ -103,8 +110,11 @@ const DateTimeOptions = ({ homeTimezone, onKeyDown, setQueryParam, + sort, + syncSortWithDepartArrive, time: initialTime, - timeFormat + timeFormat, + updateItineraryFilter }: Props) => { const [departArrive, setDepartArrive] = useState( initialDate || initialTime ? 'DEPART' : 'NOW' @@ -187,6 +197,18 @@ const DateTimeOptions = ({ }) }) } + + if ( + syncSortWithDepartArrive && + DepartArriveTypeMap[departArrive as DepartArriveValue] !== sort.type + ) { + updateItineraryFilter({ + sort: { + ...sort, + type: DepartArriveTypeMap[departArrive as DepartArriveValue] + } + }) + } }, [dateTime, departArrive, homeTimezone, setQueryParam]) // Handler for updating the time and date fields when NOW is selected @@ -283,11 +305,18 @@ const DateTimeOptions = ({ // connect to the redux store const mapStateToProps = (state: any) => { - const { dateTime, homeTimezone } = state.otp.config + const { dateTime, homeTimezone, itinerary } = state.otp.config + const { syncSortWithDepartArrive } = itinerary + const { sort } = state.otp.filter return { homeTimezone, + sort, + syncSortWithDepartArrive, timeFormat: dateTime?.timeFormat || 'h:mm a' } } +const mapDispatchToProps = { + updateItineraryFilter: narriativeActions.updateItineraryFilter +} -export default connect(mapStateToProps)(DateTimeOptions) +export default connect(mapStateToProps, mapDispatchToProps)(DateTimeOptions) diff --git a/lib/components/form/date-time-modal.tsx b/lib/components/form/date-time-modal.tsx index e9f31407b..bd7082eef 100644 --- a/lib/components/form/date-time-modal.tsx +++ b/lib/components/form/date-time-modal.tsx @@ -21,9 +21,9 @@ type Props = { updateItineraryFilter: (payload: FilterType) => void } -type DepartArriveValue = 'NOW' | 'DEPART' | 'ARRIVE' +export type DepartArriveValue = 'NOW' | 'DEPART' | 'ARRIVE' -const DepartArriveTypeMap: Record< +export const DepartArriveTypeMap: Record< DepartArriveValue, FilterType['sort']['type'] > = { From 8ce18b29279bbed75f9e5a1fec47c0c7621d4024 Mon Sep 17 00:00:00 2001 From: miles-grant-ibigroup Date: Thu, 14 Nov 2024 16:24:50 -0500 Subject: [PATCH 2/4] address pr feedback --- lib/components/form/call-taker/date-time-picker.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/components/form/call-taker/date-time-picker.tsx b/lib/components/form/call-taker/date-time-picker.tsx index ea310ef99..7cf2101e8 100644 --- a/lib/components/form/call-taker/date-time-picker.tsx +++ b/lib/components/form/call-taker/date-time-picker.tsx @@ -8,8 +8,8 @@ import coreUtils from '@opentripplanner/core-utils' import React, { useEffect, useRef, useState } from 'react' import * as narriativeActions from '../../../actions/narrative' +import { AppReduxState, FilterType, SortType } from '../../../util/state-types' import { DepartArriveTypeMap, DepartArriveValue } from '../date-time-modal' -import { FilterType, SortType } from '../../../util/state-types' const { getCurrentDate, OTP_API_DATE_FORMAT, OTP_API_TIME_FORMAT } = coreUtils.time @@ -304,8 +304,9 @@ const DateTimeOptions = ({ } // connect to the redux store -const mapStateToProps = (state: any) => { +const mapStateToProps = (state: AppReduxState) => { const { dateTime, homeTimezone, itinerary } = state.otp.config + // @ts-expect-error TS doesn't understand it's fine if this value is undefined const { syncSortWithDepartArrive } = itinerary const { sort } = state.otp.filter return { From ac2e27457caee17edf9e634404b52c91b1049570 Mon Sep 17 00:00:00 2001 From: Daniel Heppner Date: Mon, 18 Nov 2024 17:43:04 -0500 Subject: [PATCH 3/4] fix typescript for @miles-grant-ibigroup --- .../form/call-taker/date-time-picker.tsx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/components/form/call-taker/date-time-picker.tsx b/lib/components/form/call-taker/date-time-picker.tsx index 7cf2101e8..3fddd8444 100644 --- a/lib/components/form/call-taker/date-time-picker.tsx +++ b/lib/components/form/call-taker/date-time-picker.tsx @@ -1,5 +1,5 @@ import { connect } from 'react-redux' -import { format, toDate } from 'date-fns-tz' +import { format, OptionsWithTZ, toDate } from 'date-fns-tz' import { getCurrentTime } from '@opentripplanner/core-utils/lib/time' import { IntlShape, useIntl } from 'react-intl' import { isMatch, parse } from 'date-fns' @@ -60,7 +60,7 @@ const SUPPORTED_TIME_FORMATS = [ 'HH:mm' ] -const safeFormat = (date: Date | '', time: string, options: any) => { +const safeFormat = (date: Date | '', time: string, options?: OptionsWithTZ) => { if (date === '') return '' try { return format(date, time, options) @@ -72,7 +72,7 @@ const safeFormat = (date: Date | '', time: string, options: any) => { type Props = { date?: string - departArrive?: string + departArrive?: DepartArriveValue homeTimezone: string onKeyDown: () => void setQueryParam: ({ @@ -116,7 +116,7 @@ const DateTimeOptions = ({ timeFormat, updateItineraryFilter }: Props) => { - const [departArrive, setDepartArrive] = useState( + const [departArrive, setDepartArrive] = useState( initialDate || initialTime ? 'DEPART' : 'NOW' ) const [date, setDate] = useState(initialDate) @@ -200,12 +200,12 @@ const DateTimeOptions = ({ if ( syncSortWithDepartArrive && - DepartArriveTypeMap[departArrive as DepartArriveValue] !== sort.type + DepartArriveTypeMap[departArrive] !== sort.type ) { updateItineraryFilter({ sort: { ...sort, - type: DepartArriveTypeMap[departArrive as DepartArriveValue] + type: DepartArriveTypeMap[departArrive] } }) } @@ -231,8 +231,8 @@ const DateTimeOptions = ({ return ( <>