Skip to content

Commit

Permalink
fix(NarrativeItineraries): Show Save trip only for itineraries with t…
Browse files Browse the repository at this point in the history
…ransit.
  • Loading branch information
binh-dam-ibigroup committed Oct 28, 2020
1 parent 822b618 commit 0379130
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/components/narrative/narrative-itineraries.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import DefaultItinerary from './default/default-itinerary'
import Icon from '../narrative/icon'
import LinkButton from '../user/link-button'
import { itineraryHasTransit } from '../../util/itinerary'
import {
getResponsesWithErrors,
getActiveItineraries,
Expand Down Expand Up @@ -120,6 +121,8 @@ class NarrativeItineraries extends Component {
} = this.props
if (!activeSearch) return null
const itineraryIsExpanded = activeItinerary !== undefined && activeItinerary !== null && this.state.showDetails
const showSaveButton = itineraryHasTransit(itineraries[activeItinerary])

const showRealtimeAnnotation = realtimeEffects.isAffectedByRealtimeData && (
realtimeEffects.exceedsThreshold ||
realtimeEffects.routesDiffer ||
Expand All @@ -146,7 +149,7 @@ class NarrativeItineraries extends Component {
<i className='fa fa-arrow-left' /> View all options
</button>
{/* FIXME: only save if meets requirements (e.g., is transit + non-realtime mode) */}
{persistence && persistence.enabled
{persistence && persistence.enabled && showSaveButton
? <LinkButton
componentClass='button'
className='clear-button-formatting'
Expand Down
16 changes: 16 additions & 0 deletions lib/util/itinerary.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,19 @@ export function getLeafletLegBounds (leg) {
export function isBatchRoutingEnabled (otpConfig) {
return Boolean(otpConfig.routingTypes.find(t => t.key === 'BATCH'))
}

// TODO: move to OTP-UI + add tests?
/**
* @returns true if at least one of the legs of the specified itinerary is a transit leg.
*/
export function itineraryHasTransit (itinerary) {
if (itinerary && itinerary.legs) {
for (const leg of itinerary.legs) {
if (coreUtils.itinerary.isTransit(leg.mode)) {
return true
}
}
}

return false
}

0 comments on commit 0379130

Please sign in to comment.