Skip to content

Commit 9596d3d

Browse files
committed
Merge branch 'nearby-view-stations-basedev' of github.com:opentripplanner/otp-react-redux into nearby-view-stations-basedev
2 parents c68cf03 + 7c5619c commit 9596d3d

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-2
lines changed

Diff for: example-config.yml

+12
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,18 @@ routingTypes:
348348

349349
# Itinerary options
350350
itinerary:
351+
# Provides an array of valid mode combinations that returned itineraries will be filtered against
352+
# If left blank, all itineraries deemed valid by OTP will be returned
353+
validModeCombinations: [
354+
['WALK'],
355+
['WALK', 'PERSONAL'],
356+
['WALK', 'TRANSIT', 'SHARED'],
357+
['WALK', 'SHARED'],
358+
['WALK', 'TRANSIT'],
359+
['WALK', 'TRANSIT', 'PERSONAL'],
360+
['WALK', 'TRANSIT', 'CAR'],
361+
['CAR']
362+
]
351363
# Show fares for each transit leg (false if omitted).
352364
# (Requires using LineItinerary.)
353365
showRouteFares: false

Diff for: lib/actions/api-utils.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { TransportMode } from '@opentripplanner/types'
2+
3+
export const countFlexModes = (modes: TransportMode[]): number =>
4+
modes.filter((m) => m.mode === 'FLEX').length

Diff for: lib/actions/apiV2.js

+28-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {
3737
import { isLastStop } from '../util/stop-times'
3838

3939
import { addToRecentSearches, rememberPlace } from './user'
40+
import { countFlexModes } from './api-utils'
4041
import {
4142
createQueryAction,
4243
fetchingStopTimesForStop,
@@ -989,6 +990,7 @@ export function routingQuery(searchId = null, updateSearchInReducer) {
989990
{}
990991

991992
const strictModes = !!config?.itinerary?.strictItineraryFiltering
993+
const validModeCombinations = config?.itinerary?.validModeCombinations
992994

993995
// Filter mode definitions based on active mode keys
994996
const activeModeButtons = config.modes?.modeButtons.filter((mb) =>
@@ -1045,7 +1047,16 @@ export function routingQuery(searchId = null, updateSearchInReducer) {
10451047
// Generate combinations if the modes for query are not specified in the query
10461048
// FIXME: BICYCLE_RENT does not appear in this list unless TRANSIT is also enabled.
10471049
// 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+
})
10491060

10501061
if (combinations.length === 0) {
10511062
return RoutingQueryCallResult.INVALID_MODE_SELECTION
@@ -1121,6 +1132,22 @@ export function routingQuery(searchId = null, updateSearchInReducer) {
11211132
activeModeStrings.includes(SIMPLIFICATIONS[leg.mode])
11221133
)
11231134
)
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+
11241151
// ... Otherwise return all itineraries.
11251152
}
11261153

Diff for: lib/components/narrative/line-itin/realtime-time-column.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ function RealtimeTimeColumn({ isDestination, leg }: Props): ReactElement {
3333
}
3434

3535
const timeMillis = isDestination ? leg.endTime : leg.startTime
36-
const isRealtimeTransitLeg = isTransitLeg(leg) && leg.realTime
36+
const isRealtimeTransitLeg =
37+
!isDestination && isTransitLeg(leg) && leg.realTime
3738

3839
// For non-transit legs show only the scheduled time.
3940
if (!isTransitLeg(leg)) {

0 commit comments

Comments
 (0)