Skip to content

Commit

Permalink
Merge pull request #617 from opentripplanner/june-call-taker-fixes
Browse files Browse the repository at this point in the history
CallTaker Regression Fixes
  • Loading branch information
miles-grant-ibigroup authored Jun 8, 2022
2 parents 9cf37f0 + 309bcc4 commit 2149740
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 23 deletions.
62 changes: 40 additions & 22 deletions lib/actions/plan.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
import {OTP_API_DATE_FORMAT, OTP_API_TIME_FORMAT} from '@opentripplanner/core-utils/lib/time'
import {getTimeZoneOffset} from '@opentripplanner/core-utils/lib/itinerary'
import { getTimeZoneOffset } from '@opentripplanner/core-utils/lib/itinerary'
import {
OTP_API_DATE_FORMAT,
OTP_API_TIME_FORMAT
} from '@opentripplanner/core-utils/lib/time'
import moment from 'moment'

import {getFirstStopId} from '../util/itinerary'
import {getActiveItinerary} from '../util/state'
import { getActiveItinerary } from '../util/state'
import { getFirstStopId } from '../util/itinerary'

import {routingQuery} from './api'
import {setQueryParam} from './form'
import { routingQuery } from './api'
import { setQueryParam } from './form'

const SERVICE_BREAK = '03:00'
const NINETY_SECONDS = 90000

function updateParamsAndPlan (params) {
function updateParamsAndPlan(params) {
return function (dispatch, getState) {
dispatch(setQueryParam(params))
dispatch(routingQuery())
}
}

function offsetTime (itinerary, unixTime) {
function offsetTime(itinerary, unixTime) {
let offset = 0
if (itinerary) offset = getTimeZoneOffset(itinerary)
return moment(unixTime + offset)
Expand All @@ -28,30 +31,32 @@ function offsetTime (itinerary, unixTime) {
* Effectively checks whether #planFirst has already been clicked, i.e., the
* query is planning a depart at the service break time.
*/
function isPlanningFirst (query) {
const {departArrive, time} = query
function isPlanningFirst(query) {
const { departArrive, time } = query
return departArrive === 'DEPART' && time === SERVICE_BREAK
}

/**
* Plan the first trip of the day, or if the first trip has already been planned,
* plan the first trip of the previous day.
*/
export function planFirst () {
export function planFirst() {
return function (dispatch, getState) {
const state = getState()
const itinerary = getActiveItinerary(state)
const {currentQuery} = state.otp
const { currentQuery } = state.otp
const date = moment(currentQuery.date)
// If already planning for the "first" trip, subtract a day to mirror the
// behavior of planLast.
if (isPlanningFirst(currentQuery)) date.subtract('days', 1)
const params = {
date: date.format(OTP_API_DATE_FORMAT),
departArrive: 'DEPART',
startTransitStopId: getFirstStopId(itinerary),
time: SERVICE_BREAK
}
if (!state.otp?.config?.api?.v2) {
params.startTransitStopId = getFirstStopId(itinerary)
}
dispatch(updateParamsAndPlan(params))
}
}
Expand All @@ -60,16 +65,18 @@ export function planFirst () {
* Plan the previous trip, setting the arrive by time to the current itinerary's
* end time (minus a small amount).
*/
export function planPrevious () {
export function planPrevious() {
return function (dispatch, getState) {
const itinerary = getActiveItinerary(getState())
const newEndTime = offsetTime(itinerary, itinerary.endTime - NINETY_SECONDS)
const params = {
date: newEndTime.format(OTP_API_DATE_FORMAT),
departArrive: 'ARRIVE',
startTransitStopId: getFirstStopId(itinerary),
time: newEndTime.format(OTP_API_TIME_FORMAT)
}
if (!getState().otp?.config?.api?.v2) {
params.startTransitStopId = getFirstStopId(itinerary)
}
dispatch(updateParamsAndPlan(params))
}
}
Expand All @@ -78,16 +85,22 @@ export function planPrevious () {
* Plan the next trip, setting the depart at time to the current itinerary's
* start time (plus a small amount).
*/
export function planNext () {
export function planNext() {
return function (dispatch, getState) {
const itinerary = getActiveItinerary(getState())
const newStartTime = offsetTime(itinerary, itinerary.startTime + NINETY_SECONDS)
const newStartTime = offsetTime(
itinerary,
itinerary.startTime + NINETY_SECONDS
)
const params = {
date: newStartTime.format(OTP_API_DATE_FORMAT),
departArrive: 'DEPART',
startTransitStopId: getFirstStopId(itinerary),
time: newStartTime.format(OTP_API_TIME_FORMAT)
}
if (!getState().otp?.config?.api?.v2) {
params.startTransitStopId = getFirstStopId(itinerary)
}

dispatch(updateParamsAndPlan(params))
}
}
Expand All @@ -96,17 +109,22 @@ export function planNext () {
* Plan the last trip of the day, or if the last trip has already been planned,
* plan the last trip of the next day.
*/
export function planLast () {
export function planLast() {
return function (dispatch, getState) {
const state = getState()
const itinerary = getActiveItinerary(state)
const {currentQuery} = state.otp
const { currentQuery } = state.otp
const params = {
date: moment(currentQuery.date).add('days', 1).format(OTP_API_DATE_FORMAT),
date: moment(currentQuery.date)
.add('days', 1)
.format(OTP_API_DATE_FORMAT),
departArrive: 'ARRIVE',
startTransitStopId: getFirstStopId(itinerary),
time: SERVICE_BREAK
}
if (!state.otp?.config?.api?.v2) {
params.startTransitStopId = getFirstStopId(itinerary)
}

dispatch(updateParamsAndPlan(params))
}
}
2 changes: 1 addition & 1 deletion lib/components/app/call-taker-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class CallTakerPanel extends Component {
locationType="to"
onLocationCleared={this._removePlace}
// FIXME: function def
onLocationSelected={(result) => this._addPlace(result, i)}
onLocationSelected={(_, result) => this._addPlace(result, i)}
showClearButton={!mobile}
/>
)
Expand Down

0 comments on commit 2149740

Please sign in to comment.