Skip to content

Commit bd9e51c

Browse files
committed
fix(print): show custom icons, add distance, improve wording
1 parent ce93f97 commit bd9e51c

File tree

5 files changed

+82
-21
lines changed

5 files changed

+82
-21
lines changed

Diff for: lib/components/app/print-layout.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class PrintLayout extends Component {
5959
}
6060

6161
render () {
62-
const { companies, itinerary, timeFormat } = this.props
62+
const { configCompanies, customIcons, itinerary, timeFormat } = this.props
6363
return (
6464
<div className='otp print-layout'>
6565
{/* The header bar, including the Toggle Map and Print buttons */}
@@ -89,8 +89,9 @@ class PrintLayout extends Component {
8989
{/* The main itinerary body */}
9090
{itinerary
9191
? <PrintableItinerary
92+
configCompanies={configCompanies}
93+
customIcons={customIcons}
9294
itinerary={itinerary}
93-
companies={companies}
9495
timeFormat={timeFormat} />
9596
: null
9697
}
@@ -104,7 +105,7 @@ class PrintLayout extends Component {
104105
const mapStateToProps = (state, ownProps) => {
105106
return {
106107
itinerary: getActiveItinerary(state.otp),
107-
companies: state.otp.config.companies,
108+
configCompanies: state.otp.config.companies,
108109
timeFormat: getTimeFormat(state.otp.config)
109110
}
110111
}

Diff for: lib/components/app/responsive-webapp.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,10 @@ class RouterWrapper extends Component {
193193
/>
194194
<Route
195195
path='/print'
196-
component={PrintLayout}
196+
component={(routerProps) => {
197+
const props = {...this.props, ...routerProps}
198+
return <PrintLayout {...props} />
199+
}}
197200
/>
198201
{/* For any other route, simply return the web app. */}
199202
<Route

Diff for: lib/components/narrative/line-itin/place-row.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { connect } from 'react-redux'
44
import LocationIcon from '../../icons/location-icon'
55
import ViewStopButton from '../../viewers/view-stop-button'
66
import {
7-
getCompanyForNetwork,
7+
getCompaniesLabelFromNetworks,
88
getModeForPlace,
99
getPlaceName
1010
} from '../../../util/itinerary'
@@ -187,9 +187,11 @@ class RentedVehicleLeg extends PureComponent {
187187
// resumes there won't be any network info. In that case we simply return
188188
// that the rental is continuing.
189189
if (leg.from.networks) {
190-
const companies = leg.from.networks.map(n => getCompanyForNetwork(n, configCompanies))
191-
const companyLabel = companies.map(co => co.label).join('/')
192-
rentalDescription += ` ${companyLabel}`
190+
const companiesLabel = getCompaniesLabelFromNetworks(
191+
leg.from.networks,
192+
configCompanies
193+
)
194+
rentalDescription += ` ${companiesLabel}`
193195
// Only show vehicle name for car rentals. For bikes and eScooters, these
194196
// IDs/names tend to be less relevant (or entirely useless) in this context.
195197
if (leg.rentedCar && leg.from.name) {
@@ -200,7 +202,7 @@ class RentedVehicleLeg extends PureComponent {
200202
rentalDescription = 'Continue using rental'
201203
}
202204

203-
rentalDescription += ` ${modeString}${vehicleName}`
205+
rentalDescription += ` ${modeString} ${vehicleName}`
204206
}
205207
// e.g., Pick up REACHNOW rented car XYZNDB OR
206208
// Pick up SPIN eScooter

Diff for: lib/components/narrative/printable/printable-itinerary.js

+50-12
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import React, { Component } from 'react'
22
import PropTypes from 'prop-types'
33

4-
import ModeIcon from '../../icons/mode-icon'
54
import TripDetails from '../trip-details'
5+
import { distanceString } from '../../../util/distance'
66
import { formatTime, formatDuration } from '../../../util/time'
77
import {
8+
getCompaniesLabelFromNetworks,
9+
getLegIcon,
810
getLegModeLabel,
911
getPlaceName,
1012
getStepDirection,
@@ -18,7 +20,12 @@ export default class PrintableItinerary extends Component {
1820
}
1921

2022
render () {
21-
const { companies, itinerary, timeFormat } = this.props
23+
const {
24+
configCompanies,
25+
customIcons,
26+
itinerary,
27+
timeFormat
28+
} = this.props
2229

2330
const timeOptions = {
2431
format: timeFormat,
@@ -39,20 +46,24 @@ export default class PrintableItinerary extends Component {
3946
{itinerary.legs.map((leg, k) => leg.transitLeg
4047
? <TransitLeg
4148
key={k}
42-
leg={leg}
49+
customIcons={customIcons}
4350
interlineFollows={k < itinerary.legs.length - 1 &&
4451
itinerary.legs[k + 1].interlineWithPreviousLeg
4552
}
53+
leg={leg}
4654
timeOptions={timeOptions} />
4755
: leg.hailedCar
4856
? <TNCLeg
57+
customIcons={customIcons}
4958
leg={leg}
5059
timeOptions={timeOptions} />
5160
: <AccessLeg
5261
key={k}
62+
configCompanies={configCompanies}
63+
customIcons={customIcons}
5364
leg={leg}
5465
timeOptions={timeOptions}
55-
companies={companies} />
66+
/>
5667
)}
5768
<TripDetails itinerary={itinerary} />
5869
</div>
@@ -66,7 +77,7 @@ class TransitLeg extends Component {
6677
}
6778

6879
render () {
69-
const { leg, interlineFollows, timeOptions } = this.props
80+
const { customIcons, leg, interlineFollows, timeOptions } = this.props
7081

7182
// Handle case of transit leg interlined w/ previous
7283
if (leg.interlineWithPreviousLeg) {
@@ -91,7 +102,7 @@ class TransitLeg extends Component {
91102

92103
return (
93104
<div className='leg'>
94-
<div className='mode-icon'><ModeIcon mode={leg.mode} /></div>
105+
<div className='mode-icon'>{getLegIcon(leg, customIcons)}</div>
95106
<div className='leg-body'>
96107
<div className='leg-header'>
97108
<b>{leg.routeShortName} {leg.routeLongName}</b> to <b>{leg.to.name}</b>
@@ -123,14 +134,41 @@ class AccessLeg extends Component {
123134
}
124135

125136
render () {
126-
const { companies, leg } = this.props
137+
const { configCompanies, customIcons, leg } = this.props
138+
139+
// calculate leg mode label in a special way for this component
140+
let legModeLabel = getLegModeLabel(leg)
141+
142+
if (leg.rentedBike) {
143+
// FIXME: Special case for TriMet that needs to be refactored to
144+
// incorporate actual company.
145+
legModeLabel = 'Ride BIKETOWN bike'
146+
} else if (leg.rentedCar) {
147+
// Add extra information to printview that would otherwise clutter up
148+
// other places that use the getLegModeLabel function
149+
const companiesLabel = getCompaniesLabelFromNetworks(
150+
leg.from.networks,
151+
configCompanies
152+
)
153+
legModeLabel = `Drive ${companiesLabel} ${leg.from.name}`
154+
} else if (leg.rentedVehicle) {
155+
const companiesLabel = getCompaniesLabelFromNetworks(
156+
leg.from.networks,
157+
configCompanies
158+
)
159+
legModeLabel = `Ride ${companiesLabel} eScooter`
160+
}
161+
127162
return (
128163
<div className='leg'>
129-
<div className='mode-icon'><ModeIcon mode={leg.mode} /></div>
164+
<div className='mode-icon'>{getLegIcon(leg, customIcons)}</div>
130165
<div className='leg-body'>
131166
<div className='leg-header'>
132-
<b>{getLegModeLabel(leg)}</b>{' '}
133-
to <b>{getPlaceName(leg.to, companies)}</b>
167+
<b>{legModeLabel}</b>{' '}
168+
{!leg.hailedCar &&
169+
leg.distance > 0 &&
170+
<span> {distanceString(leg.distance)} </span>}
171+
to <b>{getPlaceName(leg.to, configCompanies)}</b>
134172
</div>
135173
{!leg.hailedCar && (
136174
<div className='leg-details'>
@@ -155,13 +193,13 @@ class TNCLeg extends Component {
155193
}
156194

157195
render () {
158-
const { leg } = this.props
196+
const { customIcons, leg } = this.props
159197
const { tncData } = leg
160198
if (!tncData) return null
161199

162200
return (
163201
<div className='leg'>
164-
<div className='mode-icon'><ModeIcon mode={leg.mode} /></div>
202+
<div className='mode-icon'>{getLegIcon(leg, customIcons)}</div>
165203
<div className='leg-body'>
166204
<div className='leg-header'>
167205
<b>Take {tncData.displayName}</b> to <b>{leg.to.name}</b>

Diff for: lib/util/itinerary.js

+17
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,10 @@ export function getLegIcon (leg, customIcons) {
402402
return getIcon(iconStr, customIcons)
403403
}
404404

405+
/**
406+
* Get the configured company object for the given network string if the company
407+
* has been defined in the provided companies array config.
408+
*/
405409
export function getCompanyForNetwork (networkString, companies = []) {
406410
const company = companies.find(co => co.id === networkString)
407411
if (!company) {
@@ -410,6 +414,19 @@ export function getCompanyForNetwork (networkString, companies = []) {
410414
return company
411415
}
412416

417+
/**
418+
* Get a string label to display from a list of vehicle rental networks.
419+
*
420+
* @param {Array<string>} networks A list of network ids.
421+
* @param {Array<object>} [companies=[]] An optional list of the companies config.
422+
* @return {string} A label for use in presentation on a website.
423+
*/
424+
export function getCompaniesLabelFromNetworks (networks, companies = []) {
425+
return networks.map(network => getCompanyForNetwork(network, companies))
426+
.map(co => co.label)
427+
.join('/')
428+
}
429+
413430
/**
414431
* Returns mode name by checking the vertex type (VertexType class in OTP) for
415432
* the provided place. NOTE: this is currently only intended for vehicles at

0 commit comments

Comments
 (0)