Skip to content

Commit

Permalink
Add configurable strict mode to itinerary filter
Browse files Browse the repository at this point in the history
  • Loading branch information
amy-corson-ibigroup committed Oct 6, 2023
1 parent 0537e10 commit f3d2f6a
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions lib/actions/apiV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ import { RoutingQueryCallResult } from './api-constants'
import { setItineraryView } from './ui'
import { zoomToPlace } from './map'

const { generateCombinations, generateOtp2Query } = coreUtils.queryGen
const { generateCombinations, generateOtp2Query, SIMPLIFICATIONS } =
coreUtils.queryGen
const { getTripOptionsFromQuery, getUrlParams } = coreUtils.query
const { convertGraphQLResponseToLegacy } = coreUtils.itinerary
const { randId } = coreUtils.storage
Expand Down Expand Up @@ -824,6 +825,8 @@ export function routingQuery(searchId = null, updateSearchInReducer) {
config?.modes?.initialState?.enabledModeButtons ||
{}

const strictModes = config?.itinerary?.strictItineraryFiltering

// Filter mode definitions based on active mode keys
const activeModeButtons = config.modes?.modeButtons.filter((mb) =>
activeModeKeys.includes(mb.key)
Expand Down Expand Up @@ -920,11 +923,28 @@ export function routingQuery(searchId = null, updateSearchInReducer) {
routingError,
{
rewritePayload: (response, dispatch, getState) => {
const withCollapsedShortNames =
response.data?.plan?.itineraries?.map((itin) => ({
const itineraries = response.data?.plan?.itineraries
const activeModeStrings = activeModes.map(
(am) => SIMPLIFICATIONS[am.mode]
)
let filteredItineraries

if (strictModes) {
filteredItineraries = itineraries.filter((itin) =>
itin.legs.some((leg) =>
activeModeStrings.includes(SIMPLIFICATIONS[leg.mode])
)
)
} else {
filteredItineraries = itineraries
}

const withCollapsedShortNames = filteredItineraries.map(
(itin) => ({
...itin,
legs: itin.legs?.map(convertGraphQLResponseToLegacy)
}))
})
)

/* It is possible for a NO_TRANSIT_CONNECTION error to be
returned even if trips were returned, since it is on a mode-by-mode basis.
Expand Down

0 comments on commit f3d2f6a

Please sign in to comment.