Skip to content
Open
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
1 change: 1 addition & 0 deletions __tests__/test-utils/mock-data/empty-string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = ''
54 changes: 53 additions & 1 deletion lib/components/map/default-map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck
import { connect } from 'react-redux'
import {
findRequiredOptionsForTransportMode,
RequiredOptionsForTransportMode
} from '@opentripplanner/trip-form'
import { GeolocateControl, NavigationControl } from 'react-map-gl/maplibre'
import { getCurrentDate } from '@opentripplanner/core-utils/lib/time'
import { injectIntl } from 'react-intl'
import { MapLocationActionArg } from '@opentripplanner/types'
import { QueryParamChangeEvent } from '@opentripplanner/trip-form/lib/types'
import BaseMap from '@opentripplanner/base-map'
import generateOTP2TileLayers from '@opentripplanner/otp2-tile-overlay'
import React, { Component } from 'react'
Expand All @@ -18,10 +24,17 @@ import {
vehicleRentalQuery
} from '../../actions/api'
import { ComponentContext } from '../../util/contexts'
import { decodeQueryParams } from 'serialize-query-params'
import { getActiveItinerary, getActiveSearch } from '../../util/state'
import { getCurrentPosition } from '../../actions/location'
import { MainPanelContent } from '../../actions/ui-constants'
import {
modesQueryParamConfig,
onSettingsUpdate,
setModeButton
} from '../form/util'
import { setLocation, setMapPopupLocationAndGeocode } from '../../actions/map'
import { setQueryParam } from '../../actions/form'
import { setViewedStop } from '../../actions/ui'
import { updateOverlayVisibility } from '../../actions/config'
import TransitOperatorIcons from '../util/connected-transit-operator-icons'
Expand Down Expand Up @@ -303,6 +316,7 @@ class DefaultMap extends Component {
carRentalQuery,
carRentalStations,
config,
enabledModeButtons,
getCurrentPosition,
intl,
itinerary,
Expand All @@ -311,6 +325,7 @@ class DefaultMap extends Component {
nearbyViewActive,
pending,
setLocation,
setQueryParam,
setViewedStop,
vehicleRentalQuery,
vehicleRentalStations,
Expand Down Expand Up @@ -345,6 +360,34 @@ class DefaultMap extends Component {
const baseLayerUrls = baseLayersWithNames?.map((bl) => bl.url)
const baseLayerNames = baseLayersWithNames?.map((bl) => bl.name)

const overlayTypes = overlays
?.find((overlay) => overlay?.type === 'otp2')
?.layers?.map((layer) => layer?.type)
const handleSetLocation = (location: MapLocationActionArg) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is one approach, but could we not fix this by adjusting query params? What if we check for map state in the places where query params are set? Might that be a better separation of concerns than setting modes within the map component?

if (overlayTypes && overlayTypes.includes('rentalVehicles')) {
const requiredOptions: RequiredOptionsForTransportMode =
findRequiredOptionsForTransportMode(
config.modes.modeButtons,
config.modes.modeSettingDefinitions,
{ mode: 'SCOOTER', qualifier: 'RENT' }
)
if (requiredOptions) {
const modeSetter = setModeButton(
enabledModeButtons,
onSettingsUpdate(setQueryParam)
)

modeSetter(requiredOptions.modeButton, true)

if (requiredOptions.modeSetting)
onSettingsUpdate(setQueryParam)({
[requiredOptions.modeSetting]: true
})
}
}
setLocation(location)
}

const routeBasedTransitVehicleOverlayNameOverride =
overlays?.find((o) => o.type === 'vehicles-one-route') || undefined

Expand Down Expand Up @@ -468,7 +511,7 @@ class DefaultMap extends Component {
name: getLayerName(l, config, intl) || l.network || l.type
})),
vectorTilesEndpoint,
setLocation,
handleSetLocation,
setViewedStop,
viewedRouteStops,
config.companies,
Expand Down Expand Up @@ -516,12 +559,20 @@ const mapStateToProps = (state) => {
)
)
: null
const urlSearchParams = new URLSearchParams(state.router.location.search)
const { modes } = state.otp.config

return {
activeNearbyFilters,
bikeRentalStations: state.otp.overlay.bikeRental.stations,
carRentalStations: state.otp.overlay.carRental.stations,
config: state.otp.config,
enabledModeButtons:
decodeQueryParams(modesQueryParamConfig, {
modeButtons: urlSearchParams.get('modeButtons')
})?.modeButtons ||
modes?.initialState?.enabledModeButtons ||
{},
itinerary: getActiveItinerary(state),
mapConfig: state.otp.config.map,
nearbyFilters,
Expand All @@ -541,6 +592,7 @@ const mapDispatchToProps = {
getCurrentPosition,
setLocation,
setMapPopupLocationAndGeocode,
setQueryParam,
setViewedStop,
updateOverlayVisibility,
vehicleRentalQuery
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"@opentripplanner/transit-vehicle-overlay": "7.0.0",
"@opentripplanner/transitive-overlay": "7.0.0",
"@opentripplanner/trip-details": "^8.0.1",
"@opentripplanner/trip-form": "6.0.1",
"@opentripplanner/trip-form": "6.1.0",
"@opentripplanner/trip-viewer-overlay": "5.0.0",
"@opentripplanner/vehicle-rental-overlay": "5.0.0",
"@styled-icons/fa-regular": "^10.34.0",
Expand Down Expand Up @@ -210,6 +210,7 @@
"i18n/(.*)\\.yml$": "<rootDir>__tests__/test-utils/mock-data/empty-yml.js",
"modeSettings.yml$": "<rootDir>__tests__/test-utils/mock-data/empty-yml.js",
"i18n-loader": "<rootDir>__tests__/test-utils/mock-data/i18n-loader.js",
"\\.graphql$": "<rootDir>__tests__/test-utils/mock-data/empty-string.js",
"\\.(jpg|ico|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>__tests__/test-utils/mock-data/fileMock.js"
},
"transform": {
Expand Down
28 changes: 23 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2725,6 +2725,24 @@
lodash.isequal "^4.5.0"
qs "^6.9.1"

"@opentripplanner/[email protected]":
version "14.0.1"
resolved "https://registry.yarnpkg.com/@opentripplanner/core-utils/-/core-utils-14.0.1.tgz#8800c9cd50680ff09e5375b4a20d2f1c24fb4a8b"
integrity sha512-LfCNtl+YORiBxeutC4+SXL4yMIumrMdL3zNfcV+mghRtpRmus36xd5rCgnzXtv1d6Arbbk+zXixJg90j/tBmwA==
dependencies:
"@conveyal/lonlat" "^1.4.1"
"@mapbox/polyline" "^1.1.1"
"@opentripplanner/geocoder" "3.0.5"
"@styled-icons/foundation" "^10.34.0"
"@turf/along" "^6.0.1"
chroma-js "^2.4.2"
date-fns "^2.28.0"
date-fns-tz "^1.2.2"
graphql "^16.6.0"
lodash.clonedeep "^4.5.0"
lodash.isequal "^4.5.0"
qs "^6.9.1"

"@opentripplanner/[email protected]":
version "5.0.0"
resolved "https://registry.yarnpkg.com/@opentripplanner/endpoints-overlay/-/endpoints-overlay-5.0.0.tgz#216ba195ef7cf9dd8f76b862480c018e7b96ffc6"
Expand Down Expand Up @@ -2938,14 +2956,14 @@
flat "^5.0.2"
react-animate-height "^3.0.4"

"@opentripplanner/trip-form@6.0.1":
version "6.0.1"
resolved "https://registry.yarnpkg.com/@opentripplanner/trip-form/-/trip-form-6.0.1.tgz#262079589e056bf49c285a5b38257c54c59f088f"
integrity sha512-7o8frpL7rhieQmkrSaAxj+kqp8ocHyxmyB2l2LH8jJmoGgGevtQ5VxEmXaVctwpGJ12Fi1P/yiqD08PqnPG49w==
"@opentripplanner/trip-form@6.1.0":
version "6.1.0"
resolved "https://registry.yarnpkg.com/@opentripplanner/trip-form/-/trip-form-6.1.0.tgz#0238052e423436f25ecd0edc3d98c6c5b3429754"
integrity sha512-jeo6wPZBHaf5wBJI3msrjckc5C08WMj6VkRe5b+a2CqEoDwPInxRN658+H6qgxDeCxFzNiOehey3lQq35bTP/Q==
dependencies:
"@floating-ui/react" "^0.19.2"
"@opentripplanner/building-blocks" "3.0.1"
"@opentripplanner/core-utils" "13.0.1"
"@opentripplanner/core-utils" "14.0.1"
"@opentripplanner/icons" "4.0.0"
"@styled-icons/bootstrap" "^10.34.0"
"@styled-icons/boxicons-regular" "^10.38.0"
Expand Down
Loading