diff --git a/example-config.yml b/example-config.yml index 79a242954..d62b241ae 100644 --- a/example-config.yml +++ b/example-config.yml @@ -268,7 +268,11 @@ modes: iconName: wheelchair type: CHECKBOX # Possible options: CHECKBOX, SUBMODE, SLIDER, DROPDOWN transitModes: - - mode: BUS + # Mode can be a string or an array of strings. + - mode: ["TROLLEYBUS", "BUS"] + # When mode is an array an overrideMode must be provided. + # This specifies the displayed mode used for icon and URL param. + overrideMode: BUS label: Bus # A mode color can be added, used throughout the application, # most notably in the enhanced stop viewer bubble diff --git a/lib/actions/form.js b/lib/actions/form.js index bfdc65fe7..61ef9b87f 100644 --- a/lib/actions/form.js +++ b/lib/actions/form.js @@ -43,7 +43,7 @@ export function resetForm(full = false) { const options = getTripOptionsFromQuery(defaultQuery) // Default mode is currently WALK,TRANSIT. We need to update this value // here to match the list of modes, otherwise the form will break. - options.mode = ['WALK', ...transitModes.map((m) => m.mode)].join(',') + options.mode = ['WALK', ...transitModes.flatMap((m) => m.mode)].join(',') dispatch(settingQueryParam(options)) } if (full) { diff --git a/lib/reducers/create-otp-reducer.js b/lib/reducers/create-otp-reducer.js index fa0f082ef..c4b3a7811 100644 --- a/lib/reducers/create-otp-reducer.js +++ b/lib/reducers/create-otp-reducer.js @@ -135,10 +135,18 @@ export function getInitialState(userDefinedConfig) { const transitModeSettings = config?.modes?.transitModes.map((transitMode) => { const { mode, overrideMode } = transitMode + if (Array.isArray(mode) && !overrideMode) { + console.warn( + `Mode ${mode} is an array, but no overrideMode is specified.` + ) + } const displayedMode = overrideMode || mode + const addTransportModes = Array.isArray(mode) + ? mode.map((m) => ({ mode: m })) + : { mode } return { // This is the mode that gets added to the actual query to OTP - addTransportMode: { mode }, + addTransportMode: addTransportModes, applicableMode: 'TRANSIT', default: true, iconName: displayedMode.toLowerCase(), diff --git a/lib/util/config-types.ts b/lib/util/config-types.ts index cd29d83f7..481a62582 100644 --- a/lib/util/config-types.ts +++ b/lib/util/config-types.ts @@ -323,7 +323,7 @@ export interface GeocoderConfig extends GeocoderConfigOtpUI { export interface TransitModeConfig { color?: string label?: string - mode: string + mode: string | string[] showWheelchairSetting?: boolean }