From f2c5871636d66005d24f6d5e03e5dd5650a1ec3d Mon Sep 17 00:00:00 2001 From: miles-grant-ibigroup Date: Wed, 13 Sep 2023 15:07:18 -0400 Subject: [PATCH 1/3] fix: un-de-duplicate headsigns in pattern viewer --- i18n/en-US.yml | 1 + lib/components/viewers/route-details.tsx | 29 +++++++++++++----------- lib/components/viewers/styled.ts | 1 - 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/i18n/en-US.yml b/i18n/en-US.yml index 9a1a8c9a7..9a4dab4e6 100644 --- a/i18n/en-US.yml +++ b/i18n/en-US.yml @@ -472,6 +472,7 @@ components: RouteDetails: moreDetails: More Details operatedBy: Operated by {agencyName} + headsignTo: "{headsign} ({lastStop})" selectADirection: Select a direction... stopsTo: Toward RouteViewer: diff --git a/lib/components/viewers/route-details.tsx b/lib/components/viewers/route-details.tsx index 579e376cc..48e6c6bc2 100644 --- a/lib/components/viewers/route-details.tsx +++ b/lib/components/viewers/route-details.tsx @@ -43,6 +43,7 @@ interface PatternSummary { geometryLength: number headsign: string id: string + lastStop?: string } interface Props { @@ -85,27 +86,29 @@ class RouteDetails extends Component { ([id, pat]): PatternSummary => ({ geometryLength: pat.patternGeometry?.length || 0, headsign: extractHeadsignFromPattern(pat, shortName), - id + id, + lastStop: pat.stops?.[pat.stops?.length - 1]?.name }) ) - // Remove duplicate headsigns. Using a reducer means that the first pattern - // with a specific headsign is the accepted one. TODO: is this good behavior? + // Remove duplicate headsigns. Replaces duplicate headsigns with the last stop name .reduce((prev: PatternSummary[], cur) => { const amended = prev const alreadyExistingIndex = prev.findIndex( (h) => h.headsign === cur.headsign ) - // If the item we're replacing has less geometry, replace it! - if (alreadyExistingIndex >= 0) { - // Only replace if new pattern has greater geometry - if ( - amended[alreadyExistingIndex].geometryLength < cur.geometryLength - ) { - amended[alreadyExistingIndex] = cur - } - } else { - amended.push(cur) + // If the item we're replacing has less geometry, amend the headsign to be more helpful + if ( + alreadyExistingIndex >= 0 && + cur.lastStop && + cur.headsign !== cur.lastStop + ) { + cur.headsign = intl.formatMessage( + { id: 'components.RouteDetails.headsignTo' }, + { ...cur } + ) } + + amended.push(cur) return amended }, []) .sort((a, b) => { diff --git a/lib/components/viewers/styled.ts b/lib/components/viewers/styled.ts index 16bfbe173..278dbbd12 100644 --- a/lib/components/viewers/styled.ts +++ b/lib/components/viewers/styled.ts @@ -52,7 +52,6 @@ export const PatternContainer = styled.div` align-items: center; display: flex; justify-content: space-between; - max-width: 300px; width: 95%; span { From 7d847ba7417a1ee0b6c1b87e1cc42a44cef29149 Mon Sep 17 00:00:00 2001 From: miles-grant-ibigroup Date: Wed, 13 Sep 2023 15:19:12 -0400 Subject: [PATCH 2/3] ci: appease --- i18n/en-US.yml | 2 +- i18n/fr.yml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/i18n/en-US.yml b/i18n/en-US.yml index 9a4dab4e6..80815f847 100644 --- a/i18n/en-US.yml +++ b/i18n/en-US.yml @@ -470,9 +470,9 @@ components: tripsFound: We Found {count, plural, one {# Option} other {# Options}} waiting: Waiting... RouteDetails: + headsignTo: "{headsign} ({lastStop})" moreDetails: More Details operatedBy: Operated by {agencyName} - headsignTo: "{headsign} ({lastStop})" selectADirection: Select a direction... stopsTo: Toward RouteViewer: diff --git a/i18n/fr.yml b/i18n/fr.yml index 0cc06933a..7c07ce285 100644 --- a/i18n/fr.yml +++ b/i18n/fr.yml @@ -485,6 +485,7 @@ components: tripsFound: "{count, plural, one {# trajet trouvé} other {# trajets trouvés}}" waiting: Patientez... RouteDetails: + headsignTo: "{headsign} ({lastStop})" moreDetails: Plus d'infos operatedBy: Exploité par {agencyName} selectADirection: Choisissez une direction... From 6f2210291ce3b874a6d725a0c19c7867cc9ab678 Mon Sep 17 00:00:00 2001 From: miles-grant-ibigroup Date: Fri, 15 Sep 2023 14:28:36 -0400 Subject: [PATCH 3/3] address pr feedback --- lib/components/viewers/route-details.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/components/viewers/route-details.tsx b/lib/components/viewers/route-details.tsx index 48e6c6bc2..c85382e9e 100644 --- a/lib/components/viewers/route-details.tsx +++ b/lib/components/viewers/route-details.tsx @@ -90,7 +90,7 @@ class RouteDetails extends Component { lastStop: pat.stops?.[pat.stops?.length - 1]?.name }) ) - // Remove duplicate headsigns. Replaces duplicate headsigns with the last stop name + // Address duplicate headsigns. Replaces duplicate headsigns with the last stop name .reduce((prev: PatternSummary[], cur) => { const amended = prev const alreadyExistingIndex = prev.findIndex(