From f3d2f6a1055bcd085ba49654def77da67145e8b3 Mon Sep 17 00:00:00 2001 From: amy-corson-ibigroup <115499534+amy-corson-ibigroup@users.noreply.github.com> Date: Fri, 6 Oct 2023 14:48:24 -0500 Subject: [PATCH 1/4] Add configurable strict mode to itinerary filter --- lib/actions/apiV2.js | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/actions/apiV2.js b/lib/actions/apiV2.js index ae64d539c..dd77fbfc8 100644 --- a/lib/actions/apiV2.js +++ b/lib/actions/apiV2.js @@ -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 @@ -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) @@ -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. From 15b71fc61007ac7ecc59175566d53e96f758d3cb Mon Sep 17 00:00:00 2001 From: amy-corson-ibigroup <115499534+amy-corson-ibigroup@users.noreply.github.com> Date: Mon, 9 Oct 2023 09:22:37 -0500 Subject: [PATCH 2/4] Add comments and example config variable --- example-config.yml | 3 +++ lib/actions/apiV2.js | 1 + 2 files changed, 4 insertions(+) diff --git a/example-config.yml b/example-config.yml index cc270ada0..2bae9c943 100644 --- a/example-config.yml +++ b/example-config.yml @@ -310,6 +310,9 @@ itinerary: # Whether the plan first/previous/next/last buttons should be shown along with # plan trip itineraries. showPlanFirstLastButtons: false + # Filters out trips returned by OTP by default, unless specifically requested. + # e.g. filters out walk-only itineraries if user has not explicitly asked for them. + strictItineraryFiltering: false # Whether to render route names and colors in the blocks inside # the batch ui rows renderRouteNamesInBlocks: true diff --git a/lib/actions/apiV2.js b/lib/actions/apiV2.js index dd77fbfc8..9f7b60b75 100644 --- a/lib/actions/apiV2.js +++ b/lib/actions/apiV2.js @@ -939,6 +939,7 @@ export function routingQuery(searchId = null, updateSearchInReducer) { filteredItineraries = itineraries } + // Filter itineraries to collapse short names and hide unnecessary errors. const withCollapsedShortNames = filteredItineraries.map( (itin) => ({ ...itin, From ddf8156a43d8feefbccb4b28ef90f6dae3a56b09 Mon Sep 17 00:00:00 2001 From: amy-corson-ibigroup <115499534+amy-corson-ibigroup@users.noreply.github.com> Date: Mon, 9 Oct 2023 15:18:27 -0500 Subject: [PATCH 3/4] Add additional comments for clarity --- lib/actions/apiV2.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/actions/apiV2.js b/lib/actions/apiV2.js index 9f7b60b75..57c6d141d 100644 --- a/lib/actions/apiV2.js +++ b/lib/actions/apiV2.js @@ -924,17 +924,21 @@ export function routingQuery(searchId = null, updateSearchInReducer) { { rewritePayload: (response, dispatch, getState) => { const itineraries = response.data?.plan?.itineraries + + // Convert user-selected transit modes from mode selector into modes recognized by OTP. const activeModeStrings = activeModes.map( (am) => SIMPLIFICATIONS[am.mode] ) - let filteredItineraries + let filteredItineraries + // If "strictItineraryFiltering" is enabled, only return itineraries that contain at least one explicitly requested mode... if (strictModes) { filteredItineraries = itineraries.filter((itin) => itin.legs.some((leg) => activeModeStrings.includes(SIMPLIFICATIONS[leg.mode]) ) ) + // ... Otherwise return all itineraries. } else { filteredItineraries = itineraries } From 8a26d355c975049c9c15ce4c20f51ffabb6b2551 Mon Sep 17 00:00:00 2001 From: amy-corson-ibigroup <115499534+amy-corson-ibigroup@users.noreply.github.com> Date: Wed, 11 Oct 2023 17:42:00 -0500 Subject: [PATCH 4/4] refactor: remove else block from strict filtering --- lib/actions/apiV2.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/actions/apiV2.js b/lib/actions/apiV2.js index 57c6d141d..032032b2a 100644 --- a/lib/actions/apiV2.js +++ b/lib/actions/apiV2.js @@ -930,7 +930,7 @@ export function routingQuery(searchId = null, updateSearchInReducer) { (am) => SIMPLIFICATIONS[am.mode] ) - let filteredItineraries + let filteredItineraries = itineraries // If "strictItineraryFiltering" is enabled, only return itineraries that contain at least one explicitly requested mode... if (strictModes) { filteredItineraries = itineraries.filter((itin) => @@ -939,8 +939,6 @@ export function routingQuery(searchId = null, updateSearchInReducer) { ) ) // ... Otherwise return all itineraries. - } else { - filteredItineraries = itineraries } // Filter itineraries to collapse short names and hide unnecessary errors.