diff --git a/app/component/WithSearchContext.js b/app/component/WithSearchContext.js
index 2f4521d874..7ef2c7f8f2 100644
--- a/app/component/WithSearchContext.js
+++ b/app/component/WithSearchContext.js
@@ -6,6 +6,7 @@ import suggestionToLocation from '@digitransit-search-util/digitransit-search-ut
import connectToStores from 'fluxible-addons-react/connectToStores';
import { configShape, locationStateShape } from '../util/shapes';
import { addAnalyticsEvent } from '../util/analyticsUtils';
+import { useCitybikes } from '../util/modeUtils';
import {
PREFIX_ITINERARY_SUMMARY,
PREFIX_STOPS,
@@ -25,10 +26,33 @@ const PATH_OPTS = {
itinerarySummaryPrefix: PREFIX_ITINERARY_SUMMARY,
};
-export default function withSearchContext(
- WrappedComponent,
- embeddedSearch = false,
-) {
+export function getLocationSearchTargets(config, isMobile) {
+ let locationSearchTargets = ['Locations', 'CurrentPosition'];
+
+ if (config.locationSearchTargetsFromOTP) {
+ // configurable setup
+ locationSearchTargets = [
+ ...locationSearchTargets,
+ ...config.locationSearchTargetsFromOTP,
+ ];
+ } else {
+ // default setup
+ locationSearchTargets.push('Stations');
+ locationSearchTargets.push('Stops');
+ if (useCitybikes(config.vehicleRental?.networks, config)) {
+ locationSearchTargets.push('VehicleRentalStations');
+ }
+ if (config.includeParkAndRideSuggestions) {
+ locationSearchTargets.push('ParkingAreas');
+ }
+ }
+ if (isMobile) {
+ locationSearchTargets.push('MapPosition');
+ }
+ return locationSearchTargets;
+}
+
+export function withSearchContext(WrappedComponent, embeddedSearch = false) {
class ComponentWithSearchContext extends React.Component {
static contextTypes = {
config: configShape.isRequired,
diff --git a/app/component/itinerary/OriginDestinationBar.js b/app/component/itinerary/OriginDestinationBar.js
index 0af108f125..4995bec2ff 100644
--- a/app/component/itinerary/OriginDestinationBar.js
+++ b/app/component/itinerary/OriginDestinationBar.js
@@ -11,7 +11,10 @@ import {
locationShape,
} from '../../util/shapes';
import { addAnalyticsEvent } from '../../util/analyticsUtils';
-import withSearchContext from '../WithSearchContext';
+import {
+ withSearchContext,
+ getLocationSearchTargets,
+} from '../WithSearchContext';
import {
setIntermediatePlaces,
updateItinerarySearch,
@@ -21,7 +24,6 @@ import { getIntermediatePlaces, locationToOTP } from '../../util/otpStrings';
import { setViaPoints } from '../../action/ViaPointActions';
import { LightenDarkenColor } from '../../util/colorUtils';
import { getRefPoint } from '../../util/apiUtils';
-import { useCitybikes } from '../../util/modeUtils';
const DTAutosuggestPanelWithSearchContext =
withSearchContext(DTAutosuggestPanel);
@@ -129,11 +131,6 @@ class OriginDestinationBar extends React.Component {
props.destination,
props.locationState,
);
- const desktopTargets = ['Locations', 'CurrentPosition', 'Stops'];
- if (useCitybikes(config.vehicleRental?.networks, config)) {
- desktopTargets.push('VehicleRentalStations');
- }
- const mobileTargets = [...desktopTargets, 'MapPosition'];
const filter = config.stopSearchFilter
? results => results.filter(config.stopSearchFilter)
: undefined;
@@ -162,7 +159,7 @@ class OriginDestinationBar extends React.Component {
'Datasource',
props.showFavourites ? 'Favourite' : '',
]}
- targets={props.isMobile ? mobileTargets : desktopTargets}
+ targets={getLocationSearchTargets(config, false)}
lang={props.language}
disableAutoFocus={props.isMobile}
isMobile={props.isMobile}
diff --git a/app/component/nearyou/NearYouPage.js b/app/component/nearyou/NearYouPage.js
index c2aa0f97ac..a80a836104 100644
--- a/app/component/nearyou/NearYouPage.js
+++ b/app/component/nearyou/NearYouPage.js
@@ -29,7 +29,10 @@ import {
getReadMessageIds,
setReadMessageIds,
} from '../../store/localStorage';
-import withSearchContext from '../WithSearchContext';
+import {
+ withSearchContext,
+ getLocationSearchTargets,
+} from '../WithSearchContext';
import { PREFIX_NEARYOU } from '../../util/path';
import StopsNearYouContainer from './StopsNearYouContainer';
import SwipeableTabs from '../SwipeableTabs';
@@ -387,6 +390,7 @@ class NearYouPage extends React.Component {
const renderRefetchButton = centerOfMapChanged && !noFavorites;
const nearByStopModes = this.modes;
const index = nearByStopModes.indexOf(mode);
+ const { config } = this.context;
const tabs = nearByStopModes.map(nearByStopMode => {
const renderSearch =
nearByStopMode !== 'FERRY' && nearByStopMode !== 'FAVORITE';
@@ -459,7 +463,7 @@ class NearYouPage extends React.Component {
variables={this.getQueryVariables(nearByStopMode)}
environment={this.props.relayEnvironment}
render={({ props }) => {
- const { vehicleRental } = this.context.config;
+ const { vehicleRental } = config;
// Use buy instructions if available
const cityBikeBuyUrl = vehicleRental.buyUrl;
const buyInstructions = cityBikeBuyUrl
@@ -471,20 +475,18 @@ class NearYouPage extends React.Component {
if (Object.keys(vehicleRental.networks).length === 1) {
cityBikeNetworkUrl = getRentalNetworkConfig(
getRentalNetworkId(Object.keys(vehicleRental.networks)),
- this.context.config,
+ config,
).url;
}
const prioritizedStops =
- this.context.config.prioritizedStopsNearYou[
- nearByStopMode.toLowerCase()
- ];
+ config.prioritizedStopsNearYou[nearByStopMode.toLowerCase()];
return (
{renderDisruptionBanner && (
)}
{renderSearch && (
@@ -517,7 +519,7 @@ class NearYouPage extends React.Component {
role="button"
>
@@ -828,18 +830,7 @@ class NearYouPage extends React.Component {
modeSet: this.context.config.iconModeSet,
getAutoSuggestIcons: this.context.config.getAutoSuggestIcons,
};
- const targets = ['Locations', 'Stations', 'Stops'];
- if (
- useCitybikes(
- this.context.config.vehicleRental?.networks,
- this.context.config,
- )
- ) {
- targets.push('VehicleRentalStations');
- }
- if (this.context.config.includeParkAndRideSuggestions && onMap) {
- targets.push('ParkingAreas');
- }
+ const targets = getLocationSearchTargets(this.context.config, false);
return (