Skip to content

Commit 308a3cc

Browse files
Creates a set of valid combos and introduces strictValidCombos config item
1 parent 2702a51 commit 308a3cc

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

Diff for: example-config.yml

+3
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,9 @@ itinerary:
363363
# Filters out trips returned by OTP by default, unless specifically requested.
364364
# e.g. filters out walk-only itineraries if user has not explicitly asked for them.
365365
strictItineraryFiltering: false
366+
# Whether to filter out itineraries that do not match our list of valid mode combinations
367+
# (e.g. "WALK" + "DRIVE")
368+
strictValidCombos: false
366369
# Whether to render route names and colors in the blocks inside
367370
# the batch ui rows
368371
renderRouteNamesInBlocks: true

Diff for: lib/actions/apiV2.js

+28
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,17 @@ const { randId } = coreUtils.storage
7373

7474
const LIGHT_GRAY = '666666'
7575

76+
const VALID_COMBOS = [
77+
['WALK'],
78+
['WALK', 'PERSONAL'],
79+
['WALK', 'TRANSIT', 'SHARED'],
80+
['WALK', 'SHARED'],
81+
['WALK', 'TRANSIT'],
82+
['WALK', 'TRANSIT', 'PERSONAL'],
83+
['WALK', 'TRANSIT', 'CAR'],
84+
['CAR']
85+
]
86+
7687
function formatRecentPlace(place) {
7788
return convertToPlace({
7889
...place,
@@ -982,6 +993,7 @@ export function routingQuery(searchId = null, updateSearchInReducer) {
982993
{}
983994

984995
const strictModes = !!config?.itinerary?.strictItineraryFiltering
996+
const strictValidCombos = !!config?.itinerary?.strictValidCombos
985997

986998
// Filter mode definitions based on active mode keys
987999
const activeModeButtons = config.modes?.modeButtons.filter((mb) =>
@@ -1114,6 +1126,22 @@ export function routingQuery(searchId = null, updateSearchInReducer) {
11141126
activeModeStrings.includes(SIMPLIFICATIONS[leg.mode])
11151127
)
11161128
)
1129+
// If "strictValidCombos" is enabled, filter out itineraries that do not match our list of valid mode combinations
1130+
// (e.g. "WALK" + "DRIVE")
1131+
// TODO: Remove this and VALID_COMBOS once we switch to planConnection API
1132+
if (strictValidCombos) {
1133+
filteredItineraries = filteredItineraries.filter((itin) => {
1134+
const modeCombo = Array.from(
1135+
new Set(itin.legs.map((leg) => SIMPLIFICATIONS[leg.mode]))
1136+
)
1137+
return !!VALID_COMBOS.find(
1138+
(vc) =>
1139+
modeCombo.every((m) => vc.includes(m)) &&
1140+
vc.every((m) => modeCombo.includes(m))
1141+
)
1142+
})
1143+
}
1144+
11171145
// ... Otherwise return all itineraries.
11181146
}
11191147

0 commit comments

Comments
 (0)