Skip to content

Commit 281bbe3

Browse files
Merge branch 'dev' into fix-recent-trips-actions
2 parents 826d860 + 2aa9558 commit 281bbe3

File tree

7 files changed

+49
-5
lines changed

7 files changed

+49
-5
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,
@@ -982,6 +983,7 @@ export function routingQuery(searchId = null, updateSearchInReducer) {
982983
{}
983984

984985
const strictModes = !!config?.itinerary?.strictItineraryFiltering
986+
const validModeCombinations = config?.itinerary?.validModeCombinations
985987

986988
// Filter mode definitions based on active mode keys
987989
const activeModeButtons = config.modes?.modeButtons.filter((mb) =>
@@ -1038,7 +1040,16 @@ export function routingQuery(searchId = null, updateSearchInReducer) {
10381040
// Generate combinations if the modes for query are not specified in the query
10391041
// FIXME: BICYCLE_RENT does not appear in this list unless TRANSIT is also enabled.
10401042
// This is likely due to the fact that BICYCLE_RENT is treated as a transit submode.
1041-
const combinations = modes ? [baseQuery] : generateCombinations(baseQuery)
1043+
let combinations = modes ? [baseQuery] : generateCombinations(baseQuery)
1044+
1045+
// Pre-planConnection API hack: FLEX should always be bundled together.
1046+
// The real solution is to change how we generate mode selections, but for now
1047+
// this removes superfluous flex requests.
1048+
combinations = combinations.filter((c) => {
1049+
const flexCount = countFlexModes(c.modes)
1050+
// We need either all 3 flex modes or none! Anything in-between is invalid
1051+
return flexCount === 0 || flexCount === 3
1052+
})
10421053

10431054
if (combinations.length === 0) {
10441055
return RoutingQueryCallResult.INVALID_MODE_SELECTION
@@ -1114,6 +1125,22 @@ export function routingQuery(searchId = null, updateSearchInReducer) {
11141125
activeModeStrings.includes(SIMPLIFICATIONS[leg.mode])
11151126
)
11161127
)
1128+
// If "acceptableValidModeCombos" is provided, filter out itineraries that do not match our list of valid mode combinations
1129+
// (e.g. "WALK" + "DRIVE")
1130+
// TODO: Remove this once we switch to planConnection API
1131+
if (validModeCombinations?.length > 0) {
1132+
filteredItineraries = filteredItineraries.filter((itin) => {
1133+
const modeCombo = Array.from(
1134+
new Set(itin.legs.map((leg) => SIMPLIFICATIONS[leg.mode]))
1135+
)
1136+
return validModeCombinations.find(
1137+
(vc) =>
1138+
modeCombo.length === vc.length &&
1139+
vc.every((m) => modeCombo.includes(m))
1140+
)
1141+
})
1142+
}
1143+
11171144
// ... Otherwise return all itineraries.
11181145
}
11191146

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)) {

Diff for: lib/components/util/company-icon-internal.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const CompanyIcon = ({
1212
fallbackContent = null,
1313
...otherProps
1414
}: Props): ReactElement | null => {
15-
const CompanyIcon = getCompanyIcon ? getCompanyIcon(company) : null
15+
const CompanyIcon = getCompanyIcon && company ? getCompanyIcon(company) : null
1616
return CompanyIcon ? (
1717
<Suspense fallback={<span>{company}</span>}>
1818
<CompanyIcon {...otherProps} />

Diff for: lib/components/viewers/nearby/rental-station.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const RentalStation = ({ companies, fromToSlot, place }: Props) => {
2525

2626
const stationIcon = (
2727
<CompanyIcon
28-
company={company}
28+
company={company || ''}
2929
fallbackContent={<Bicycle />}
3030
height={22}
3131
style={{ marginRight: '5px' }}

Diff for: lib/components/viewers/nearby/vehicle-rent.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ const Vehicle = ({
9797
<IconWithText
9898
icon={
9999
<CompanyIcon
100-
company={vehicle.network}
100+
company={vehicle.network || ''}
101101
fallbackContent={getVehicleIcon(formFactor)}
102102
height={22}
103103
style={{ marginRight: '5px' }}

0 commit comments

Comments
 (0)