Skip to content

Commit

Permalink
Merge pull request #1218 from opentripplanner/fix-no-itins-error
Browse files Browse the repository at this point in the history
fix adding NO_TRANSIT_CONNECTION error
  • Loading branch information
amy-corson-ibigroup authored Jun 5, 2024
2 parents 17c7b71 + a28d7f7 commit 934b47f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
21 changes: 6 additions & 15 deletions lib/actions/apiV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -1109,17 +1109,16 @@ export function routingQuery(searchId = null, updateSearchInReducer) {
returned even if trips were returned, since it is on a mode-by-mode basis.
there is a chance for user confusion!
By checking if itineraries exist, we can hide this error when it is
not applicable. */
We'll reintroduce this error later once all the results are compiled */

response.data.plan.routingErrors =
response.data?.plan?.routingErrors.filter(
(re) => re?.code !== 'NO_TRANSIT_CONNECTION'
)
if (
getActiveItineraries(getState())?.length > 0 &&
response?.data?.plan
) {
response.data.plan.routingErrors =
response.data?.plan?.routingErrors.filter(
(re) => re?.code !== 'NO_TRANSIT_CONNECTION'
)

// Add accessibility error, if it is turned on
const state = getState()
const { displayA11yError } = state.otp.config?.itinerary
Expand All @@ -1139,14 +1138,6 @@ export function routingQuery(searchId = null, updateSearchInReducer) {
}
}

// If there are no itineraries, generate an error
// so we're not left with an empty results container.
if (withCollapsedShortNames.length === 0) {
response.data.plan.routingErrors.push({
code: 'NO_TRANSIT_CONNECTION'
})
}

return {
index,
response: {
Expand Down
11 changes: 9 additions & 2 deletions lib/components/narrative/narrative-itineraries.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ import Skeleton, { SkeletonTheme } from 'react-loading-skeleton'

import * as uiActions from '../../actions/ui'
import { ComponentContext } from '../../util/contexts'
import { firstTransitLegIsRealtime } from '../../util/viewer'
import {
createNoItinerariesErr,
getActiveItineraries,
getActiveSearch,
getRealtimeEffects,
getResponsesWithErrors,
getVisibleItineraryIndex,
sortItinerariesInPlaceIfNeeded
} from '../../util/state'
import { firstTransitLegIsRealtime } from '../../util/viewer'
import {
getFirstLegStartTime,
itinerariesAreEqual,
Expand Down Expand Up @@ -604,6 +605,12 @@ const mapStateToProps = (state) => {
// Sort the merged (displayed) itineraries if needed
sortItinerariesInPlaceIfNeeded(mergedItineraries, state)

const errorsWithNoItineraries = createNoItinerariesErr(
state,
activeSearch?.response?.reduce(reduceErrorsFromResponse, {}),
pending
)

return {
// swap out realtime itineraries with non-realtime depending on boolean
activeItinerary,
Expand All @@ -616,7 +623,7 @@ const mapStateToProps = (state) => {
errorMessages,
errors: getResponsesWithErrors(state),
// TODO: Destroy otp1 errors and rename this
errorsOtp2: activeSearch?.response?.reduce(reduceErrorsFromResponse, {}),
errorsOtp2: errorsWithNoItineraries,
groupItineraries,
groupTransitModes,
itineraries: allItineraries,
Expand Down
12 changes: 12 additions & 0 deletions lib/util/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@ export const getActiveItineraries = createSelector(
}
)

/**
* If there are no itineraries, generate an error
* so we're not left with an empty results container.
*/
export const createNoItinerariesErr = (state, errors, pending) => {
const itineraries = getActiveItineraries(state)
if (errors && itineraries.length === 0 && !pending) {
errors.NO_TRANSIT_CONNECTION = new Set()
}
return errors
}

/**
* Helper method to sort itineraries.
* As the name indicates, it will mutate the order in the specified array.
Expand Down

0 comments on commit 934b47f

Please sign in to comment.