Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(map-layers): stop layers shown even if disabled #884

Merged
merged 1 commit into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions app/component/ItineraryPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,9 @@ class ItineraryPage extends React.Component {
]?.legs.some(leg => leg.from?.vehicleRentalStation);

const mapLayerOptions = itineraryContainsDepartureFromVehicleRentalStation
? addBikeStationMapForRentalVehicleItineraries(itineraries)
? addBikeStationMapForRentalVehicleItineraries(
this.context.config.enableLockedMapLayers,
)
: this.props.mapLayerOptions;

const objectsToHide = getRentalStationsToHideOnMap(
Expand Down Expand Up @@ -1618,26 +1620,32 @@ class ItineraryPage extends React.Component {
}
}

const ItineraryPageWithBreakpoint = withBreakpoint(props => (
const ItineraryPageWithBreakpoint = withBreakpoint((props, context) => (
<ReactRelayContext.Consumer>
{({ environment }) => (
<ItineraryPage {...props} relayEnvironment={environment} />
<ItineraryPage {...props} {...context} relayEnvironment={environment} />
)}
</ReactRelayContext.Consumer>
));

const ItineraryPageWithStores = connectToStores(
ItineraryPageWithBreakpoint,
['MapLayerStore'],
({ getStore }) => ({
({ config, getStore }) => ({
mapLayers: getStore('MapLayerStore').getMapLayers({
notThese: ['stop', 'citybike', 'vehicles'],
}),
mapLayerOptions: getMapLayerOptions({
lockedMapLayers: ['vehicles', 'citybike', 'stop'],
selectedMapLayers: ['vehicles'],
}),
mapLayerOptions: getMapLayerOptions(
{
lockedMapLayers: ['vehicles', 'citybike', 'stop'],
selectedMapLayers: ['vehicles'],
},
config.enableLockedMapLayers,
),
}),
{
config: PropTypes.object,
},
);

const containerComponent = createRefetchContainer(
Expand Down
15 changes: 10 additions & 5 deletions app/component/ItineraryPageUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,16 @@ export function updateClient(itineraryTopics, context) {
startClient(itineraryTopics, context);
}

export function addBikeStationMapForRentalVehicleItineraries() {
return getMapLayerOptions({
lockedMapLayers: ['vehicles', 'citybike', 'stop'],
selectedMapLayers: ['vehicles', 'citybike'],
});
export function addBikeStationMapForRentalVehicleItineraries(
enableLockedMapLayers,
) {
return getMapLayerOptions(
{
lockedMapLayers: ['vehicles', 'citybike', 'stop'],
selectedMapLayers: ['vehicles', 'citybike'],
},
enableLockedMapLayers,
);
}

/**
Expand Down
22 changes: 14 additions & 8 deletions app/component/StopsNearYouPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,13 @@ class StopsNearYouPage extends React.Component {
const showCityBikeTeaser = !readMessageIds.includes('citybike_teaser');
if (this.context.config.map.showLayerSelector) {
const { mode } = this.props.match.params;
const mapLayerOptions = getMapLayerOptions({
lockedMapLayers: ['vehicles', 'citybike', 'stop'],
selectedMapLayers: ['vehicles', mode.toLowerCase()],
});
const mapLayerOptions = getMapLayerOptions(
{
lockedMapLayers: ['vehicles', 'citybike', 'stop'],
selectedMapLayers: ['vehicles', mode.toLowerCase()],
},
this.context.config.enableLockedMapLayers,
);
this.setState({ showCityBikeTeaser, mapLayerOptions });
} else {
this.setState({ showCityBikeTeaser });
Expand Down Expand Up @@ -197,10 +200,13 @@ class StopsNearYouPage extends React.Component {

setMapLayerOptions = () => {
const { mode } = this.props.match.params;
const mapLayerOptions = getMapLayerOptions({
lockedMapLayers: ['vehicles', 'citybike', 'stop'],
selectedMapLayers: ['vehicles', mode.toLowerCase()],
});
const mapLayerOptions = getMapLayerOptions(
{
lockedMapLayers: ['vehicles', 'citybike', 'stop'],
selectedMapLayers: ['vehicles', mode.toLowerCase()],
},
this.context.config.enableLockedMapLayers,
);
this.setState({ mapLayerOptions });
};

Expand Down
16 changes: 11 additions & 5 deletions app/component/map/RoutePageMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,17 @@ class RoutePageMap extends React.Component {
const RoutePageMapWithVehicles = connectToStores(
withBreakpoint(RoutePageMap),
['RealTimeInformationStore', 'MapLayerStore'],
({ getStore }, { trip }) => {
({ config, getStore }, { trip }) => {
const mapLayers = getStore('MapLayerStore').getMapLayers({
notThese: ['stop', 'vehicles'],
});
const mapLayerOptions = getMapLayerOptions({
lockedMapLayers: ['vehicles', 'stop', 'citybike'],
selectedMapLayers: ['vehicles'],
});
const mapLayerOptions = getMapLayerOptions(
{
lockedMapLayers: ['vehicles', 'stop', 'citybike'],
selectedMapLayers: ['vehicles'],
},
config.enableLockedMapLayers,
);
if (trip) {
const { vehicles } = getStore('RealTimeInformationStore');
const tripStart = getStartTime(
Expand Down Expand Up @@ -227,6 +230,9 @@ const RoutePageMapWithVehicles = connectToStores(
}
return { mapLayers, mapLayerOptions };
},
{
config: PropTypes.object,
},
);

export default createFragmentContainer(RoutePageMapWithVehicles, {
Expand Down
11 changes: 7 additions & 4 deletions app/component/map/StopPageMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,13 @@ const StopPageMapWithStores = connectToStores(
}
const mapLayers = getStore(MapLayerStore).getMapLayers(ml);
const mode = getModeFromProps(props);
const mapLayerOptions = getMapLayerOptions({
lockedMapLayers: ['vehicles', mode],
selectedMapLayers: ['vehicles', mode],
});
const mapLayerOptions = getMapLayerOptions(
{
lockedMapLayers: ['vehicles', mode],
selectedMapLayers: ['vehicles', mode],
},
config.enableLockedMapLayers,
);
return {
locationState,
currentTime,
Expand Down
2 changes: 2 additions & 0 deletions app/configurations/config.herrenberg.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,8 @@ export default configMerger(parentConfig, {

layers,

enableLockedMapLayers: false,

staticMessagesUrl: STATIC_MESSAGE_URL,

parkAndRideBannedVehicleParkingTags: [
Expand Down
7 changes: 5 additions & 2 deletions app/util/mapLayerUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ export const isFeatureLayerEnabled = (
return isLayerEnabled(layerName, mapLayers);
};

export const getMapLayerOptions = (options = {}) => {
export const getMapLayerOptions = (
options = {},
enableLockedMapLayers = true,
) => {
const layerOptions = {
parkAndRide: {
isLocked: false,
Expand Down Expand Up @@ -147,7 +150,7 @@ export const getMapLayerOptions = (options = {}) => {
};
lockedMapLayers.forEach(key => {
// Stop keyword locks every mode
if (key === 'stop') {
if (enableLockedMapLayers && key === 'stop') {
Object.keys(layerOptions[key]).forEach(subKey => {
if (layerOptions[key][subKey]) {
layerOptions[key][subKey].isLocked = true;
Expand Down
Loading