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

Merged
merged 7 commits into from
Nov 22, 2024
Merged
Changes from all commits
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
56 changes: 49 additions & 7 deletions __tests__/components/__snapshots__/date-time-options.js.snap
Original file line number Diff line number Diff line change
@@ -28,8 +28,14 @@ exports[`components > form > call-taker > date time options should correctly han
>
<DateTimeOptions
date="2022-11-17"
dispatch={[Function]}
homeTimezone="America/Los_Angeles"
importedUpdateItineraryFilter={[Function]}
sort={
Object {
"direction": "ASC",
"type": "BEST",
}
}
time="12a"
timeFormat="h:mm a"
>
@@ -145,8 +151,14 @@ exports[`components > form > call-taker > date time options should correctly han
>
<DateTimeOptions
date="2022-11-17"
dispatch={[Function]}
homeTimezone="America/Los_Angeles"
importedUpdateItineraryFilter={[Function]}
sort={
Object {
"direction": "ASC",
"type": "BEST",
}
}
time="12p"
timeFormat="h:mm a"
>
@@ -262,8 +274,14 @@ exports[`components > form > call-taker > date time options should correctly han
>
<DateTimeOptions
date="2022-11-17"
dispatch={[Function]}
homeTimezone="America/Los_Angeles"
importedUpdateItineraryFilter={[Function]}
sort={
Object {
"direction": "ASC",
"type": "BEST",
}
}
time="133"
timeFormat="h:mm a"
>
@@ -379,8 +397,14 @@ exports[`components > form > call-taker > date time options should correctly han
>
<DateTimeOptions
date="2022-11-17"
dispatch={[Function]}
homeTimezone="America/Los_Angeles"
importedUpdateItineraryFilter={[Function]}
sort={
Object {
"direction": "ASC",
"type": "BEST",
}
}
time="133p"
timeFormat="h:mm a"
>
@@ -496,8 +520,14 @@ exports[`components > form > call-taker > date time options should correctly han
>
<DateTimeOptions
date="2022-11-17"
dispatch={[Function]}
homeTimezone="America/Los_Angeles"
importedUpdateItineraryFilter={[Function]}
sort={
Object {
"direction": "ASC",
"type": "BEST",
}
}
time="135p"
timeFormat="h:mm a"
>
@@ -613,8 +643,14 @@ exports[`components > form > call-taker > date time options should correctly han
>
<DateTimeOptions
date="2022-11-17"
dispatch={[Function]}
homeTimezone="America/Los_Angeles"
importedUpdateItineraryFilter={[Function]}
sort={
Object {
"direction": "ASC",
"type": "BEST",
}
}
time="1335"
timeFormat="h:mm a"
>
@@ -730,8 +766,14 @@ exports[`components > form > call-taker > date time options should render 1`] =
>
<DateTimeOptions
date="2022-11-17"
dispatch={[Function]}
homeTimezone="America/Los_Angeles"
importedUpdateItineraryFilter={[Function]}
sort={
Object {
"direction": "ASC",
"type": "BEST",
}
}
time="12:34"
timeFormat="h:mm a"
>
1 change: 1 addition & 0 deletions __tests__/components/date-time-options.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import '../test-utils/mock-window-matchMedia'
import '../test-utils/mock-window-url'
import {
getMockInitialState,
7 changes: 7 additions & 0 deletions __tests__/test-utils/mock-window-matchMedia.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const mockedMediaQuery = jest.fn()
mockedMediaQuery.mockReturnValue({ matches: [] })

Object.defineProperty(window, 'matchMedia', {
value: mockedMediaQuery,
writable: true
})
47 changes: 38 additions & 9 deletions lib/components/form/call-taker/date-time-picker.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
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'
import { OverlayTrigger, Tooltip } from 'react-bootstrap'
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 { updateItineraryFilter } from '../../../actions/narrative'

const { getCurrentDate, OTP_API_DATE_FORMAT, OTP_API_TIME_FORMAT } =
coreUtils.time

@@ -56,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)
@@ -68,8 +72,9 @@ const safeFormat = (date: Date | '', time: string, options: any) => {

type Props = {
date?: string
departArrive?: string
departArrive?: DepartArriveValue
homeTimezone: string
importedUpdateItineraryFilter: (payload: FilterType) => void
onKeyDown: () => void
setQueryParam: ({
date,
@@ -80,6 +85,8 @@ type Props = {
departArrive: string
time: string
}) => void
sort: SortType
syncSortWithDepartArrive?: boolean
time?: string
timeFormat: string
}
@@ -101,12 +108,15 @@ const DateTimeOptions = ({
date: initialDate,
departArrive: initialDepartArrive,
homeTimezone,
importedUpdateItineraryFilter,
onKeyDown,
setQueryParam,
sort,
syncSortWithDepartArrive,
time: initialTime,
timeFormat
}: Props) => {
const [departArrive, setDepartArrive] = useState(
const [departArrive, setDepartArrive] = useState<DepartArriveValue>(
initialDate || initialTime ? 'DEPART' : 'NOW'
)
const [date, setDate] = useState<string | undefined>(initialDate)
@@ -187,6 +197,18 @@ const DateTimeOptions = ({
})
})
}

if (
syncSortWithDepartArrive &&
DepartArriveTypeMap[departArrive] !== sort.type
) {
importedUpdateItineraryFilter({
sort: {
...sort,
type: DepartArriveTypeMap[departArrive]
}
})
}
}, [dateTime, departArrive, homeTimezone, setQueryParam])

// Handler for updating the time and date fields when NOW is selected
@@ -209,8 +231,8 @@ const DateTimeOptions = ({
return (
<>
<select
onBlur={(e) => setDepartArrive(e.target.value)}
onChange={(e) => setDepartArrive(e.target.value)}
onBlur={(e) => setDepartArrive(e.target.value as DepartArriveValue)}
onChange={(e) => setDepartArrive(e.target.value as DepartArriveValue)}
onKeyDown={onKeyDown}
value={departArrive}
>
@@ -282,12 +304,19 @@ const DateTimeOptions = ({
}

// connect to the redux store
const mapStateToProps = (state: any) => {
const { dateTime, homeTimezone } = state.otp.config
const mapStateToProps = (state: AppReduxState) => {
const { dateTime, homeTimezone, itinerary } = state.otp.config
const syncSortWithDepartArrive = itinerary?.syncSortWithDepartArrive
const { sort } = state.otp.filter
return {
homeTimezone,
sort,
syncSortWithDepartArrive,
timeFormat: dateTime?.timeFormat || 'h:mm a'
}
}
const mapDispatchToProps = {
importedUpdateItineraryFilter: 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
@@ -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']
> = {

Unchanged files with check annotations Beta

import { replace, push } from 'connected-react-router'

Check failure on line 1 in lib/actions/auth.js

GitHub Actions / test-build-release

Member 'push' of the import declaration should be sorted alphabetically
import { setPathBeforeSignIn } from '../actions/user'
* @param {Error} err
* @param {AccessTokenRequestOptions} options
*/
export function showAccessTokenError (err, options) {

Check failure on line 11 in lib/actions/auth.js

GitHub Actions / test-build-release

Delete `·`
return function (dispatch, getState) {
// TODO: improve this.
console.error('Failed to retrieve access token: ', err)
* when signing-in fails for some reason.
* @param {Error} err
*/
export function showLoginError (err) {

Check failure on line 23 in lib/actions/auth.js

GitHub Actions / test-build-release

Delete `·`
return function (dispatch, getState) {
// TODO: improve this.
if (err) dispatch(push('/oops'))
* @param {Object} appState The state stored when calling useAuth0().loginWithRedirect
* or when instantiating a component that uses withAuhenticationRequired.
*/
export function processSignIn (appState) {

Check failure on line 36 in lib/actions/auth.js

GitHub Actions / test-build-release

Delete `·`
return function (dispatch, getState) {
if (appState && appState.returnTo) {
// Remove URL parameters that were added by auth0-react
import { createAction } from 'redux-actions'
if (typeof (fetch) === 'undefined') require('isomorphic-fetch')

Check failure on line 2 in lib/actions/zipcar.js

GitHub Actions / test-build-release

Replace `(fetch)` with `fetch`
export const receivedZipcarLocationsError = createAction('ZIPCAR_LOCATIONS_ERROR')

Check failure on line 4 in lib/actions/zipcar.js

GitHub Actions / test-build-release

Replace `'ZIPCAR_LOCATIONS_ERROR'` with `⏎··'ZIPCAR_LOCATIONS_ERROR'⏎`
export const receivedZipcarLocationsResponse = createAction('ZIPCAR_LOCATIONS_RESPONSE')

Check failure on line 5 in lib/actions/zipcar.js

GitHub Actions / test-build-release

Replace `'ZIPCAR_LOCATIONS_RESPONSE'` with `⏎··'ZIPCAR_LOCATIONS_RESPONSE'⏎`
export const requestZipcarLocationsResponse = createAction('ZIPCAR_LOCATIONS_REQUEST')

Check failure on line 6 in lib/actions/zipcar.js

GitHub Actions / test-build-release

Replace `'ZIPCAR_LOCATIONS_REQUEST'` with `⏎··'ZIPCAR_LOCATIONS_REQUEST'⏎`
export function zipcarLocationsQuery (url) {

Check failure on line 8 in lib/actions/zipcar.js

GitHub Actions / test-build-release

Delete `·`
return async function (dispatch, getState) {
dispatch(requestZipcarLocationsResponse())
let json
import { Field, Form, Formik } from 'formik'
import React, {Component} from 'react'

Check failure on line 2 in lib/components/admin/editable-section.js

GitHub Actions / test-build-release

Replace `Component` with `·Component·`
import {
Button,