Skip to content

Commit 2842877

Browse files
fix(transitive): Upgrade to core-utils/transitive-overlay 1.0.7.
1 parent 7389e85 commit 2842877

4 files changed

Lines changed: 79 additions & 36 deletions

File tree

example.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ const TermsOfStorage = () => (
7272
// define some application-wide components that should be used in
7373
// various places. The following components can be provided here:
7474
// - defaultMobileTitle (required)
75+
// - getTransitiveRouteLabel (optional, with signature itineraryLeg => string)
7576
// - ItineraryBody (required)
7677
// - ItineraryFooter (optional)
7778
// - LegIcon (required)
@@ -84,7 +85,18 @@ const TermsOfStorage = () => (
8485
// - TermsOfService (required if otpConfig.persistence.strategy === 'otp_middleware')
8586
// - TermsOfStorage (required if otpConfig.persistence.strategy === 'otp_middleware')
8687
const components = {
88+
8789
defaultMobileTitle: () => <div className='navbar-title'>OpenTripPlanner</div>,
90+
/**
91+
* Example of a custom route label provider to pass to @opentripplanner/core-utils/map#itineraryToTransitive.
92+
* @param {*} itineraryLeg The OTP itinerary leg for which to obtain a custom route label.
93+
* @returns A string with the custom label to display for the given leg, or null to render no label.
94+
*/
95+
getTransitiveRouteLabel: itineraryLeg => {
96+
if (itineraryLeg.mode === 'RAIL') return 'Train'
97+
if (itineraryLeg.mode === 'BUS') return itineraryLeg.routeShortName
98+
return null // null or undefined or empty string will tell transitive-js to not render a route label.
99+
},
88100
ItineraryBody: DefaultItinerary,
89101
LegIcon: MyLegIcon,
90102
MainControls: isCallTakerModuleEnabled ? CallTakerControls : null,
Lines changed: 44 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,62 @@
11
import coreUtils from '@opentripplanner/core-utils'
22
import TransitiveCanvasOverlay from '@opentripplanner/transitive-overlay'
3+
import React, { Component } from 'react'
34
import { connect } from 'react-redux'
45

5-
import { getActiveSearch, getActiveItinerary, getActiveItineraries } from '../../util/state'
6+
import { ComponentContext } from '../../util/contexts'
7+
import { getActiveItinerary, getActiveItineraries, getActiveSearch } from '../../util/state'
8+
9+
/**
10+
* Wrapper for TransitiveCanvasOverlay that passes getTransitiveRouteLabel defined in ComponentContext.
11+
*/
12+
class TransitiveCanvasOverlayWithContext extends Component {
13+
static contextType = ComponentContext
14+
15+
render () {
16+
const { activeSearchResponseOtp, activeSearchVisibleItinerary, ...otherProps } = this.props
17+
let transitiveData = null
18+
if (activeSearchVisibleItinerary) {
19+
transitiveData = coreUtils.map.itineraryToTransitive(activeSearchVisibleItinerary, null, this.context.getTransitiveRouteLabel)
20+
} else if (activeSearchResponseOtp) {
21+
transitiveData = activeSearchResponseOtp
22+
}
23+
24+
return <TransitiveCanvasOverlay {...otherProps} transitiveData={transitiveData} />
25+
}
26+
}
627

728
// connect to the redux store
829

930
const mapStateToProps = (state, ownProps) => {
1031
const activeSearch = getActiveSearch(state.otp)
11-
let transitiveData = null
12-
if (
13-
activeSearch &&
14-
activeSearch.query.routingType === 'ITINERARY' &&
15-
activeSearch.response &&
16-
activeSearch.response.length > 0
17-
) {
18-
// FIXME: This may need some simplification.
19-
const itins = getActiveItineraries(state.otp)
20-
const visibleIndex = activeSearch.visibleItinerary !== undefined && activeSearch.visibleItinerary !== null
21-
? activeSearch.visibleItinerary
22-
: activeSearch.activeItinerary
23-
// TODO: prevent itineraryToTransitive() from being called more than needed
24-
const visibleItinerary = itins[visibleIndex] ? itins[visibleIndex] : getActiveItinerary(state.otp)
25-
if (visibleItinerary) transitiveData = coreUtils.map.itineraryToTransitive(visibleItinerary)
26-
} else if (
27-
activeSearch &&
28-
activeSearch.response &&
29-
activeSearch.response.otp
30-
) {
31-
transitiveData = activeSearch.response.otp
32-
}
33-
32+
const { activeItinerary, query, response, visibleItinerary } = activeSearch || {}
3433
const { labeledModes, styles } = state.otp.config.map.transitive || {}
34+
let activeSearchVisibleItinerary = null
35+
let activeSearchResponseOtp = null
36+
37+
if (response) {
38+
if (query.routingType === 'ITINERARY' && response.length > 0) {
39+
// FIXME: This may need some simplification.
40+
const itins = getActiveItineraries(state.otp)
41+
const visibleIndex = visibleItinerary !== undefined && visibleItinerary !== null
42+
? visibleItinerary
43+
: activeItinerary
44+
// TODO: prevent itineraryToTransitive() from being called more than needed
45+
activeSearchVisibleItinerary = itins[visibleIndex] || getActiveItinerary(state.otp)
46+
} else if (response.otp) {
47+
activeSearchResponseOtp = response.otp
48+
}
49+
}
3550

3651
return {
37-
activeItinerary: activeSearch && activeSearch.activeItinerary,
52+
activeItinerary,
53+
activeSearchResponseOtp,
54+
activeSearchVisibleItinerary,
3855
labeledModes,
39-
routingType: activeSearch && activeSearch.query && activeSearch.query.routingType,
56+
routingType: query && query.routingType,
4057
styles,
41-
transitiveData,
4258
visible: true
4359
}
4460
}
4561

46-
export default connect(mapStateToProps)(TransitiveCanvasOverlay)
62+
export default connect(mapStateToProps)(TransitiveCanvasOverlayWithContext)

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"dependencies": {
3131
"@auth0/auth0-react": "^1.1.0",
3232
"@opentripplanner/base-map": "^1.0.5",
33-
"@opentripplanner/core-utils": "^3.1.0",
33+
"@opentripplanner/core-utils": "^3.1.1",
3434
"@opentripplanner/endpoints-overlay": "^1.0.6",
3535
"@opentripplanner/from-to-location-picker": "^1.0.4",
3636
"@opentripplanner/geocoder": "^1.0.2",
@@ -44,7 +44,7 @@
4444
"@opentripplanner/route-viewer-overlay": "^1.0.4",
4545
"@opentripplanner/stop-viewer-overlay": "^1.0.4",
4646
"@opentripplanner/stops-overlay": "^3.0.2",
47-
"@opentripplanner/transitive-overlay": "^1.0.6",
47+
"@opentripplanner/transitive-overlay": "^1.0.7",
4848
"@opentripplanner/trip-details": "^1.1.4",
4949
"@opentripplanner/trip-form": "^1.0.5",
5050
"@opentripplanner/trip-viewer-overlay": "^1.0.4",

yarn.lock

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,7 +1495,7 @@
14951495
"@opentripplanner/core-utils" "^3.0.4"
14961496
prop-types "^15.7.2"
14971497

1498-
"@opentripplanner/core-utils@^3.0.0", "@opentripplanner/core-utils@^3.0.4", "@opentripplanner/core-utils@^3.1.0":
1498+
"@opentripplanner/core-utils@^3.0.0", "@opentripplanner/core-utils@^3.0.4":
14991499
version "3.1.0"
15001500
resolved "https://registry.yarnpkg.com/@opentripplanner/core-utils/-/core-utils-3.1.0.tgz#4626807893874503c5d365b05e5db4a1b3bf163c"
15011501
integrity sha512-EYhIv6nQdmadmkQumuXGrEwvRrhUl8xDPckSv24y3o9FX7uk8h5Gqe4FPdjnBT1eOj/XUj0/fZzNcETHUvZvUg==
@@ -1510,6 +1510,21 @@
15101510
prop-types "^15.7.2"
15111511
qs "^6.9.1"
15121512

1513+
"@opentripplanner/core-utils@^3.1.1":
1514+
version "3.1.1"
1515+
resolved "https://registry.yarnpkg.com/@opentripplanner/core-utils/-/core-utils-3.1.1.tgz#d3582cbfe7a84cd5370d63a857dd26dff17591e5"
1516+
integrity sha512-20uY3uh2TawPG9PWLLWi5TVJ8F1/bws6cRaRfRNwk11qtdeFQNnVqxZGEd8q1OQSW7UI15cM45SCrK7V7Kxn6A==
1517+
dependencies:
1518+
"@mapbox/polyline" "^1.1.0"
1519+
"@opentripplanner/geocoder" "^1.0.2"
1520+
"@turf/along" "^6.0.1"
1521+
bowser "^2.7.0"
1522+
lodash.isequal "^4.5.0"
1523+
moment "^2.24.0"
1524+
moment-timezone "^0.5.27"
1525+
prop-types "^15.7.2"
1526+
qs "^6.9.1"
1527+
15131528
"@opentripplanner/endpoints-overlay@^1.0.6":
15141529
version "1.0.6"
15151530
resolved "https://registry.yarnpkg.com/@opentripplanner/endpoints-overlay/-/endpoints-overlay-1.0.6.tgz#db636e61a058475fbcafdc6fba9443e20455da2f"
@@ -1631,12 +1646,12 @@
16311646
"@opentripplanner/from-to-location-picker" "^1.0.3"
16321647
"@opentripplanner/zoom-based-markers" "^1.0.1"
16331648

1634-
"@opentripplanner/transitive-overlay@^1.0.6":
1635-
version "1.0.6"
1636-
resolved "https://registry.yarnpkg.com/@opentripplanner/transitive-overlay/-/transitive-overlay-1.0.6.tgz#73a1cedbc1df897b950f172e4145924462e88217"
1637-
integrity sha512-JXRJWEhhwl3cYFJVO4EULaXQywHaAr2TtHnbCulCgc+jmKOHQTnyLx2son5OKo3NR8v5FIo2YaleoHczhLhnWA==
1649+
"@opentripplanner/transitive-overlay@^1.0.7":
1650+
version "1.0.7"
1651+
resolved "https://registry.yarnpkg.com/@opentripplanner/transitive-overlay/-/transitive-overlay-1.0.7.tgz#42706fea6ce3fd3c93b75d272c6da1c00e9044e4"
1652+
integrity sha512-2QgvfGgq/8B2EpzFAtaxrmexP/k97WHZwKMVho4ZNPiAYfcaE5kRsa1ifWy5A5hHXb36ixAgzfJYiVLeadWbQQ==
16381653
dependencies:
1639-
"@opentripplanner/core-utils" "^3.0.4"
1654+
"@opentripplanner/core-utils" "^3.1.1"
16401655
lodash.isequal "^4.5.0"
16411656
transitive-js "^0.13.7"
16421657

0 commit comments

Comments
 (0)