diff --git a/client/src/components/Planner/TransitJourneyModal.tsx b/client/src/components/Planner/TransitJourneyModal.tsx index e39bac3fd..04d0f49c6 100644 --- a/client/src/components/Planner/TransitJourneyModal.tsx +++ b/client/src/components/Planner/TransitJourneyModal.tsx @@ -15,7 +15,7 @@ import { useTranslation } from '../../i18n' import { useSettingsStore } from '../../store/settingsStore' import { useTripStore } from '../../store/tripStore' import { splitReservationDateTime, formatTime } from '../../utils/formatters' -import { TransitTitle, TransitMetaBadges, TransitWalkDivider, fmtTransitDuration } from './transitDisplay' +import { TransitTitle, TransitLineBadge, TransitMetaBadges, TransitWalkDivider, fmtTransitDuration } from './transitDisplay' import type { Reservation } from '../../types' import { useIsPhone } from '../../mobile/useIsPhone' @@ -423,9 +423,7 @@ export default function TransitJourneyModal({ reservation, onClose, onSave, onDe
- - {leg.line || leg.mode} - + {leg.headsign && ( @@ -450,15 +448,13 @@ export default function TransitJourneyModal({ reservation, onClose, onSave, onDe
{leg.from?.time || ''}
- - {leg.line || leg.mode} - +
- {leg.from?.name} + {leg.from?.name} {leg.from?.track && ({t('transit.platform', { track: leg.from.track })})} - {leg.to?.name} + {leg.to?.name}
- - {leg.line || leg.mode} - + } + style={{ gap: 4, background: bg, color: fg, borderRadius: 6, padding: '2px 7px', fontSize: 'calc(11px * var(--fs-scale-caption, 1))', fontWeight: 700 }} + /> ) } @@ -425,7 +427,7 @@ function ItineraryCard({ it, tzFrom, tzTo, is12h, expanded, onToggle, onAdd, add ]} /> ) : ( <> - + { it('FE-PLANNER-BKTRANSIT-007: a line without its own colour and a leg without times or name', () => { render(); - expect(screen.getByText('BUS')).toHaveStyle({ background: 'var(--bg-tertiary)' }); + expect(screen.getByText('BUS').parentElement).toHaveStyle({ background: 'var(--bg-tertiary)' }); expect(screen.getByText('Walk to')).toBeInTheDocument(); expect(screen.queryByText(/min$/)).toBeNull(); }); it('FE-PLANNER-BKTRANSIT-008: a coloured line without a text colour is written in white', () => { render(); - expect(screen.getByText('M10')).toHaveStyle({ color: '#fff' }); + expect(screen.getByText('M10').parentElement).toHaveStyle({ color: '#fff' }); expect(screen.getByText('09:00')).toBeInTheDocument(); }); }); diff --git a/client/src/components/Planner/bookings/transitParts.tsx b/client/src/components/Planner/bookings/transitParts.tsx index 28dda974a..311bce032 100644 --- a/client/src/components/Planner/bookings/transitParts.tsx +++ b/client/src/components/Planner/bookings/transitParts.tsx @@ -1,6 +1,6 @@ import { ArrowRight, Clock, Footprints, MoveRight } from 'lucide-react' import { useTranslation } from '../../../i18n' -import { TransitMetaBadges, type TransitLegDisplay } from '../transitDisplay' +import { TransitLineBadge, TransitMetaBadges, type TransitLegDisplay } from '../transitDisplay' import { BOX, fs } from './bookingParts' export interface TransitSummary { @@ -41,11 +41,11 @@ export function TransitLegs({ legs, compact = false }: { legs: TransitLegDisplay return (
{walk ? : ( - {leg.line || leg.mode} + }} /> )}
{/* Detail views show a stop name whole: the names wrap and the diff --git a/client/src/components/Planner/transitDisplay.test.tsx b/client/src/components/Planner/transitDisplay.test.tsx index 0904b1ac6..88714f832 100644 --- a/client/src/components/Planner/transitDisplay.test.tsx +++ b/client/src/components/Planner/transitDisplay.test.tsx @@ -1,8 +1,8 @@ -// FE-PLANNER-TRANSITDISPLAY-001 to FE-PLANNER-TRANSITDISPLAY-003 +// FE-PLANNER-TRANSITDISPLAY-001 to FE-PLANNER-TRANSITDISPLAY-005 import { describe, expect, it } from 'vitest'; import { render, screen } from '../../../tests/helpers/render'; import type { TransitLegDisplay } from './transitDisplay'; -import { TransitItineraryInline, TransitWalkDivider } from './transitDisplay'; +import { TransitItineraryInline, TransitLegChips, TransitWalkDivider } from './transitDisplay'; const t = (key: string, params?: Record) => params ? `${key}:${Object.values(params).join(',')}` : key; @@ -22,6 +22,21 @@ function clipsToOneLine(el: HTMLElement): boolean { } describe('TransitItineraryInline (#3139)', () => { + it('FE-PLANNER-TRANSITDISPLAY-004: a long line name leaves room for both stops', () => { + const line = 'Skybus - Melbourne Airport - Melbourne City'; + const from = 'Skybus Coach Terminal/Spencer St'; + const to = 'Melbourne (Tullamarine) Airport'; + render(); + + const label = screen.getByText(line); + expect(label.parentElement?.style.maxInlineSize).toBe('40%'); + expect(label).toHaveClass('[overflow-wrap:anywhere]'); + expect(label).not.toHaveClass('truncate'); + expect(label).toHaveAttribute('title', line); + expect(screen.getByText(from)).toBeInTheDocument(); + expect(screen.getByText(to)).toBeInTheDocument(); + }); + it('FE-PLANNER-TRANSITDISPLAY-001: a ride shows both stop names in full', () => { render(); for (const name of ['Basingstoke', 'Reading']) { @@ -45,3 +60,15 @@ describe('TransitWalkDivider (#3139)', () => { expect(clipsToOneLine(text)).toBe(false); }); }); + +describe('TransitLegChips', () => { + it('FE-PLANNER-TRANSITDISPLAY-005: a long badge fits within the chip row', () => { + const line = 'Skybus Melbourne Airport Express'; + const { container } = render(); + + expect(container.firstElementChild).toHaveStyle({ minInlineSize: '0px', maxInlineSize: '100%' }); + const label = screen.getByText(line); + expect(label).toHaveClass('truncate'); + expect(label).toHaveAttribute('title', line); + }); +}); diff --git a/client/src/components/Planner/transitDisplay.tsx b/client/src/components/Planner/transitDisplay.tsx index 5ab296711..05ba9e647 100644 --- a/client/src/components/Planner/transitDisplay.tsx +++ b/client/src/components/Planner/transitDisplay.tsx @@ -22,6 +22,23 @@ export interface TransitLegDisplay { to?: { name?: string; time?: string | null; track?: string | null } } +/** Limit the line badge when it shares a row with stop or headsign text. */ +export function TransitLineBadge({ label, besideText = false, wrap = besideText, icon, className = '', style }: { + label?: string + besideText?: boolean + wrap?: boolean + icon?: React.ReactNode + className?: string + style?: React.CSSProperties +}) { + return ( + + {icon} + {label} + + ) +} + /** * A walk leg as a one-line centred divider — dashed rules left and right, @@ -77,14 +94,12 @@ export function TransitItineraryInline({ legs, t }: { {leg.from?.time || ''} {leg.to?.time && {leg.to.time}} - - {leg.line || leg.mode} - + }} />
{/* The folded-out itinerary is where a journey is read in full: stop names wrap (#3139). */}
@@ -185,7 +200,7 @@ export function TransitLegChips({ legs, transfers, size = 'sm', t }: { const walkIcon = size === 'sm' ? 10 : 12 const shown = legs.filter(l => l.mode !== 'WALK' || (l.duration || 0) >= 60) return ( - + {shown.map((leg, i) => ( {i > 0 && ›} @@ -195,15 +210,13 @@ export function TransitLegChips({ legs, transfers, size = 'sm', t }: { {Math.round((leg.duration || 0) / 60)} ) : ( - - {leg.line || leg.mode} - + }} /> )} ))} diff --git a/client/src/mobile/screens/trip/plan/MPlanTimelineRows.tsx b/client/src/mobile/screens/trip/plan/MPlanTimelineRows.tsx index bd319461f..60ae6f88b 100644 --- a/client/src/mobile/screens/trip/plan/MPlanTimelineRows.tsx +++ b/client/src/mobile/screens/trip/plan/MPlanTimelineRows.tsx @@ -13,7 +13,7 @@ import { formatTime, splitReservationDateTime } from '../../../../utils/formatte import { transportSubtitle, type TransitMeta, type TransportEntry } from './planTimelineModel' import { splitNoteTime } from '../lib/dayNotes' import type { DragRowProps } from './useMPlanDragReorder' -import type { TransitLegDisplay } from '../../../../components/Planner/transitDisplay' +import { TransitLineBadge, type TransitLegDisplay } from '../../../../components/Planner/transitDisplay' import type { Assignment, DayNote, Place, Reservation, RouteSegment, TranslationFn } from '../../../../types' import { formatScheduleMinutes } from '../../../../components/Plugins/PluginDaySchedule' import type { PluginDayScheduleItem } from '../../../../api/client' @@ -308,17 +308,17 @@ export function TransportRow({ res, dayId, chrome, reorder, drag, onOpen }: { // ── b2) Auto-transit row with collapsible legs ─────────────────────────────── -function LineBadge({ leg, className = '' }: { leg: TransitLegDisplay; className?: string }) { +function LineBadge({ leg, besideText = false, className = '' }: { leg: TransitLegDisplay; besideText?: boolean; className?: string }) { return ( - - {leg.line || leg.mode} - + /> ) } @@ -329,7 +329,7 @@ function TransitStrip({ legs }: { legs: TransitLegDisplay[] }) { return (
{shown.map((leg, i) => ( - + {i > 0 && ›} {leg.mode === 'WALK' ? ( @@ -387,7 +387,7 @@ function TransitLegRows({ legs, t }: { legs: TransitLegDisplay[]; t: Translation ) : (
- + {flowText([leg.from?.name, leg.to?.name].filter((n): n is string => !!n))} diff --git a/client/src/mobile/screens/trip/sheets/MTransportSheet.tsx b/client/src/mobile/screens/trip/sheets/MTransportSheet.tsx index 945a16a80..965188d62 100644 --- a/client/src/mobile/screens/trip/sheets/MTransportSheet.tsx +++ b/client/src/mobile/screens/trip/sheets/MTransportSheet.tsx @@ -11,6 +11,7 @@ import { getFlightLegs, getTrainLegs, seatLabel, seatsOfLegs, usesStationRoute, import { runsOnDay } from '../../../../utils/reservationRoutes' import { filesFor } from '../../../../utils/reservationFiles' import { bookingDayLabel, segmentCodeLabel } from '../../../../components/Planner/transportDetailModel' +import { TransitLineBadge } from '../../../../components/Planner/transitDisplay' import type { Reservation } from '../../../../types' import { useSearchParams } from 'react-router' import { isTransportReservationType } from '@trek/shared' @@ -311,15 +312,15 @@ export default function MTransportSheet({ planner, shell }: MTripSheetsProps) { {isWalk ? ( ) : ( - - {leg.line || leg.mode} - + /> )}