From e657f347b0309c5e92ea9b202b1c7a74b61161c9 Mon Sep 17 00:00:00 2001
From: binh-dam-ibigroup <56846598+binh-dam-ibigroup@users.noreply.github.com>
Date: Mon, 23 Mar 2020 11:37:11 -0400
Subject: [PATCH 1/7] refactor(trip-details): Replace TripDetails component
with its OTP-UI counterpart.
---
.../narrative/connected-trip-details.js | 17 ++
.../narrative/default/default-itinerary.js | 2 +-
.../narrative/line-itin/itin-body.js | 2 +-
.../printable/printable-itinerary.js | 2 +-
lib/components/narrative/trip-details.js | 157 ------------------
lib/index.js | 2 +-
package.json | 7 +-
yarn.lock | 89 +++++-----
8 files changed, 65 insertions(+), 213 deletions(-)
create mode 100644 lib/components/narrative/connected-trip-details.js
delete mode 100644 lib/components/narrative/trip-details.js
diff --git a/lib/components/narrative/connected-trip-details.js b/lib/components/narrative/connected-trip-details.js
new file mode 100644
index 000000000..ee9042b03
--- /dev/null
+++ b/lib/components/narrative/connected-trip-details.js
@@ -0,0 +1,17 @@
+import { connect } from 'react-redux'
+import TripDetails from '@opentripplanner/trip-details'
+
+import { getTimeFormat, getLongDateFormat } from '../../util/time'
+
+// Connect imported TripDetails class to redux store.
+
+const mapStateToProps = (state, ownProps) => {
+ return {
+ routingType: state.otp.currentQuery.routingType,
+ tnc: state.otp.tnc,
+ timeFormat: getTimeFormat(state.otp.config),
+ longDateFormat: getLongDateFormat(state.otp.config)
+ }
+}
+
+export default connect(mapStateToProps)(TripDetails)
diff --git a/lib/components/narrative/default/default-itinerary.js b/lib/components/narrative/default/default-itinerary.js
index b6b66a227..57f2717de 100644
--- a/lib/components/narrative/default/default-itinerary.js
+++ b/lib/components/narrative/default/default-itinerary.js
@@ -3,7 +3,7 @@ import React from 'react'
import NarrativeItinerary from '../narrative-itinerary'
import ItinerarySummary from './itinerary-summary'
import ItineraryDetails from './itinerary-details'
-import TripDetails from '../trip-details'
+import TripDetails from '../connected-trip-details'
import TripTools from '../trip-tools'
import { formatDuration, formatTime } from '../../../util/time'
diff --git a/lib/components/narrative/line-itin/itin-body.js b/lib/components/narrative/line-itin/itin-body.js
index c38ced30d..713e02b7b 100644
--- a/lib/components/narrative/line-itin/itin-body.js
+++ b/lib/components/narrative/line-itin/itin-body.js
@@ -2,7 +2,7 @@ import React, { Component } from 'react'
import PropTypes from 'prop-types'
import isEqual from 'lodash.isequal'
-import TripDetails from '../trip-details'
+import TripDetails from '../connected-trip-details'
import TripTools from '../trip-tools'
import PlaceRow from './place-row'
diff --git a/lib/components/narrative/printable/printable-itinerary.js b/lib/components/narrative/printable/printable-itinerary.js
index ecb13c545..cf8d40cae 100644
--- a/lib/components/narrative/printable/printable-itinerary.js
+++ b/lib/components/narrative/printable/printable-itinerary.js
@@ -1,7 +1,7 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
-import TripDetails from '../trip-details'
+import TripDetails from '../connected-trip-details'
import { distanceString } from '../../../util/distance'
import { formatTime, formatDuration } from '../../../util/time'
import {
diff --git a/lib/components/narrative/trip-details.js b/lib/components/narrative/trip-details.js
deleted file mode 100644
index 0b7118d4f..000000000
--- a/lib/components/narrative/trip-details.js
+++ /dev/null
@@ -1,157 +0,0 @@
-import React, { Component } from 'react'
-import { connect } from 'react-redux'
-import { Button } from 'react-bootstrap'
-import { VelocityTransitionGroup } from 'velocity-react'
-import moment from 'moment'
-
-import { calculateFares, calculatePhysicalActivity, getTimeZoneOffset } from '../../util/itinerary'
-import { formatTime, getTimeFormat, getLongDateFormat } from '../../util/time'
-
-class TripDetails extends Component {
- render () {
- const { itinerary, timeFormat, longDateFormat } = this.props
- const date = moment(itinerary.startTime)
-
- // process the transit fare
- const { centsToString, dollarsToString, maxTNCFare, minTNCFare, transitFare } = calculateFares(itinerary)
- let companies
- itinerary.legs.forEach(leg => {
- if (leg.tncData) {
- companies = leg.tncData.company
- }
- })
- let fare
- if (transitFare || minTNCFare) {
- fare = (
-
- {transitFare && (
- Transit Fare: {centsToString(transitFare)}
- )}
- {minTNCFare !== 0 && (
-
-
-
- {companies.toLowerCase()}
- {' '}
- Fare: {dollarsToString(minTNCFare)} - {dollarsToString(maxTNCFare)}
-
- )}
-
- )
- }
-
- // Compute calories burned.
- const { bikeDuration, caloriesBurned, walkDuration } = calculatePhysicalActivity(itinerary)
-
- const timeOptions = {
- format: timeFormat,
- offset: getTimeZoneOffset(itinerary)
- }
-
- return (
-
-
Trip Details
-
-
}
- summary={
-
- Depart {date.format(longDateFormat)}
- {this.props.routingType === 'ITINERARY' && at {formatTime(itinerary.startTime, timeOptions)} }
-
- }
- />
- {fare && (
-
}
- summary={fare}
- />
- )}
- {caloriesBurned > 0 && (
-
}
- summary={
Calories Burned: {Math.round(caloriesBurned)} }
- description={
-
- Calories burned is based on {Math.round(walkDuration / 60)} minute(s) {' '}
- spent walking and {Math.round(bikeDuration / 60)} minute(s) {' '}
- spent biking during this trip. Adapted from{' '}
-
- Dietary Guidelines for Americans 2005, page 16, Table 4
- .
-
- }
- />
- )}
-
-
- )
- }
-}
-
-class TripDetail extends Component {
- constructor (props) {
- super(props)
- this.state = {
- expanded: false
- }
- }
-
- _toggle = () => this.state.expanded ? this._onHideClick() : this._onExpandClick()
-
- _onExpandClick = () => {
- this.setState({ expanded: true })
- }
-
- _onHideClick = () => {
- this.setState({ expanded: false })
- }
-
- render () {
- const { icon, summary, description } = this.props
- return (
-
-
{icon}
-
- {summary}
- {description && (
-
-
-
- )}
-
- {this.state.expanded && (
-
-
-
-
- {description}
-
- )}
-
-
-
- )
- }
-}
-
-// Connect main class to redux store
-
-const mapStateToProps = (state, ownProps) => {
- return {
- routingType: state.otp.currentQuery.routingType,
- tnc: state.otp.tnc,
- timeFormat: getTimeFormat(state.otp.config),
- longDateFormat: getLongDateFormat(state.otp.config)
- }
-}
-
-export default connect(mapStateToProps)(TripDetails)
diff --git a/lib/index.js b/lib/index.js
index c671bff9c..738918280 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -34,7 +34,7 @@ import NarrativeRoutingResults from './components/narrative/narrative-routing-re
import RealtimeAnnotation from './components/narrative/realtime-annotation'
import SimpleRealtimeAnnotation from './components/narrative/simple-realtime-annotation'
import TransportationNetworkCompanyLeg from './components/narrative/default/tnc-leg'
-import TripDetails from './components/narrative/trip-details'
+import TripDetails from './components/narrative/connected-trip-details'
import TripTools from './components/narrative/trip-tools'
import LineItinerary from './components/narrative/line-itin/line-itinerary'
diff --git a/package.json b/package.json
index 75f922e0a..445f85cbc 100644
--- a/package.json
+++ b/package.json
@@ -29,9 +29,10 @@
"dependencies": {
"@conveyal/lonlat": "^1.1.0",
"@mapbox/polyline": "^0.2.0",
- "@opentripplanner/from-to-location-picker": "^0.0.14",
- "@opentripplanner/geocoder": "^0.0.16",
- "@opentripplanner/location-field": "^0.0.16",
+ "@opentripplanner/from-to-location-picker": "^0.0.18",
+ "@opentripplanner/geocoder": "^0.0.18",
+ "@opentripplanner/location-field": "^0.0.18",
+ "@opentripplanner/trip-details": "^0.0.18",
"bootstrap": "^3.3.7",
"clone": "^2.1.0",
"connected-react-router": "^6.5.2",
diff --git a/yarn.lock b/yarn.lock
index 48d3fff61..89f6e994a 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -1324,10 +1324,10 @@
universal-user-agent "^3.0.0"
url-template "^2.0.8"
-"@opentripplanner/core-utils@^0.0.14":
- version "0.0.14"
- resolved "https://registry.yarnpkg.com/@opentripplanner/core-utils/-/core-utils-0.0.14.tgz#9e58e78227759ab5c13e1dad22467c474bd102b7"
- integrity sha512-JMtOermSYrpPN649DEexd/EKdMPisBrooHiUAeCSdapXgxN7y1h+fUZj+OglLgUoo48wPRv7ru/n5doqVrGSaQ==
+"@opentripplanner/core-utils@^0.0.18":
+ version "0.0.18"
+ resolved "https://registry.yarnpkg.com/@opentripplanner/core-utils/-/core-utils-0.0.18.tgz#5109a60e262802dca3b1e7a34091c9a394f5b290"
+ integrity sha512-6ej3MVTd/Kz4OYnIDJBm8fT4OHkchWq+sU9G+Z6fHJhGE5nh/ljCcps/8Vew1HXK6nhaeDMm099nkA/8YKRnug==
dependencies:
"@mapbox/polyline" "^1.1.0"
"@turf/along" "^6.0.1"
@@ -1338,70 +1338,61 @@
prop-types "^15.7.2"
qs "^6.9.1"
-"@opentripplanner/core-utils@^0.0.16":
- version "0.0.16"
- resolved "https://registry.yarnpkg.com/@opentripplanner/core-utils/-/core-utils-0.0.16.tgz#72b85f9e36fb5dc00d442d9c2e6d883efdc3fa8d"
- integrity sha512-ekPxWC0woOJDbfj0Lxk+NX2fLpIGpbDRQbEsO/rF+UCCvg4sCcmobjHaMwtW6rAXtVzNMmFDYXctPW/49Qdq8A==
+"@opentripplanner/from-to-location-picker@^0.0.18":
+ version "0.0.18"
+ resolved "https://registry.yarnpkg.com/@opentripplanner/from-to-location-picker/-/from-to-location-picker-0.0.18.tgz#21d1164d09724becea640a95f97aadb479df8f24"
+ integrity sha512-y5GJxvf1La2Wk9ldEtKO5zzVnECi89HkrWdT5Tb2ZYuJrUVnPZZ28CmLEtQGSh+Qtj/kxVBMII/UOkoja3SkuQ==
dependencies:
- "@mapbox/polyline" "^1.1.0"
- "@turf/along" "^6.0.1"
- bowser "^2.7.0"
- lodash.isequal "^4.5.0"
- moment "^2.24.0"
- moment-timezone "^0.5.27"
- prop-types "^15.7.2"
- qs "^6.9.1"
-
-"@opentripplanner/from-to-location-picker@^0.0.14":
- version "0.0.14"
- resolved "https://registry.yarnpkg.com/@opentripplanner/from-to-location-picker/-/from-to-location-picker-0.0.14.tgz#efe2a3452d58d769bc0d5904753df8516279f6c7"
- integrity sha512-w2jf+wErtH34CdxQkAyHf446JeCsVxOYej6JRK15jc3+LCWi4bct2A0tf1wp9uNdMvAnL06AZL6hwsED6WqrVA==
- dependencies:
- "@opentripplanner/core-utils" "^0.0.14"
- "@opentripplanner/location-icon" "^0.0.13"
+ "@opentripplanner/core-utils" "^0.0.18"
+ "@opentripplanner/location-icon" "^0.0.18"
prop-types "^15.7.2"
-"@opentripplanner/geocoder@^0.0.16":
- version "0.0.16"
- resolved "https://registry.yarnpkg.com/@opentripplanner/geocoder/-/geocoder-0.0.16.tgz#55bdff8be36b2b68b83d62008c0fd45e03dd2a11"
- integrity sha512-wpIyKThP4FhNiXDLHGHyux+g7+BAWN43ZZzdOgSBhSHoKRYXee+Ga7ht3zsNtJroZhkDQkEISXiNejK16SCWvQ==
+"@opentripplanner/geocoder@^0.0.18":
+ version "0.0.18"
+ resolved "https://registry.yarnpkg.com/@opentripplanner/geocoder/-/geocoder-0.0.18.tgz#fe1ecddd025b08e6b2bf51a9ddf8c65e10571b90"
+ integrity sha512-NvqZDJc6c+fKRXys5jkaFD5F2gtXag4gKov2L6z0d3+Sn8BTQvDTuE961J5Bb/xn8xE4IvmcIs5tQmE/B+tvBw==
dependencies:
"@conveyal/geocoder-arcgis-geojson" "^0.0.2"
"@conveyal/lonlat" "^1.4.0"
isomorphic-mapzen-search "^1.4.1"
lodash.memoize "^4.1.2"
-"@opentripplanner/humanize-distance@^0.0.16":
- version "0.0.16"
- resolved "https://registry.yarnpkg.com/@opentripplanner/humanize-distance/-/humanize-distance-0.0.16.tgz#e8197671b45719ce5c728d34c60e80b6d816d287"
- integrity sha512-qec9FZGhITC1u+YIBn0+6drxvbJr4N7FX0+VdpXl4+op6xVPlH+LPRittQhdOXdwEjUwHA9qvmksIYE70mg9lw==
+"@opentripplanner/humanize-distance@^0.0.18":
+ version "0.0.18"
+ resolved "https://registry.yarnpkg.com/@opentripplanner/humanize-distance/-/humanize-distance-0.0.18.tgz#eeb49b826754e9e04ca84813781fa47baeaebc7f"
+ integrity sha512-emn2TTVBk9DUnbLPh9OIP/ZlKdbDpJzVWq+tO5HIqCIL1TW0XFEQDbQLv3b3rGS2R2LHbhKlYYJKmP36ZFS20w==
-"@opentripplanner/location-field@^0.0.16":
- version "0.0.16"
- resolved "https://registry.yarnpkg.com/@opentripplanner/location-field/-/location-field-0.0.16.tgz#1d23792965e9bfcd1044521b9bef261fbba090a7"
- integrity sha512-nnEspCddomJGJgWuGh8S2npUogKKa6oPCopCl0sdgU7UyI/xUpgwHwTHaxJyJNWQmd4RT+GgKv9jlzKRVtxFXA==
+"@opentripplanner/location-field@^0.0.18":
+ version "0.0.18"
+ resolved "https://registry.yarnpkg.com/@opentripplanner/location-field/-/location-field-0.0.18.tgz#c01d5a876f7cd76ee1855ed4ee186abd3ff85ae1"
+ integrity sha512-RAJkkgCWTuZRcjOguzFWb+z4YDLv8Lrp6V2QZJhNV289SPjokuGOuDrARl7+FQ8Di0ZuH95Ca/PipJEdeF2wAQ==
dependencies:
- "@opentripplanner/core-utils" "^0.0.16"
- "@opentripplanner/geocoder" "^0.0.16"
- "@opentripplanner/humanize-distance" "^0.0.16"
- "@opentripplanner/location-icon" "^0.0.16"
+ "@opentripplanner/core-utils" "^0.0.18"
+ "@opentripplanner/geocoder" "^0.0.18"
+ "@opentripplanner/humanize-distance" "^0.0.18"
+ "@opentripplanner/location-icon" "^0.0.18"
prop-types "^15.7.2"
styled-icons "^9.1.0"
throttle-debounce "^2.1.0"
-"@opentripplanner/location-icon@^0.0.13":
- version "0.0.13"
- resolved "https://registry.yarnpkg.com/@opentripplanner/location-icon/-/location-icon-0.0.13.tgz#18e53e2dcd916814675340c9a69d2bc7797bb177"
- integrity sha512-KeGm9xQLA2qdQHuPod706OUuoUk25cDjJrFA+waWaN9qQqcqSxOBavcLg5FH9yRQR8uuSTgi1yooIlccOUYnxQ==
+"@opentripplanner/location-icon@^0.0.18":
+ version "0.0.18"
+ resolved "https://registry.yarnpkg.com/@opentripplanner/location-icon/-/location-icon-0.0.18.tgz#8f207e1d7032ae04081cffa981ee3117c3647478"
+ integrity sha512-4Pv0RZZeHvDpc50XMOMUOS4E7dlYBNne/OvnOxHcbEmHSOUHGKNSiIq2EPO7Eyrae+SsKKhksv++okIiw6KOmw==
dependencies:
styled-icons "^9.1.0"
-"@opentripplanner/location-icon@^0.0.16":
- version "0.0.16"
- resolved "https://registry.yarnpkg.com/@opentripplanner/location-icon/-/location-icon-0.0.16.tgz#16824fb8dd522f59be39b28a2a31617b27532bcd"
- integrity sha512-QcbmO7aOcbECpKfZc2VNGxYq/HY7JZP+7FW6W1PBG98ThIbdg4cSwWWf7kf8fl3LpJAhqMdV14AE1O/P/Sq8rw==
+"@opentripplanner/trip-details@^0.0.18":
+ version "0.0.18"
+ resolved "https://registry.yarnpkg.com/@opentripplanner/trip-details/-/trip-details-0.0.18.tgz#69d8fa4e8a70977c9aaa71a777a34021aec0fa12"
+ integrity sha512-jCBgmPQhl9gsUniYSbPqDvpyFUHqsGNHUwHg+jqAplPHWu60Hn2F/P1oWf5PmjXlBV7ZFOsuTeH7HVmGfVrPrw==
dependencies:
+ "@opentripplanner/core-utils" "^0.0.18"
+ "@opentripplanner/humanize-distance" "^0.0.18"
+ moment "^2.24.0"
+ prop-types "^15.7.2"
styled-icons "^9.1.0"
+ velocity-react "^1.4.3"
"@semantic-release/commit-analyzer@^6.1.0":
version "6.2.0"
@@ -15970,7 +15961,7 @@ velocity-animate@^1.4.0:
resolved "https://registry.yarnpkg.com/velocity-animate/-/velocity-animate-1.5.2.tgz#5a351d75fca2a92756f5c3867548b873f6c32105"
integrity sha512-m6EXlCAMetKztO1ppBhGU1/1MR3IiEevO6ESq6rcrSQ3Q77xYSW13jkfXW88o4xMrkXJhy/U7j4wFR/twMB0Eg==
-velocity-react@^1.3.3:
+velocity-react@^1.3.3, velocity-react@^1.4.3:
version "1.4.3"
resolved "https://registry.yarnpkg.com/velocity-react/-/velocity-react-1.4.3.tgz#63e41d92e334d5a3bea8b2fa02ee170f62ef4d36"
integrity sha512-zvefGm85A88S3KdF9/dz5vqyFLAiwKYlXGYkHH2EbXl+CZUD1OT0a0aS1tkX/WXWTa/FUYqjBaAzAEFYuSobBQ==
From 1077fbf7dad36195ce6cefc623748af458cde3bb Mon Sep 17 00:00:00 2001
From: binh-dam-ibigroup <56846598+binh-dam-ibigroup@users.noreply.github.com>
Date: Mon, 23 Mar 2020 12:18:12 -0400
Subject: [PATCH 2/7] refactor(trip-viewer-overlay): Replace TripViewerOverlay
with its counterpart from OTP-UI.
---
.../map/connected-trip-viewer-overlay.js | 19 ++++++
lib/components/map/default-map.js | 5 +-
lib/components/map/trip-viewer-overlay.js | 60 -------------------
package.json | 1 +
yarn.lock | 9 +++
5 files changed, 32 insertions(+), 62 deletions(-)
create mode 100644 lib/components/map/connected-trip-viewer-overlay.js
delete mode 100644 lib/components/map/trip-viewer-overlay.js
diff --git a/lib/components/map/connected-trip-viewer-overlay.js b/lib/components/map/connected-trip-viewer-overlay.js
new file mode 100644
index 000000000..916464dfa
--- /dev/null
+++ b/lib/components/map/connected-trip-viewer-overlay.js
@@ -0,0 +1,19 @@
+import { connect } from 'react-redux'
+import { withLeaflet } from 'react-leaflet'
+import TripViewerOverlay from '@opentripplanner/trip-viewer-overlay'
+
+// connect to the redux store
+
+const mapStateToProps = (state, ownProps) => {
+ const viewedTrip = state.otp.ui.viewedTrip
+ return {
+ tripData: viewedTrip
+ ? state.otp.transitIndex.trips[viewedTrip.tripId]
+ : null
+ }
+}
+
+const mapDispatchToProps = {
+}
+
+export default connect(mapStateToProps, mapDispatchToProps)(withLeaflet(TripViewerOverlay))
diff --git a/lib/components/map/default-map.js b/lib/components/map/default-map.js
index b9432ffce..f979a0eb5 100644
--- a/lib/components/map/default-map.js
+++ b/lib/components/map/default-map.js
@@ -6,15 +6,16 @@ import {
carRentalQuery,
vehicleRentalQuery
} from '../../actions/api'
+
import BaseMap from './base-map'
import EndpointsOverlay from './endpoints-overlay'
import ParkAndRideOverlay from './park-and-ride-overlay'
+import RouteViewerOverlay from './route-viewer-overlay'
import StopsOverlay from './stops-overlay'
import StopViewerOverlay from './stop-viewer-overlay'
import TileOverlay from './tile-overlay'
import TransitiveOverlay from './transitive-overlay'
-import TripViewerOverlay from './trip-viewer-overlay'
-import RouteViewerOverlay from './route-viewer-overlay'
+import TripViewerOverlay from './connected-trip-viewer-overlay'
import VehicleRentalOverlay from './vehicle-rental-overlay'
import ZipcarOverlay from './zipcar-overlay'
diff --git a/lib/components/map/trip-viewer-overlay.js b/lib/components/map/trip-viewer-overlay.js
deleted file mode 100644
index 42368a392..000000000
--- a/lib/components/map/trip-viewer-overlay.js
+++ /dev/null
@@ -1,60 +0,0 @@
-import React from 'react'
-import PropTypes from 'prop-types'
-import { connect } from 'react-redux'
-import { FeatureGroup, MapLayer, Polyline, withLeaflet } from 'react-leaflet'
-
-import polyline from '@mapbox/polyline'
-
-class TripViewerOverlay extends MapLayer {
- static propTypes = {
- tripData: PropTypes.object,
- viewedTrip: PropTypes.object
- }
-
- componentDidMount () { }
-
- // TODO: determine why the default MapLayer componentWillUnmount() method throws an error
- componentWillUnmount () { }
-
- componentDidUpdate (prevProps) {
- const oldGeometry = prevProps.tripData && prevProps.tripData.geometry
- const newGeometry = this.props.tripData && this.props.tripData.geometry
- if (oldGeometry === newGeometry || !newGeometry) return
- const pts = polyline.decode(newGeometry.points)
- this.props.leaflet.map.fitBounds(pts)
- }
-
- createLeafletElement () { }
-
- updateLeafletElement () { }
-
- render () {
- const { tripData } = this.props
-
- if (!tripData || !tripData.geometry) return
-
- const pts = polyline.decode(tripData.geometry.points)
- return (
-
-
-
- )
- }
-}
-
-// connect to the redux store
-
-const mapStateToProps = (state, ownProps) => {
- const viewedTrip = state.otp.ui.viewedTrip
- return {
- viewedTrip,
- tripData: viewedTrip
- ? state.otp.transitIndex.trips[viewedTrip.tripId]
- : null
- }
-}
-
-const mapDispatchToProps = {
-}
-
-export default connect(mapStateToProps, mapDispatchToProps)(withLeaflet(TripViewerOverlay))
diff --git a/package.json b/package.json
index 445f85cbc..6a963e51f 100644
--- a/package.json
+++ b/package.json
@@ -33,6 +33,7 @@
"@opentripplanner/geocoder": "^0.0.18",
"@opentripplanner/location-field": "^0.0.18",
"@opentripplanner/trip-details": "^0.0.18",
+ "@opentripplanner/trip-viewer-overlay": "^0.0.18",
"bootstrap": "^3.3.7",
"clone": "^2.1.0",
"connected-react-router": "^6.5.2",
diff --git a/yarn.lock b/yarn.lock
index 89f6e994a..85016c4be 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -1394,6 +1394,15 @@
styled-icons "^9.1.0"
velocity-react "^1.4.3"
+"@opentripplanner/trip-viewer-overlay@^0.0.18":
+ version "0.0.18"
+ resolved "https://registry.yarnpkg.com/@opentripplanner/trip-viewer-overlay/-/trip-viewer-overlay-0.0.18.tgz#7e774378cc274caf7603aa14a08d4b57cd220b14"
+ integrity sha512-iz+KQBFRZORz36w10kXEUHhxS4CwTCXWb8xcLYAwh9LmWkHhbGXPnClwn6PJ+BPj0PcdvLukcQaCUpoxZggfqg==
+ dependencies:
+ "@mapbox/polyline" "^1.1.0"
+ "@opentripplanner/core-utils" "^0.0.18"
+ prop-types "^15.7.2"
+
"@semantic-release/commit-analyzer@^6.1.0":
version "6.2.0"
resolved "https://registry.yarnpkg.com/@semantic-release/commit-analyzer/-/commit-analyzer-6.2.0.tgz#5cd25ce67ba9ba5b46e47457505e63629e186695"
From b0e3cd51e405759bf94c4d748253845d495292f7 Mon Sep 17 00:00:00 2001
From: binh-dam-ibigroup <56846598+binh-dam-ibigroup@users.noreply.github.com>
Date: Mon, 23 Mar 2020 12:35:23 -0400
Subject: [PATCH 3/7] refactor(narrative.css): Remove old trip-details styles.
---
lib/components/narrative/narrative.css | 52 --------------------------
1 file changed, 52 deletions(-)
diff --git a/lib/components/narrative/narrative.css b/lib/components/narrative/narrative.css
index 21c1ab760..ac8c4effa 100644
--- a/lib/components/narrative/narrative.css
+++ b/lib/components/narrative/narrative.css
@@ -116,58 +116,6 @@
fontSize: 16px;
}
-/* TRIP DETAILS */
-
-.otp .trip-details {
- border: 2px solid gray;
- padding: 6px 10px;
- margin-top: 16px;
-}
-
-.otp .trip-details .trip-details-header {
- font-size: 18px;
- font-weight: 600;
-}
-
-.otp .trip-details .trip-detail {
- margin-top: 6px;
-}
-
-.otp .trip-details .trip-detail .icon {
- float: left;
- font-size: 17px;
-}
-
-.otp .trip-details .trip-detail .summary {
- margin-left: 28px;
- padding-top: 2px;
-}
-
-.otp .trip-details .trip-detail .expand-button {
- margin-left: 6px;
- margin-top: -2px;
- font-size: 16px;
- color: blue;
-}
-
-.otp .trip-details .trip-detail .description {
- background-color: #fff;
- border: 1px solid #888;
- padding: 8px;
- margin-top: 2px;
- font-size: 12px;
-}
-
-.otp .trip-details .trip-detail b {
- font-weight: 600;
-}
-
-.otp .trip-details .trip-detail .hide-button {
- float: right;
- top: 5;
- right: 5;
-}
-
/* TRIP TOOLS ROW */
.otp .trip-tools {
margin-top: 10px;
From 6a6aaee4bb552ad9d11fb580e4e1cc19f9ad09bc Mon Sep 17 00:00:00 2001
From: binh-dam-ibigroup <56846598+binh-dam-ibigroup@users.noreply.github.com>
Date: Mon, 23 Mar 2020 14:16:16 -0400
Subject: [PATCH 4/7] fix(connected-trip-details): Bring back styling using
styled-components.
---
lib/components/narrative/connected-trip-details.js | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/lib/components/narrative/connected-trip-details.js b/lib/components/narrative/connected-trip-details.js
index ee9042b03..cfdccb898 100644
--- a/lib/components/narrative/connected-trip-details.js
+++ b/lib/components/narrative/connected-trip-details.js
@@ -1,8 +1,16 @@
import { connect } from 'react-redux'
-import TripDetails from '@opentripplanner/trip-details'
+import styled from 'styled-components'
+import UITripDetails from '@opentripplanner/trip-details'
import { getTimeFormat, getLongDateFormat } from '../../util/time'
+const TripDetails = styled(UITripDetails)`
+ border: 2px solid gray;
+ border-radius: 0;
+ padding: 6px 10px;
+ margin: 16px 0 10px;
+`
+
// Connect imported TripDetails class to redux store.
const mapStateToProps = (state, ownProps) => {
From cd26acfdc78624f2e4425af6d6ed4cf0be3a380e Mon Sep 17 00:00:00 2001
From: binh-dam-ibigroup <56846598+binh-dam-ibigroup@users.noreply.github.com>
Date: Mon, 23 Mar 2020 14:18:01 -0400
Subject: [PATCH 5/7] refactor(connected-trip-details): Rename imported class.
---
lib/components/narrative/connected-trip-details.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/components/narrative/connected-trip-details.js b/lib/components/narrative/connected-trip-details.js
index cfdccb898..16183ea1e 100644
--- a/lib/components/narrative/connected-trip-details.js
+++ b/lib/components/narrative/connected-trip-details.js
@@ -1,10 +1,10 @@
import { connect } from 'react-redux'
import styled from 'styled-components'
-import UITripDetails from '@opentripplanner/trip-details'
+import TripDetailsBase from '@opentripplanner/trip-details'
import { getTimeFormat, getLongDateFormat } from '../../util/time'
-const TripDetails = styled(UITripDetails)`
+const TripDetails = styled(TripDetailsBase)`
border: 2px solid gray;
border-radius: 0;
padding: 6px 10px;
From b72c501084958eec8d1a037bfb9a52d54d5d9f17 Mon Sep 17 00:00:00 2001
From: binh-dam-ibigroup <56846598+binh-dam-ibigroup@users.noreply.github.com>
Date: Mon, 23 Mar 2020 18:21:47 -0400
Subject: [PATCH 6/7] refactor(printable-itinerary): Replace PrintableItinerary
with its counterpart from OTP-UI.
Also change PrintLayout to support customIcons from configuration, and remove unused CSS.
---
lib/components/app/print-layout.js | 48 ++--
.../narrative/printable/itinerary.css | 33 ---
.../printable/printable-itinerary.js | 221 ------------------
lib/index.css | 1 -
package.json | 2 +
yarn.lock | 17 ++
6 files changed, 52 insertions(+), 270 deletions(-)
delete mode 100644 lib/components/narrative/printable/itinerary.css
delete mode 100644 lib/components/narrative/printable/printable-itinerary.js
diff --git a/lib/components/app/print-layout.js b/lib/components/app/print-layout.js
index d6d126747..fa00581df 100644
--- a/lib/components/app/print-layout.js
+++ b/lib/components/app/print-layout.js
@@ -2,15 +2,16 @@ import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import { Button } from 'react-bootstrap'
+import TriMetLegIcon from '@opentripplanner/icons/lib/trimet-leg-icon'
+import PrintableItinerary from '@opentripplanner/printable-itinerary'
import BaseMap from '../map/base-map'
import EndpointsOverlay from '../map/endpoints-overlay'
import TransitiveOverlay from '../map/transitive-overlay'
-import PrintableItinerary from '../narrative/printable/printable-itinerary'
+import TripDetails from '../narrative/connected-trip-details'
import { parseUrlQueryString } from '../../actions/form'
import { routingQuery } from '../../actions/api'
import { getActiveItinerary } from '../../util/state'
-import { getTimeFormat } from '../../util/time'
class PrintLayout extends Component {
static propTypes = {
@@ -34,14 +35,14 @@ class PrintLayout extends Component {
}
componentDidMount () {
- const { location } = this.props
+ const { location, parseUrlQueryString } = this.props
// Add print-view class to html tag to ensure that iOS scroll fix only applies
// to non-print views.
const root = document.getElementsByTagName('html')[0]
root.setAttribute('class', 'print-view')
// Parse the URL query parameters, if present
if (location && location.search) {
- this.props.parseUrlQueryString()
+ parseUrlQueryString()
}
}
@@ -53,8 +54,24 @@ class PrintLayout extends Component {
root.removeAttribute('class')
}
+ /**
+ * Use one of the customIcons if provided,
+ * (similar to @opentraiplanner/trip-form/ModeIcon)
+ * otherwise, fall back on TriMetLegIcon.
+ * TODO: Combine all custom icon rendering in one place.
+ */
+ customLegIcon = icons => {
+ return function ({leg, props}) {
+ // Check if there is a custom icon (exact match required).
+ if (icons && leg.mode in icons) {
+ return icons[leg.mode]
+ }
+ return TriMetLegIcon({leg, props})
+ }
+ }
+
render () {
- const { configCompanies, customIcons, itinerary, timeFormat } = this.props
+ const { config, customIcons, itinerary } = this.props
return (
{/* The header bar, including the Toggle Map and Print buttons */}
@@ -82,13 +99,15 @@ class PrintLayout extends Component {
}
{/* The main itinerary body */}
- {itinerary
- ?
- : null
+ {itinerary &&
+
}
)
@@ -99,9 +118,8 @@ class PrintLayout extends Component {
const mapStateToProps = (state, ownProps) => {
return {
- itinerary: getActiveItinerary(state.otp),
- configCompanies: state.otp.config.companies,
- timeFormat: getTimeFormat(state.otp.config)
+ config: state.otp.config,
+ itinerary: getActiveItinerary(state.otp)
}
}
diff --git a/lib/components/narrative/printable/itinerary.css b/lib/components/narrative/printable/itinerary.css
deleted file mode 100644
index 07b6c9dfe..000000000
--- a/lib/components/narrative/printable/itinerary.css
+++ /dev/null
@@ -1,33 +0,0 @@
-.otp .printable-itinerary .leg {
- margin-bottom: 10px;
- border-top: 1px solid gray;
- padding-top: 18px;
-}
-
-.otp .printable-itinerary .leg.collapse-top {
- border-top: none;
- padding-top: 0px;
-}
-
-.otp .printable-itinerary .mode-icon {
- float: left;
- width: 32px;
- height: 32px;
-}
-
-.otp .printable-itinerary .leg-body {
- margin-left: 40px;
-}
-
-.otp .printable-itinerary .leg-header {
- font-size: 18px;
-}
-
-.otp .printable-itinerary .leg-details {
- margin-top: 5px;
-}
-
-.otp .printable-itinerary .leg-detail {
- margin-top: 3px;
- font-size: 14px;
-}
diff --git a/lib/components/narrative/printable/printable-itinerary.js b/lib/components/narrative/printable/printable-itinerary.js
deleted file mode 100644
index cf8d40cae..000000000
--- a/lib/components/narrative/printable/printable-itinerary.js
+++ /dev/null
@@ -1,221 +0,0 @@
-import React, { Component } from 'react'
-import PropTypes from 'prop-types'
-
-import TripDetails from '../connected-trip-details'
-import { distanceString } from '../../../util/distance'
-import { formatTime, formatDuration } from '../../../util/time'
-import {
- getCompaniesLabelFromNetworks,
- getLegIcon,
- getLegModeLabel,
- getPlaceName,
- getStepDirection,
- getStepStreetName,
- getTimeZoneOffset
-} from '../../../util/itinerary'
-
-export default class PrintableItinerary extends Component {
- static propTypes = {
- itinerary: PropTypes.object
- }
-
- render () {
- const {
- configCompanies,
- customIcons,
- itinerary,
- timeFormat
- } = this.props
-
- const timeOptions = {
- format: timeFormat,
- offset: getTimeZoneOffset(itinerary)
- }
-
- return (
-
- {itinerary.legs.length > 0 && (
-
-
-
- Depart from {itinerary.legs[0].from.name}
-
-
-
- )}
- {itinerary.legs.map((leg, k) => leg.transitLeg
- ?
- : leg.hailedCar
- ?
- :
- )}
-
-
- )
- }
-}
-
-class TransitLeg extends Component {
- static propTypes = {
- leg: PropTypes.object
- }
-
- render () {
- const { customIcons, leg, interlineFollows, timeOptions } = this.props
-
- // Handle case of transit leg interlined w/ previous
- if (leg.interlineWithPreviousLeg) {
- return (
-
-
-
- Continues as{' '}
- {leg.routeShortName} {leg.routeLongName} {' '}
- to {leg.to.name}
-
-
-
- Get off at {leg.to.name} {' '}
- at {formatTime(leg.endTime, timeOptions)}
-
-
-
-
- )
- }
-
- return (
-
-
{getLegIcon(leg, customIcons)}
-
-
- {leg.routeShortName} {leg.routeLongName} to {leg.to.name}
-
-
-
- Board at {leg.from.name} {' '}
- at {formatTime(leg.startTime, timeOptions)}
-
-
- {interlineFollows
- ? Stay on board at {leg.to.name}
- :
- Get off at {leg.to.name} {' '}
- at {formatTime(leg.endTime, timeOptions)}
-
- }
-
-
-
-
- )
- }
-}
-
-class AccessLeg extends Component {
- static propTypes = {
- leg: PropTypes.object
- }
-
- render () {
- const { configCompanies, customIcons, leg } = this.props
-
- // calculate leg mode label in a special way for this component
- let legModeLabel = getLegModeLabel(leg)
-
- if (leg.rentedBike) {
- // FIXME: Special case for TriMet that needs to be refactored to
- // incorporate actual company.
- legModeLabel = 'Ride BIKETOWN bike'
- } else if (leg.rentedCar) {
- // Add extra information to printview that would otherwise clutter up
- // other places that use the getLegModeLabel function
- const companiesLabel = getCompaniesLabelFromNetworks(
- leg.from.networks,
- configCompanies
- )
- legModeLabel = `Drive ${companiesLabel} ${leg.from.name}`
- } else if (leg.rentedVehicle) {
- const companiesLabel = getCompaniesLabelFromNetworks(
- leg.from.networks,
- configCompanies
- )
- legModeLabel = `Ride ${companiesLabel} E-scooter`
- }
-
- return (
-
-
{getLegIcon(leg, customIcons)}
-
-
- {legModeLabel} {' '}
- {!leg.hailedCar &&
- leg.distance > 0 &&
- {distanceString(leg.distance)} }
- to {getPlaceName(leg.to, configCompanies)}
-
- {!leg.hailedCar && (
-
- {leg.steps.map((step, k) => {
- return (
-
- {getStepDirection(step)} on {getStepStreetName(step)}
-
- )
- })}
-
- )}
-
-
- )
- }
-}
-
-class TNCLeg extends Component {
- static propTypes = {
- leg: PropTypes.object
- }
-
- render () {
- const { customIcons, leg } = this.props
- const { tncData } = leg
- if (!tncData) return null
-
- return (
-
-
{getLegIcon(leg, customIcons)}
-
-
- Take {tncData.displayName} to {leg.to.name}
-
-
-
- Estimated wait time for pickup:{' '}
- {formatDuration(tncData.estimatedArrival)}
-
-
- Estimated travel time:{' '}
- {formatDuration(leg.duration)} (does not account for traffic)
-
-
-
-
- )
- }
-}
diff --git a/lib/index.css b/lib/index.css
index 41bd670a6..3d67aa9c4 100644
--- a/lib/index.css
+++ b/lib/index.css
@@ -12,7 +12,6 @@
@import url(lib/components/narrative/narrative.css);
@import url(lib/components/narrative/default/itinerary.css);
@import url(lib/components/narrative/line-itin/itinerary.css);
-@import url(lib/components/narrative/printable/itinerary.css);
@import url(lib/components/mobile/mobile.css);
@import url(lib/components/viewers/viewers.css);
diff --git a/package.json b/package.json
index 6a963e51f..0047d97af 100644
--- a/package.json
+++ b/package.json
@@ -31,7 +31,9 @@
"@mapbox/polyline": "^0.2.0",
"@opentripplanner/from-to-location-picker": "^0.0.18",
"@opentripplanner/geocoder": "^0.0.18",
+ "@opentripplanner/icons": "^0.0.18",
"@opentripplanner/location-field": "^0.0.18",
+ "@opentripplanner/printable-itinerary": "^0.0.18",
"@opentripplanner/trip-details": "^0.0.18",
"@opentripplanner/trip-viewer-overlay": "^0.0.18",
"bootstrap": "^3.3.7",
diff --git a/yarn.lock b/yarn.lock
index 85016c4be..5da232a90 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -1362,6 +1362,14 @@
resolved "https://registry.yarnpkg.com/@opentripplanner/humanize-distance/-/humanize-distance-0.0.18.tgz#eeb49b826754e9e04ca84813781fa47baeaebc7f"
integrity sha512-emn2TTVBk9DUnbLPh9OIP/ZlKdbDpJzVWq+tO5HIqCIL1TW0XFEQDbQLv3b3rGS2R2LHbhKlYYJKmP36ZFS20w==
+"@opentripplanner/icons@^0.0.18":
+ version "0.0.18"
+ resolved "https://registry.yarnpkg.com/@opentripplanner/icons/-/icons-0.0.18.tgz#4486286988801d374a31975aec80ac326ff17061"
+ integrity sha512-g0+8r9VL/6TPXlFak4mg8xOzAGzID5SGMurLayXvCuroFIbqwUD3/BOhGUD6+z25MvOv3Tov7V9wtN9l822eTg==
+ dependencies:
+ "@opentripplanner/core-utils" "^0.0.18"
+ prop-types "^15.7.2"
+
"@opentripplanner/location-field@^0.0.18":
version "0.0.18"
resolved "https://registry.yarnpkg.com/@opentripplanner/location-field/-/location-field-0.0.18.tgz#c01d5a876f7cd76ee1855ed4ee186abd3ff85ae1"
@@ -1382,6 +1390,15 @@
dependencies:
styled-icons "^9.1.0"
+"@opentripplanner/printable-itinerary@^0.0.18":
+ version "0.0.18"
+ resolved "https://registry.yarnpkg.com/@opentripplanner/printable-itinerary/-/printable-itinerary-0.0.18.tgz#4137fa0000f8c1164e5fa4226243e0b887412105"
+ integrity sha512-uxUm80WU4m8Pni3OzkBzMI/7kmtgRSR7e3wJqy6N9PpZRyEEzUzzSaDmAS8+/nswgZyrNpeenp5ZK5e+7AJA+g==
+ dependencies:
+ "@opentripplanner/core-utils" "^0.0.18"
+ "@opentripplanner/humanize-distance" "^0.0.18"
+ prop-types "^15.7.2"
+
"@opentripplanner/trip-details@^0.0.18":
version "0.0.18"
resolved "https://registry.yarnpkg.com/@opentripplanner/trip-details/-/trip-details-0.0.18.tgz#69d8fa4e8a70977c9aaa71a777a34021aec0fa12"
From db1f3bf0acb2f7693e176388394fbe4db36f7f31 Mon Sep 17 00:00:00 2001
From: binh-dam-ibigroup <56846598+binh-dam-ibigroup@users.noreply.github.com>
Date: Tue, 24 Mar 2020 11:08:29 -0400
Subject: [PATCH 7/7] style(PrintLayout, TripViewerOverlay): Change style and
typo per PR review.
---
lib/components/app/print-layout.js | 6 +++---
lib/components/map/connected-trip-viewer-overlay.js | 3 +--
2 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/lib/components/app/print-layout.js b/lib/components/app/print-layout.js
index fa00581df..e6687f166 100644
--- a/lib/components/app/print-layout.js
+++ b/lib/components/app/print-layout.js
@@ -56,7 +56,7 @@ class PrintLayout extends Component {
/**
* Use one of the customIcons if provided,
- * (similar to @opentraiplanner/trip-form/ModeIcon)
+ * (similar to @opentriplanner/trip-form/ModeIcon)
* otherwise, fall back on TriMetLegIcon.
* TODO: Combine all custom icon rendering in one place.
*/
@@ -100,14 +100,14 @@ class PrintLayout extends Component {
{/* The main itinerary body */}
{itinerary &&
-
+ >
}
)
diff --git a/lib/components/map/connected-trip-viewer-overlay.js b/lib/components/map/connected-trip-viewer-overlay.js
index 916464dfa..3159e694e 100644
--- a/lib/components/map/connected-trip-viewer-overlay.js
+++ b/lib/components/map/connected-trip-viewer-overlay.js
@@ -13,7 +13,6 @@ const mapStateToProps = (state, ownProps) => {
}
}
-const mapDispatchToProps = {
-}
+const mapDispatchToProps = {}
export default connect(mapStateToProps, mapDispatchToProps)(withLeaflet(TripViewerOverlay))