From 864cf79cd7160ebe33c81b48be8b74cc323bbefb Mon Sep 17 00:00:00 2001 From: Evan Siroky Date: Thu, 18 Jul 2019 09:39:06 -0700 Subject: [PATCH] fix(narrative): properly render eScooter legs occurring after forced walking --- .../narrative/line-itin/place-row.js | 56 ++++++++++++------- lib/util/itinerary.js | 4 +- 2 files changed, 38 insertions(+), 22 deletions(-) diff --git a/lib/components/narrative/line-itin/place-row.js b/lib/components/narrative/line-itin/place-row.js index 6667d7990..5ae81d09f 100644 --- a/lib/components/narrative/line-itin/place-row.js +++ b/lib/components/narrative/line-itin/place-row.js @@ -156,6 +156,9 @@ class RentedVehicleLeg extends PureComponent { render () { const { config, leg } = this.props const configCompanies = config.companies || [] + + // Sometimes rented vehicles can be walked over things like stairs or other + // ways that forbid the main mode of travel. if (leg.mode === 'WALK') { return (
@@ -163,35 +166,48 @@ class RentedVehicleLeg extends PureComponent {
) } - if (leg.rentedVehicle || leg.rentedBike || leg.rentedCar) { - let pickUpString = 'Pick up' - if (leg.rentedBike) { - // TODO: Special case for TriMet may need to be refactored. - pickUpString += ` shared bike` - } else { - // Add company and vehicle labels. + + let pickUpString = 'Pick up' + if (leg.rentedBike) { + // TODO: Special case for TriMet may need to be refactored. + pickUpString += ` shared bike` + } else { + // Add company and vehicle labels. + let vehicleName = '' + // TODO allow more flexibility in customizing these mode strings + let modeString = leg.rentedVehicle + ? 'eScooter' + : leg.rentedBike + ? 'bike' + : 'car' + + // The networks attribute of the from data will only appear at the very + // beggining of the rental. It is possible that there will be some forced + // walking that occurs in the middle of the rental, so once the main mode + // resumes there won't be any network info. In that case we simply return + // that the rental is continuing. + if (leg.from.networks) { const companies = leg.from.networks.map(n => getCompanyForNetwork(n, configCompanies)) const companyLabel = companies.map(co => co.label).join('/') pickUpString += ` ${companyLabel}` - const modeString = getModeForPlace(leg.from) // Only show vehicle name for car rentals. For bikes and eScooters, these // IDs/names tend to be less relevant (or entirely useless) in this context. - const vehicleName = leg.rentedCar ? ` ${leg.from.name}` : '' - pickUpString += ` ${modeString}${vehicleName}` + if (leg.rentedCar && leg.from.name) { + vehicleName = leg.from.name + } + modeString = getModeForPlace(leg.from) + } else { + pickUpString = 'Continue using rental' } - // e.g., Pick up REACHNOW rented car XYZNDB OR - // Pick up SPIN eScooter - // Pick up shared bike - return ( -
- {pickUpString} -
- ) + + pickUpString += ` ${modeString}${vehicleName}` } - // FIXME: Under what conditions would this be returned? + // e.g., Pick up REACHNOW rented car XYZNDB OR + // Pick up SPIN eScooter + // Pick up shared bike return (
- Continue riding from {leg.from.name} + {pickUpString}
) } diff --git a/lib/util/itinerary.js b/lib/util/itinerary.js index 7befc25bd..412e1bfae 100644 --- a/lib/util/itinerary.js +++ b/lib/util/itinerary.js @@ -393,9 +393,9 @@ export function getLegIcon (leg, customIcons) { iconStr = leg.from.networks[0] } else if (iconStr === 'CAR' && leg.tncData) { iconStr = leg.tncData.company - } else if (iconStr === 'BICYCLE' && leg.rentedBike) { + } else if (iconStr === 'BICYCLE' && leg.rentedBike && leg.from.networks) { iconStr = leg.from.networks[0] - } else if (iconStr === 'MICROMOBILITY' && leg.rentedVehicle) { + } else if (iconStr === 'MICROMOBILITY' && leg.rentedVehicle && leg.from.networks) { iconStr = leg.from.networks[0] }