@@ -37,6 +37,7 @@ import {
37
37
import { isLastStop } from '../util/stop-times'
38
38
39
39
import { addToRecentSearches , rememberPlace } from './user'
40
+ import { countFlexModes } from './api-utils'
40
41
import {
41
42
createQueryAction ,
42
43
fetchingStopTimesForStop ,
@@ -989,6 +990,7 @@ export function routingQuery(searchId = null, updateSearchInReducer) {
989
990
{ }
990
991
991
992
const strictModes = ! ! config ?. itinerary ?. strictItineraryFiltering
993
+ const validModeCombinations = config ?. itinerary ?. validModeCombinations
992
994
993
995
// Filter mode definitions based on active mode keys
994
996
const activeModeButtons = config . modes ?. modeButtons . filter ( ( mb ) =>
@@ -1045,7 +1047,16 @@ export function routingQuery(searchId = null, updateSearchInReducer) {
1045
1047
// Generate combinations if the modes for query are not specified in the query
1046
1048
// FIXME: BICYCLE_RENT does not appear in this list unless TRANSIT is also enabled.
1047
1049
// This is likely due to the fact that BICYCLE_RENT is treated as a transit submode.
1048
- const combinations = modes ? [ baseQuery ] : generateCombinations ( baseQuery )
1050
+ let combinations = modes ? [ baseQuery ] : generateCombinations ( baseQuery )
1051
+
1052
+ // Pre-planConnection API hack: FLEX should always be bundled together.
1053
+ // The real solution is to change how we generate mode selections, but for now
1054
+ // this removes superfluous flex requests.
1055
+ combinations = combinations . filter ( ( c ) => {
1056
+ const flexCount = countFlexModes ( c . modes )
1057
+ // We need either all 3 flex modes or none! Anything in-between is invalid
1058
+ return flexCount === 0 || flexCount === 3
1059
+ } )
1049
1060
1050
1061
if ( combinations . length === 0 ) {
1051
1062
return RoutingQueryCallResult . INVALID_MODE_SELECTION
@@ -1121,6 +1132,22 @@ export function routingQuery(searchId = null, updateSearchInReducer) {
1121
1132
activeModeStrings . includes ( SIMPLIFICATIONS [ leg . mode ] )
1122
1133
)
1123
1134
)
1135
+ // If "acceptableValidModeCombos" is provided, filter out itineraries that do not match our list of valid mode combinations
1136
+ // (e.g. "WALK" + "DRIVE")
1137
+ // TODO: Remove this once we switch to planConnection API
1138
+ if ( validModeCombinations ?. length > 0 ) {
1139
+ filteredItineraries = filteredItineraries . filter ( ( itin ) => {
1140
+ const modeCombo = Array . from (
1141
+ new Set ( itin . legs . map ( ( leg ) => SIMPLIFICATIONS [ leg . mode ] ) )
1142
+ )
1143
+ return validModeCombinations . find (
1144
+ ( vc ) =>
1145
+ modeCombo . length === vc . length &&
1146
+ vc . every ( ( m ) => modeCombo . includes ( m ) )
1147
+ )
1148
+ } )
1149
+ }
1150
+
1124
1151
// ... Otherwise return all itineraries.
1125
1152
}
1126
1153
0 commit comments