diff --git a/client/src/components/Planner/DayPlanSidebarTransportDetailModal.test.tsx b/client/src/components/Planner/DayPlanSidebarTransportDetailModal.test.tsx index afe4647ec..965a43bd0 100644 --- a/client/src/components/Planner/DayPlanSidebarTransportDetailModal.test.tsx +++ b/client/src/components/Planner/DayPlanSidebarTransportDetailModal.test.tsx @@ -1,4 +1,4 @@ -// FE-PLANNER-DPTRANSPORT-001 to FE-PLANNER-DPTRANSPORT-021 +// FE-PLANNER-DPTRANSPORT-001 to FE-PLANNER-DPTRANSPORT-024 import { render, screen, fireEvent, within } from '../../../tests/helpers/render' import userEvent from '@testing-library/user-event' import { resetAllStores, seedStore } from '../../../tests/helpers/store' @@ -329,4 +329,29 @@ describe('DayPlanSidebarTransportDetailModal', () => { await user.click(screen.getByRole('button', { name: 'Close' })) expect(setTransportDetail).toHaveBeenCalledWith(null) }) + + // #3122: a transport holding only times showed them without the day they fall on. + it('FE-PLANNER-DPTRANSPORT-022: a booking holding only times names the date of its linked day', () => { + seedStore(useTripStore, { days: [{ id: 4, trip_id: 1, day_number: 2, date: '2025-06-16' }] as never }) + const res = { ...flight(), day_id: 4, reservation_time: '09:15', reservation_end_time: '11:00', endpoints: [] } as Reservation + render() + expect(screen.getByText('09:15 → 11:00').parentElement).toHaveTextContent(/Mon, Jun 16/) + }) + + it('FE-PLANNER-DPTRANSPORT-023: an overnight booking names the arrival date too', () => { + const res = { ...flight(), reservation_time: '2025-06-15T22:30:00', reservation_end_time: '2025-06-16T06:05:00' } as Reservation + render() + expect(screen.getByText('22:30 → 06:05').parentElement).toHaveTextContent(/Sun, Jun 15 → Mon, Jun 16/) + }) + + it('FE-PLANNER-DPTRANSPORT-024: in a right-to-left UI the overnight days read in order', () => { + document.documentElement.dir = 'rtl' + try { + const res = { ...flight(), reservation_time: '2025-06-15T22:30:00', reservation_end_time: '2025-06-16T06:05:00' } as Reservation + render() + expect(screen.getByText('22:30 → 06:05').parentElement).toHaveTextContent('⁨Sun, Jun 15⁩ ← ⁨Mon, Jun 16⁩') + } finally { + document.documentElement.dir = '' + } + }) }) diff --git a/client/src/components/Planner/DayPlanSidebarTransportDetailModal.tsx b/client/src/components/Planner/DayPlanSidebarTransportDetailModal.tsx index 6c580622b..fcbad002a 100644 --- a/client/src/components/Planner/DayPlanSidebarTransportDetailModal.tsx +++ b/client/src/components/Planner/DayPlanSidebarTransportDetailModal.tsx @@ -14,7 +14,9 @@ import { BOX, Eyebrow, Field, fs, toneColor, toneOf } from './bookings/bookingPa import { filesFor } from '../../utils/reservationFiles' import { bookingDayLabel, segmentCodeLabel } from './transportDetailModel' import { TransitLegs, transitSummary } from './bookings/transitParts' -import type { Reservation } from '../../types' +import { bookingDates } from './bookings/bookingsModel' +import { flowText } from '../../utils/flowText' +import type { Day, Reservation } from '../../types' type Translate = (key: string, params?: Record) => string @@ -50,11 +52,12 @@ export function DayPlanSidebarTransportDetailModal({ transportDetail, ...rest }: function TransportDetailDialog({ res, setTransportDetail, onNavigateToFiles, onEdit, t, locale, timeFormat }: Omit & { res: Reservation }) { const titleId = useId() const allFiles = useTripStore(s => s.files) + const days = useTripStore(s => s.days) const close = () => setTransportDetail(null) const meta = parseReservationMetadata(res) const transit = transitSummary(meta) const files = filesFor(res, allFiles || []) - const when = whenOf(res, locale, timeFormat) + const when = whenOf(res, days, locale, timeFormat) const cells = detailCells(res, meta, t) const confirmed = res.status === 'confirmed' @@ -192,11 +195,18 @@ function detailCells(res: Reservation, meta: Record, t: Transla return cells } -/** The booking's day and its time or time range, each empty when the booking has none. */ -function whenOf(res: Reservation, locale: string, timeFormat: string): { day: string; time: string } { - const { date, time } = splitReservationDateTime(res.reservation_time) +/** + * The booking's calendar day (both, when it arrives on a later one) and its time or + * time range, each empty when the booking has none. A booking holding only times + * takes the date of the day it is linked to (#3122). + */ +function whenOf(res: Reservation, days: Day[], locale: string, timeFormat: string): { day: string; time: string } { + const { time } = splitReservationDateTime(res.reservation_time) const { time: endTime } = splitReservationDateTime(res.reservation_end_time) - const day = date ? bookingDayLabel(date, locale) : '' + const dates = bookingDates(res, days || []) + // An arrival date alone would read as the departure, so it only joins a start date. + const span = dates.start ? [dates.start, dates.end !== dates.start ? dates.end : null].filter((d): d is string => !!d) : [] + const day = span.length > 0 ? flowText(span.map(d => bookingDayLabel(d, locale))) : '' const start = time ? formatTime(time, locale, timeFormat) : '' const end = endTime ? formatTime(endTime, locale, timeFormat) : '' return { day, time: start && end ? `${start} → ${end}` : start } diff --git a/client/src/components/Planner/bookings/bookingFacts.ts b/client/src/components/Planner/bookings/bookingFacts.ts index b7698c715..78eb39f06 100644 --- a/client/src/components/Planner/bookings/bookingFacts.ts +++ b/client/src/components/Planner/bookings/bookingFacts.ts @@ -2,7 +2,7 @@ import type { Day, Reservation, ReservationEndpoint } from '../../../types' import { formatPriceText, formatTime, splitReservationDateTime } from '../../../utils/formatters' import { getFlightLegs, getTrainLegs, usesStationRoute } from '../../../utils/flightLegs' import { safeExternalHref } from '../../../utils/safeUrl' -import { daySpan, hotelStayTimes, parseMeta, type AssignmentLookupEntry } from './bookingsModel' +import { bookingDates, daySpan, hotelStayTimes, parseMeta, type AssignmentLookupEntry } from './bookingsModel' export interface FactsContext { t: (key: string, params?: Record) => string @@ -84,6 +84,7 @@ export function bookingFacts(r: Reservation, c: FactsContext): BookingFacts { const eps = (r.endpoints || []).slice().sort((a, b) => (a.sequence ?? 0) - (b.sequence ?? 0)) const from = eps.find(e => e.role === 'from') const to = eps.find(e => e.role === 'to') + const dates = bookingDates(r, c.days) const startTime = startDt.time || from?.local_time || null const endTime = endDt.time || to?.local_time || null // A stay backed by an accommodation says its times as check-in and check-out; @@ -124,8 +125,8 @@ export function bookingFacts(r: Reservation, c: FactsContext): BookingFacts { return { day, time, startTime, endTime, - startDate: startDt.date || from?.local_date || span.start?.date || null, - endDate: endDt.date || to?.local_date || span.end?.date || null, + startDate: dates.start, + endDate: dates.end, cells, endpoints: eps.length >= 2 ? eps : [], legCodes, place: r.location || r.place_name || null, accommodation: r.accommodation_name || null, diff --git a/client/src/components/Planner/bookings/bookingsModel.ts b/client/src/components/Planner/bookings/bookingsModel.ts index f0a75f595..616504d86 100644 --- a/client/src/components/Planner/bookings/bookingsModel.ts +++ b/client/src/components/Planner/bookings/bookingsModel.ts @@ -132,6 +132,23 @@ export function daySpan(r: Reservation, days: Day[]): DaySpan { return { start: byId(r.day_id), end: byId(r.end_day_id) } } +/** + * The calendar dates a booking starts and ends on, as "YYYY-MM-DD", or null where it + * knows none: its own date first, then the local date of its first or last stop, + * then the date of the day it is linked to. A day-linked transport often carries + * only times, so its day stands in. + */ +export function bookingDates(r: Reservation, days: Day[]): { start: string | null; end: string | null } { + const span = daySpan(r, days) + const eps = (r.endpoints || []).slice().sort((a, b) => (a.sequence ?? 0) - (b.sequence ?? 0)) + const from = eps.find(e => e.role === 'from') + const to = eps.find(e => e.role === 'to') + return { + start: splitReservationDateTime(r.reservation_time).date || from?.local_date || span.start?.date || null, + end: splitReservationDateTime(r.reservation_end_time).date || to?.local_date || span.end?.date || null, + } +} + /** * The moment a booking starts, as "YYYY-MM-DDTHH:MM" in its own local time, or null * without any date. A day-linked transport often carries no date in reservation_time, diff --git a/client/src/mobile/screens/trip/sheets/MTransportSheet.tsx b/client/src/mobile/screens/trip/sheets/MTransportSheet.tsx index e24237f2c..326449d15 100644 --- a/client/src/mobile/screens/trip/sheets/MTransportSheet.tsx +++ b/client/src/mobile/screens/trip/sheets/MTransportSheet.tsx @@ -16,7 +16,7 @@ import { useSearchParams } from 'react-router' import { isTransportReservationType } from '@trek/shared' import { useBookingLink } from '../../../../hooks/useBookingLink' import { bookingFacts, stayStats } from '../../../../components/Planner/bookings/bookingFacts' -import { parseMeta } from '../../../../components/Planner/bookings/bookingsModel' +import { bookingDates, parseMeta } from '../../../../components/Planner/bookings/bookingsModel' import { ActionCircle, Eyebrow, INNER_CLS, StatBox, TileHeader, displayTime } from './MTripSheetUi' import { CardFiles } from '../tabs/MReservationCardParts' import { downloadAttachment, openAttachment } from '../../../../components/Planner/bookings/openAttachment' @@ -131,9 +131,10 @@ export default function MTransportSheet({ planner, shell }: MTripSheetsProps) { const canEdit = liveRes != null && (isTransportReservationType(liveRes.type) ? canEditDays : canEditBookings) const ResIcon = RES_ICONS[res.type as keyof typeof RES_ICONS] || RES_ICONS.other - const from = (res.endpoints || []).find(e => e.role === 'from') - const to = (res.endpoints || []).find(e => e.role === 'to') - const { date, time: startTime } = splitReservationDateTime(res.reservation_time) + const endpoints = res.endpoints || [] + const from = endpoints.find(e => e.role === 'from') + const to = endpoints.find(e => e.role === 'to') + const { time: startTime } = splitReservationDateTime(res.reservation_time) const { time: endTime } = splitReservationDateTime(res.reservation_end_time) const bookingDepTime = from?.local_time || startTime const bookingArrTime = to?.local_time || endTime @@ -151,6 +152,12 @@ export default function MTransportSheet({ planner, shell }: MTripSheetsProps) { const arrTime = leg ? leg.arr_time || '' : bookingArrTime const depLabel = (leg ? leg.from : from?.name) || t('reservations.time') const arrLabel = (leg ? leg.to : to?.name) || t('reservations.time') + // The calendar date each time falls on (#3122): a time alone cannot be placed + // when the sheet is opened from a compact list that shows nothing else. + const legDate = (dayId?: number | null) => (dayId != null ? planner.days.find(d => d.id === dayId)?.date : null) || null + const dates = leg ? { start: legDate(leg.dep_day_id), end: legDate(leg.arr_day_id) } : bookingDates(res, planner.days) + const depDate = dates.start ? bookingDayLabel(dates.start, locale) : null + const arrDate = dates.end ? bookingDayLabel(dates.end, locale) : null const subParts: string[] = [] const airline = leg ? legDetail.airline : meta.airline @@ -161,7 +168,6 @@ export default function MTransportSheet({ planner, shell }: MTripSheetsProps) { if (trainNumber) subParts.push(trainNumber) if (leg && (leg.from || leg.to)) subParts.push(flowText([leg.from, leg.to].filter((n): n is string => !!n))) else if (from?.name && to?.name) subParts.push(flowText([from.name, to.name])) - else if (date) subParts.push(bookingDayLabel(date, locale)) // A flight's legs carry no seat or platform of their own, so those stay the booking's. const seat = leg && !isFlight ? legDetail.seat : meta.seat @@ -170,6 +176,11 @@ export default function MTransportSheet({ planner, shell }: MTripSheetsProps) { // Opened from one leg's row, only that leg's live card; from the booking, every followed leg. const shownLive = leg ? liveLegs.filter(l => l.leg_index === payload.legIndex) : liveLegs + const showTimes = shownLive.length === 0 + // A shown time box carries its own date. Without one (no time entered yet, or the + // live card in its place) the subline names the day, route and airline or not. + const datedTime = showTimes && ((depTime && depDate) || (arrTime && arrDate)) + if (depDate && !datedTime) subParts.push(depDate) const resFiles = filesFor(res, planner.files || []) @@ -263,13 +274,13 @@ export default function MTransportSheet({ planner, shell }: MTripSheetsProps) { ))} {/* ── Times / seat stats (the live card already shows the times) ── */} - {hotelStats.length === 0 && ((shownLive.length === 0 && (depTime || arrTime)) || seat || platform) && ( + {hotelStats.length === 0 && ((showTimes && (depTime || arrTime)) || seat || platform) && (
- {shownLive.length === 0 && depTime && ( - + {showTimes && depTime && ( + )} - {shownLive.length === 0 && arrTime && ( - + {showTimes && arrTime && ( + )} {platform && } {seat && } diff --git a/client/src/mobile/screens/trip/sheets/MTripSheetUi.tsx b/client/src/mobile/screens/trip/sheets/MTripSheetUi.tsx index c213ef202..65338e2bd 100644 --- a/client/src/mobile/screens/trip/sheets/MTripSheetUi.tsx +++ b/client/src/mobile/screens/trip/sheets/MTripSheetUi.tsx @@ -121,6 +121,8 @@ export function TileHeader({ icon, title, sub, subWrap = false, onClose, closeLa interface StatBoxProps { value: ReactNode label: ReactNode + /** A line above the value, such as the calendar date a time falls on. */ + caption?: ReactNode blurred?: boolean onClick?: () => void /** Colours the label, so a check-in or check-out time carries its own state. */ @@ -133,10 +135,11 @@ const LABEL_TONE: Record, string> = { } /** Small stat box (check-in / times / code): value 700 tabular over a faint Geist label. */ -export function StatBox({ value, label, blurred = false, onClick, labelTone }: StatBoxProps) { +export function StatBox({ value, label, caption, blurred = false, onClick, labelTone }: StatBoxProps) { const box = 'min-w-0 flex-1 rounded-[10px] bg-[color:var(--m-ic)] px-[9px] py-[7px] text-center' const inner = ( <> + {caption &&
{caption}
}
diff --git a/client/tests/unit/mobile/trip/MTransportSheet.test.tsx b/client/tests/unit/mobile/trip/MTransportSheet.test.tsx index a57a9452f..12ef4f3a9 100644 --- a/client/tests/unit/mobile/trip/MTransportSheet.test.tsx +++ b/client/tests/unit/mobile/trip/MTransportSheet.test.tsx @@ -9,7 +9,7 @@ import { buildPlanner, buildShell } from '../../../helpers/mobileTrip' import { resetAllStores, seedStore } from '../../../helpers/store' import { fireEvent, render, screen } from '../../../helpers/render' -// FE-MOB-TRSH-001 to FE-MOB-TRSH-036 +// FE-MOB-TRSH-001 to FE-MOB-TRSH-044 vi.mock('../../../../src/utils/fileDownload', () => ({ openFile: vi.fn(() => Promise.resolve()), @@ -504,4 +504,108 @@ describe('MTransportSheet', () => { expect(screen.getByText('10:20')).toBeInTheDocument() expect(screen.getByText('06:45')).toBeInTheDocument() }) + // #3122: opened from the compact Transports list, the sheet showed the times + // but not the day they fall on. + describe('calendar dates beside the times (#3122)', () => { + const DAYS = [ + { id: 3, trip_id: 1, day_number: 1, date: '2026-05-01' }, + { id: 4, trip_id: 1, day_number: 2, date: '2026-05-02' }, + ] + + it('FE-MOB-TRSH-037: a flight with a route shows the departure and the arrival date beside their times', () => { + render() + const dep = screen.getByText('10:20').parentElement as HTMLElement + const arr = screen.getByText('06:45').parentElement as HTMLElement + expect(dep).toHaveTextContent('Fri, May 1') + expect(arr).toHaveTextContent('Sat, May 2') + }) + + it('FE-MOB-TRSH-038: a transport holding only times reads its date off the linked day, not "Day 1"', () => { + const res = { + ...FLIGHT, type: 'ferry', title: 'Ferry to Naxos', day_id: 4, end_day_id: null, + reservation_time: '08:15', reservation_end_time: '13:40', metadata: null, + endpoints: [ + { id: 1, reservation_id: 7, role: 'from', sequence: 0, name: 'Piraeus', lat: 37.94, lng: 23.64, local_date: null, local_time: null }, + { id: 2, reservation_id: 7, role: 'to', sequence: 1, name: 'Naxos', lat: 37.1, lng: 25.37, local_date: null, local_time: null }, + ], + } as unknown as Reservation + render() + expect(screen.getByText('08:15').parentElement).toHaveTextContent('Sat, May 2') + expect(screen.queryByText(/Day 1/)).not.toBeInTheDocument() + }) + + it("FE-MOB-TRSH-039: a leg opened from its row shows that leg's own dates", () => { + const res = { + ...FLIGHT, type: 'train', title: 'Night train', endpoints: [], reservation_time: null, reservation_end_time: null, + metadata: JSON.stringify({ + legs: [ + { from: 'Vienna', to: 'Munich', dep_day_id: 3, dep_time: '22:10', arr_day_id: 3, arr_time: '23:50' }, + { from: 'Munich', to: 'Paris', dep_day_id: 3, dep_time: '23:58', arr_day_id: 4, arr_time: '09:30' }, + ], + }), + } as unknown as Reservation + render() + expect(screen.getByText('23:58').parentElement).toHaveTextContent('Fri, May 1') + expect(screen.getByText('09:30').parentElement).toHaveTextContent('Sat, May 2') + }) + + it('FE-MOB-TRSH-040: names a date once, beside the time, and not again in the subline', () => { + const res = { ...FLIGHT, endpoints: [], metadata: null } as unknown as Reservation + render() + expect(screen.getAllByText('Fri, May 1')).toHaveLength(1) + }) + + it('FE-MOB-TRSH-041: a flight with an airline but no route and no time names its date in the subline', () => { + const res = { ...FLIGHT, endpoints: [], reservation_time: '2026-05-01', reservation_end_time: null } as unknown as Reservation + render() + expect(screen.getByText('Lufthansa · LH 716 · Fri, May 1')).toBeInTheDocument() + }) + + it('FE-MOB-TRSH-042: a transport with a route but no times yet names the date of its linked day', () => { + const res = { + ...FLIGHT, type: 'ferry', title: 'Ferry to Naxos', day_id: 4, end_day_id: null, + reservation_time: null, reservation_end_time: null, metadata: null, + endpoints: [ + { id: 1, reservation_id: 7, role: 'from', sequence: 0, name: 'Piraeus', lat: 37.94, lng: 23.64, local_date: null, local_time: null }, + { id: 2, reservation_id: 7, role: 'to', sequence: 1, name: 'Naxos', lat: 37.1, lng: 25.37, local_date: null, local_time: null }, + ], + } as unknown as Reservation + render() + expect(screen.getByText('Piraeus → Naxos · Sat, May 2')).toBeInTheDocument() + }) + + it('FE-MOB-TRSH-043: with the live card in place of the time boxes, the subline names the date', () => { + const now = Date.now() + const soon: FlightLiveLeg = { + reservation_id: 7, leg_index: 0, callsign: 'DLH716', flight_number: 'LH 716', service_date: '2026-05-01', + origin: { code: 'FRA', name: 'Frankfurt', lat: 50.03, lng: 8.57, timezone: 'Europe/Berlin' }, + destination: { code: 'HND', name: 'Tokyo Haneda', lat: 35.55, lng: 139.78, timezone: 'Asia/Tokyo' }, + phase: 'scheduled', scheduled_departure: new Date(now + 3_600_000).toISOString(), scheduled_arrival: new Date(now + 7_200_000).toISOString(), + departed_at: null, landed_at: null, estimated_arrival: null, departure_delay_min: null, arrival_delay_min: null, + progress: null, distance_total_km: null, distance_remaining_km: null, position: null, aircraft: null, + last_seen_at: null, fetched_at: new Date(now).toISOString(), stale: false, source: 'adsb.lol', + } + useFlightLiveStore.setState({ trips: { 1: { enabled: true, attribution: null, legs: { [legKey(7, 0)]: soon } } } }) + render() + expect(screen.queryByText('10:20')).not.toBeInTheDocument() + expect(screen.getByText(/Frankfurt \(FRA\) → Tokyo \(HND\) · Fri, May 1/)).toBeInTheDocument() + }) + + // Each box stands on its own in the row, so a same-day trip keeps the date on both + // rather than leaving one box a line shorter than the other. + it('FE-MOB-TRSH-044: a same-day trip shows its date on both time boxes', () => { + const res = { + ...FLIGHT, type: 'train', title: 'ICE to Munich', metadata: null, + reservation_time: '2026-05-01T10:20', reservation_end_time: '2026-05-01T12:05', + endpoints: [ + { id: 1, reservation_id: 7, role: 'from', sequence: 0, name: 'Frankfurt Hbf', lat: 50.1, lng: 8.66, local_date: '2026-05-01', local_time: '10:20' }, + { id: 2, reservation_id: 7, role: 'to', sequence: 1, name: 'München Hbf', lat: 48.14, lng: 11.56, local_date: '2026-05-01', local_time: '12:05' }, + ], + } as unknown as Reservation + render() + expect(screen.getByText('10:20').parentElement).toHaveTextContent('Fri, May 1') + expect(screen.getByText('12:05').parentElement).toHaveTextContent('Fri, May 1') + expect(screen.getAllByText('Fri, May 1')).toHaveLength(2) + }) + }) })