Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable https://github.com/opentripplanner/otp-react-redux/pull/1266 in call taker #1295

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions lib/components/form/call-taker/date-time-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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'
Expand Down Expand Up @@ -187,6 +197,18 @@ const DateTimeOptions = ({
})
})
}

if (
syncSortWithDepartArrive &&
DepartArriveTypeMap[departArrive as DepartArriveValue] !== sort.type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cast departArrive wherever you get it from

Copy link
Collaborator Author

@miles-grant-ibigroup miles-grant-ibigroup Nov 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a useState. TS doesn't like me typing it at definition time

) {
updateItineraryFilter({
sort: {
...sort,
type: DepartArriveTypeMap[departArrive as DepartArriveValue]
}
})
}
}, [dateTime, departArrive, homeTimezone, setQueryParam])

// Handler for updating the time and date fields when NOW is selected
Expand Down Expand Up @@ -283,11 +305,18 @@ const DateTimeOptions = ({

// connect to the redux store
const mapStateToProps = (state: any) => {
miles-grant-ibigroup marked this conversation as resolved.
Show resolved Hide resolved
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)
4 changes: 2 additions & 2 deletions lib/components/form/date-time-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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']
> = {
Expand Down
Loading