Skip to content

Add alternate route names to itin description #1406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions lib/components/narrative/metro/attribute-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,33 @@ export const removeInsignificantWalkLegs = (leg: Leg): boolean =>
// TODO: Make the 400 meters configurable?
leg.mode !== 'WALK' || leg.distance > 400

export const getAlternateRoutesFromLeg = (
leg: Leg & { alternateRoutes?: { [id: string]: Leg } }
): Array<[string, Leg]> => {
return Object.entries(leg.alternateRoutes || {})
}
/**
* Generate text for all routes used in an itinerary.
* TODO: include all alternate routes inside alternateRoutes as well!
*/
export const getItineraryRoutes = (
itinerary: Itinerary,
intl: IntlShape
): React.ReactNode => {
return intl.formatList(
itinerary.legs
.map((leg: Leg) => {
return leg.routeShortName
.map((leg: Leg & { alternateRoutes?: { [id: string]: Leg } }) => {
const alternateRouteNames =
leg.alternateRoutes &&
getAlternateRoutesFromLeg(leg)
.map((route) => route[1].routeShortName || route[1].routeLongName)
.filter((name) => !!name)

const routeName = leg.routeShortName || leg.routeLongName
return !alternateRouteNames
? routeName
: intl.formatList([routeName, ...alternateRouteNames], {
type: 'disjunction'
})
})
.filter((name) => !!name)
)
Expand Down
3 changes: 2 additions & 1 deletion lib/components/narrative/metro/route-block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import styled from 'styled-components'

import { ComponentContext } from '../../../util/contexts'

import { getAlternateRoutesFromLeg } from './attribute-utils'
import DefaultRouteRenderer from './default-route-renderer'

type Props = {
Expand Down Expand Up @@ -124,7 +125,7 @@ const RouteBlock = ({
// Determine if the routeShortName will fit!
const alternateRoutesAreTooLongToDisplay =
leg?.alternateRoutes &&
Object.entries(leg.alternateRoutes || {}).every(
getAlternateRoutesFromLeg(leg).every(
(altRoute) =>
// This 7 does a good job at filtering out most problematic short names,
// but may be revistited in the future depending on what feeds cause issues
Expand Down
Loading