diff --git a/client/scripts/size-baseline.json b/client/scripts/size-baseline.json index 2e3d01696..060d9ddef 100644 --- a/client/scripts/size-baseline.json +++ b/client/scripts/size-baseline.json @@ -10,7 +10,7 @@ "src/components/Map/MapViewGL.tsx": 2116, "src/components/Planner/DayDetailPanel.test.tsx": 2333, "src/components/Planner/DayPlanSidebar.test.tsx": 5349, - "src/components/Planner/DayPlanSidebar.tsx": 2910, + "src/components/Planner/DayPlanSidebar.tsx": 2908, "src/components/Planner/PlaceFormModal.test.tsx": 2836, "src/components/Planner/PlaceInspector.tsx": 1128, "src/components/Studio/TravelElements.tsx": 1559, diff --git a/client/src/components/Planner/DayPlanSidebar.tours.test.tsx b/client/src/components/Planner/DayPlanSidebar.tours.test.tsx index 042028f66..71337cac2 100644 --- a/client/src/components/Planner/DayPlanSidebar.tours.test.tsx +++ b/client/src/components/Planner/DayPlanSidebar.tours.test.tsx @@ -585,3 +585,87 @@ describe('DayPlanSidebar, public transit between two city walks (CW-08)', () => expect(screen.getByTestId('tour-day-overrun')).toHaveTextContent('Ends at 14:00, after Harbour starts at 13:00'); }); }); + +// The walk from a train's arrival to the night's hotel: no stop is at either end, so +// there is no mode to change, and the desktop left it inert. The transit search is +// what can be planned for it, as for every other leg. +describe('DayPlanSidebar, public transit from a booking arrival to the hotel', () => { + it('FE-PLANNER-DAYPLAN-171f: the walk from a train arrival to the hotel, which no stop owns, offers public transport', async () => { + const user = userEvent.setup(); + const onPlanTransitLeg = vi.fn(); + const days = [ + buildDay({ id: 10, date: '2025-06-01', title: 'Day 1' }), + buildDay({ id: 11, date: '2025-06-02', title: 'Day 2' }), + buildDay({ id: 12, date: '2025-06-03', title: 'Day 3' }), + ]; + const accommodations = [ + { + id: 1, + trip_id: 1, + start_day_id: 10, + end_day_id: 12, + place_lat: 47.5, + place_lng: 19.05, + place_name: 'Basilica apARTment', + }, + ]; + const train = buildReservation({ + id: 430, + type: 'train', + title: 'Wien => Budapest', + day_id: 11, + end_day_id: 11, + day_plan_position: 5, + reservation_time: '2025-06-02T16:42:00', + reservation_end_time: '2025-06-02T19:29:00', + endpoints: [ + { + role: 'from', + sequence: 0, + name: 'Wien Hbf', + code: null, + lat: 48.18, + lng: 16.37, + timezone: null, + local_date: null, + local_time: null, + }, + { + role: 'to', + sequence: 1, + name: 'Budapest Keleti', + code: null, + lat: 47.5, + lng: 19.08, + timezone: null, + local_date: null, + local_time: null, + }, + ], + }); + const albertina = buildPlace({ id: 1, name: 'Albertina', place_time: '12:00', lat: 48.2, lng: 16.37 }); + render( + + ); + await user.click(await screen.findByLabelText('Public transit')); + expect(contextMenu().queryByRole('button', { name: 'Driving' })).not.toBeInTheDocument(); + await user.click(contextMenu().getByRole('button', { name: 'Public transit' })); + expect(onPlanTransitLeg).toHaveBeenCalledWith( + expect.objectContaining({ + dayId: 11, + from: expect.objectContaining({ lat: 47.5, lng: 19.08 }), + to: { name: 'Basilica apARTment', lat: 47.5, lng: 19.05 }, + }) + ); + }); +}); diff --git a/client/src/components/Planner/DayPlanSidebar.tsx b/client/src/components/Planner/DayPlanSidebar.tsx index 1afa6b61d..38774877e 100644 --- a/client/src/components/Planner/DayPlanSidebar.tsx +++ b/client/src/components/Planner/DayPlanSidebar.tsx @@ -69,7 +69,7 @@ import { findTodayDayId } from './today' import { markdownLinkComponents } from '../shared/markdownLink' import { RouteConnector, HotelRouteConnector } from './DayPlanSidebarRouteConnector' import { resolveLegMode } from './legMode' -import { useLegModeActions } from './useLegModeActions' +import { transitOnlyMenuItems, useLegModeActions } from './useLegModeActions' import { dayExportStops, fillAroundLocked } from './dayRoute' import { projectDayItinerary, projectedById, type TourStageStops } from '../Map/dayTourProjection' import type { DayRoutePoint } from '../Map/dayRoutePlan' @@ -1413,6 +1413,27 @@ const DayPlanSidebar = React.memo(function DayPlanSidebar(props: DayPlanSidebarP } as unknown as React.MouseEvent) } + // A hotel bookend leg opens the mode menu of the stop that owns it, the first stop's + // incoming mode at the top and the last stop's outgoing mode at the bottom. One no + // stop owns, a booking's arrival to the hotel, can only have transit planned. + const hotelLegRow = (dayId: number, leg: { seg: RouteSegment; name: string; targetId?: number }, placement: 'top' | 'bottom') => { + const connector = + const targetId = leg.targetId + const planTransit = targetId == null ? transitLegPlanner(dayId, leg.seg) : undefined + const open = targetId != null + ? (e: React.MouseEvent) => (placement === 'top' ? openIncomingLegModeMenu : openLegModeMenu)(e, targetId, dayId, leg.seg) + : planTransit && ((e: React.MouseEvent) => ctxMenu.open(e, transitOnlyMenuItems(planTransit, t))) + if (!canEditDays || !open) return connector + const label = targetId != null ? t('dayplan.transportMode.change') : t('transit.title') + return ( + +
openLegMenuByKey(e, open)} style={{ cursor: 'pointer' }} aria-label={label}> + {connector} +
+
+ ) + } + return ( // Sized as a flex child as well as by height: the desktop panel puts the Days / Road // trip switch above this, and at height 100% alone the list ran the switch's height @@ -1734,17 +1755,7 @@ const DayPlanSidebar = React.memo(function DayPlanSidebar(props: DayPlanSidebarP dropAfterLastItem(day.id, { assignmentId, noteId }) }} > - {hotelLegs[day.id]?.top && (() => { - const targetId = hotelLegs[day.id]?.top?.targetId - const connector = - return canEditDays && targetId != null ? ( - -
openIncomingLegModeMenu(e, targetId, day.id, hotelLegs[day.id]!.top!.seg)} onKeyDown={e => openLegMenuByKey(e, m => openIncomingLegModeMenu(m, targetId, day.id, hotelLegs[day.id]!.top!.seg))} style={{ cursor: 'pointer' }} aria-label={t('dayplan.transportMode.change')}> - {connector} -
-
- ) : connector - })()} + {hotelLegs[day.id]?.top && hotelLegRow(day.id, hotelLegs[day.id]!.top!, 'top')} {daySchedule.byPosition[day.id]?.start.map(si => )} {visibleCount === 0 && !dayNoteUi ? (
)} - {hotelLegs[day.id]?.bottom && (() => { - const targetId = hotelLegs[day.id]?.bottom?.targetId - const connector = - return canEditDays && targetId != null ? ( - -
openLegModeMenu(e, targetId, day.id, hotelLegs[day.id]!.bottom!.seg)} onKeyDown={e => openLegMenuByKey(e, m => openLegModeMenu(m, targetId, day.id, hotelLegs[day.id]!.bottom!.seg))} style={{ cursor: 'pointer' }} aria-label={t('dayplan.transportMode.change')}> - {connector} -
-
- ) : connector - })()} + {hotelLegs[day.id]?.bottom && hotelLegRow(day.id, hotelLegs[day.id]!.bottom!, 'bottom')} {/* The assistant's waiting changes, then the drop zone at the list end */}
void, t: Translate): LegModeMenuItem[] { + return [{ label: t('transit.title'), icon: TramFront, onClick: planTransit }]; +} + export interface LegModeDeps { tripId: number; toast: { error: (message: string) => void }; diff --git a/client/src/mobile/screens/trip/plan/MPlanTimeline.tsx b/client/src/mobile/screens/trip/plan/MPlanTimeline.tsx index 66e658159..a582b0a41 100644 --- a/client/src/mobile/screens/trip/plan/MPlanTimeline.tsx +++ b/client/src/mobile/screens/trip/plan/MPlanTimeline.tsx @@ -4,7 +4,7 @@ import type { LucideIcon } from 'lucide-react' import { useContextMenu, ContextMenu } from '../../../../components/shared/ContextMenu' import MarkdownText from '../../../../components/shared/MarkdownText' import { fmtTransitDuration } from '../../../../components/Planner/transitDisplay' -import { legModeMenuItems } from '../../../../components/Planner/useLegModeActions' +import { legModeMenuItems, transitOnlyMenuItems } from '../../../../components/Planner/useLegModeActions' import { formatTime } from '../../../../utils/formatters' import { useMPlanTimeline, type MPlanTimelineController } from './useMPlanTimeline' import { cityPillsForDay } from './planTimelineModel' @@ -114,16 +114,24 @@ function PlanDayPage({ planner, shell, dayId: pageDayId, active, editing, legMen const { t, trip, can } = planner const canEdit = can('day_edit', trip) const canEditPlaces = can('place_edit', trip) - const openLegMenu = (e: MouseEvent, assignmentId: number, seg: RouteSegment) => { - // Public transit sits under the road profiles, as on the desktop (#2398). + // The tap on a leg while editing: the mode menu of the stop that owns it, its + // outgoing mode for a leg it leaves, its incoming mode for one it enters from a + // booking or the morning hotel, as on the desktop. Public transit sits under the + // road profiles (#2398). A leg no stop owns, a booking's arrival to the hotel, can + // only have transit planned, and stays inert where that is not available. + const legTap = (seg: RouteSegment, owner: { id: number; incoming: boolean } | null): ((e: MouseEvent) => void) | undefined => { + if (!editing) return undefined const transitLeg = tl.transitLegFor(seg) - legMenu.open(e, legModeMenuItems( - tl.routeModeOptions, - mode => tl.setLegMode(assignmentId, mode), - t, - transitLeg ? () => tl.planTransitLeg(transitLeg, assignmentId) : undefined, - )) + const planTransit = transitLeg + ? () => tl.planTransitLeg(transitLeg, owner && !owner.incoming ? owner.id : undefined) + : undefined + if (owner) { + const pick = (mode: string | null) => (owner.incoming ? tl.setIncomingLegMode(owner.id, mode) : tl.setLegMode(owner.id, mode)) + return e => legMenu.open(e, legModeMenuItems(tl.routeModeOptions, pick, t, planTransit)) + } + return planTransit ? e => legMenu.open(e, transitOnlyMenuItems(planTransit, t)) : undefined } + const owned = (id: number | undefined, incoming: boolean) => (id != null ? { id, incoming } : null) const day = tl.day const dayId = day?.id // A stay chip shows the stay before anything can be changed, as on the @@ -249,7 +257,12 @@ function PlanDayPage({ planner, shell, dayId: pageDayId, active, editing, legMen )} {tl.hotelLegs.top && ( - + )} {dayId != null && daySchedule.byPosition[dayId]?.start.map(si => )} @@ -321,13 +334,24 @@ function PlanDayPage({ planner, shell, dayId: pageDayId, active, editing, legMen /> ) case 'conn': - return openLegMenu(e, row.assignmentId!, row.seg) : undefined} /> + return ( + + ) } })} {dayId != null && daySchedule.byPosition[dayId]?.end.map(si => )} {tl.hotelLegs.bottom && ( - + )} {tl.rows.length === 0 && !editing && ( diff --git a/client/src/mobile/screens/trip/plan/MPlanTimelineRows.tsx b/client/src/mobile/screens/trip/plan/MPlanTimelineRows.tsx index 203f93805..981e2befb 100644 --- a/client/src/mobile/screens/trip/plan/MPlanTimelineRows.tsx +++ b/client/src/mobile/screens/trip/plan/MPlanTimelineRows.tsx @@ -534,18 +534,19 @@ export function PlanScheduleRow({ item }: { item: PluginDayScheduleItem }) { // ── b4b) Accommodation bookend leg (hotel → first stop / last stop → hotel) ── -export function HotelConnRow({ seg, name, placement }: { +export function HotelConnRow({ seg, name, placement, onTap }: { seg: RouteSegment name: string placement: 'top' | 'bottom' + onTap?: (e: MouseEvent) => void }) { // Same line as the connectors between two stops, so a bookend leg routed with a - // plugin profile or set to walking reads the same as the rest of the day (#1281). - const travel = ( -
- -
- ) + // plugin profile or set to walking reads the same as the rest of the day (#1281), + // and taps the same way. Only the line is the button, the stay's name stays text. + const cls = 'flex w-full items-center gap-2 py-px text-[color:var(--m-conn)]' + const travel = onTap + ? + :
const hotel = (
diff --git a/client/src/mobile/screens/trip/plan/planTimelineModel.ts b/client/src/mobile/screens/trip/plan/planTimelineModel.ts index 458c82bfb..d5eced2ee 100644 --- a/client/src/mobile/screens/trip/plan/planTimelineModel.ts +++ b/client/src/mobile/screens/trip/plan/planTimelineModel.ts @@ -31,7 +31,12 @@ export type PlanRow = | { key: string; kind: 'transport'; item: MergedItem; res: TransportEntry } | { key: string; kind: 'transit'; item: MergedItem; res: TransportEntry; transit: TransitMeta } | { key: string; kind: 'note'; item: MergedItem; note: DayNote } - | { key: string; kind: 'conn'; seg: RouteSegment; assignmentId?: number } + /** + * A leg between two rows. `assignmentId` is the stop it leaves, whose outgoing mode it + * uses; a leg that leaves a booking uses the incoming mode of the stop it enters, + * `incomingAssignmentId`, as on the desktop day plan. + */ + | { key: string; kind: 'conn'; seg: RouteSegment; assignmentId?: number; incomingAssignmentId?: number } export function parseReservationMeta(res: Reservation): Record { let meta: unknown = res.metadata @@ -56,6 +61,26 @@ export function transportSubtitle(res: TransportEntry, t: TranslationFn): string const sameCoord = (a: [number, number], b: [number, number]): boolean => Math.abs(a[0] - b[0]) < 1e-9 && Math.abs(a[1] - b[1]) < 1e-9 +/** + * The stops whose mode the two hotel bookend legs use: the first waypoint of the + * day for the leg from the hotel (its incoming mode), the last for the leg back + * (its outgoing mode). Absent where that end of the day is a booking, which no + * stop owns. + */ +export interface BookendOwners { + top?: number + bottom?: number +} + +type PlanRowsOptions = { + merged: MergedItem[] + reservations: Reservation[] + routeSegments: RouteSegment[] + dayId: number + toursEnabled?: boolean + places?: Place[] +} + /** * Map the day's merged items to render rows and slot a travel-time connector * under the row each drawn leg belongs to. Segments are matched by their exact @@ -64,14 +89,12 @@ const sameCoord = (a: [number, number], b: [number, number]): boolean => * front: they belong to the day's edges, and a stop planned on the hotel's own * spot would otherwise pair with them (#2501). */ -export function buildPlanRows(opts: { - merged: MergedItem[] - reservations: Reservation[] - routeSegments: RouteSegment[] - dayId: number - toursEnabled?: boolean - places?: Place[] -}): PlanRow[] { +export function buildPlanRows(opts: PlanRowsOptions): PlanRow[] { + return buildPlanTimeline(opts).rows +} + +/** buildPlanRows, plus the stops that own the day's two hotel bookend legs. */ +export function buildPlanTimeline(opts: PlanRowsOptions): { rows: PlanRow[]; bookendOwners: BookendOwners } { const { merged, reservations, routeSegments, dayId } = opts const pool = routeSegments.filter(s => !s.hotelBookend) const projected = new Map(projectDayItinerary( @@ -133,15 +156,24 @@ export function buildPlanRows(opts: { // A booking whose station is the stop itself leaves a leg that goes nowhere: the // transit planner saves a journey between two of the day's places at their own // coordinates. That is no walk and no drive, so it gets no connector. + // + // A leg out of a booking has no stop to keep its mode, so it uses the incoming mode + // of the stop it enters, `toAssignmentId`, the one the route calc routed it in. type Origin = { at: [number, number]; row: number; assignmentId?: number } - const legs = new Map() - const connect = (origin: Origin | null, to: [number, number], toBooking = false) => { + const legs = new Map() + const connect = (origin: Origin | null, to: [number, number], toBooking = false, toAssignmentId?: number) => { if (!origin) return const seg = takeSegment(origin.at, to) const fromBooking = origin.assignmentId == null if (!seg || ((toBooking || fromBooking) && sameCoord(origin.at, to))) return - legs.set(origin.row, { seg, assignmentId: origin.assignmentId }) + legs.set(origin.row, { + seg, + assignmentId: origin.assignmentId, + ...(fromBooking && toAssignmentId != null ? { incomingAssignmentId: toAssignmentId } : {}), + }) } + // The day's first waypoint, a stop or a booking's departure: the hotel leg runs into it. + let first: { assignmentId?: number } | null = null let prev: Origin | null = null for (let i = 0; i < base.length; i++) { const row = base[i] @@ -151,7 +183,10 @@ export function buildPlanRows(opts: { if (row.assignment.route_excluded) continue const itineraryItem = projected.get(row.assignment.id) if (itineraryItem?.kind === 'tour') { - if (itineraryItem.start) connect(prev, [itineraryItem.start.lat, itineraryItem.start.lng]) + if (itineraryItem.start) { + first ??= { assignmentId: row.assignment.id } + connect(prev, [itineraryItem.start.lat, itineraryItem.start.lng], false, row.assignment.id) + } prev = itineraryItem.end ? { at: [itineraryItem.end.lat, itineraryItem.end.lng], row: i, assignmentId: row.assignment.id } : null @@ -159,7 +194,8 @@ export function buildPlanRows(opts: { } if (place?.lat == null || place?.lng == null) continue const at: [number, number] = [place.lat, place.lng] - connect(prev, at) + first ??= { assignmentId: row.assignment.id } + connect(prev, at, false, row.assignment.id) // The leg's mode is stored on its ORIGIN place assignment (#1281), so carry // that id for the tap-to-change menu. prev = { at, row: i, assignmentId: row.assignment.id } @@ -171,16 +207,23 @@ export function buildPlanRows(opts: { if (prev) prev = { ...prev, row: i } continue } + if (from) first ??= {} // Only out of a stop: two bookings back to back are no drive (#1394). if (from && prev?.assignmentId != null) connect(prev, [from.lat, from.lng], true) prev = to ? { at: [to.lat, to.lng], row: i } : null } } - return base.flatMap((row, i): PlanRow[] => { + const rows = base.flatMap((row, i): PlanRow[] => { const leg = legs.get(i) - return leg ? [row, { key: `conn-${row.key}`, kind: 'conn', seg: leg.seg, assignmentId: leg.assignmentId }] : [row] + return leg ? [row, { key: `conn-${row.key}`, kind: 'conn', ...leg }] : [row] }) + // The last waypoint is where the day ends: a stop, or a booking's arrival (no owner). + const bookendOwners: BookendOwners = { + ...(first?.assignmentId != null ? { top: first.assignmentId } : {}), + ...(prev?.assignmentId != null ? { bottom: prev.assignmentId } : {}), + } + return { rows, bookendOwners } } export interface HotelChip { @@ -218,7 +261,12 @@ export function hotelChipsForDay(day: Day, days: Day[], accommodations: Accommod return chips.filter(c => c.name).sort((a, b) => rank[a.variant] - rank[b.variant]) } -export interface HotelLeg { seg: RouteSegment; name: string } +export interface HotelLeg { + seg: RouteSegment + name: string + /** The stop whose mode the leg uses (see BookendOwners); absent when a booking ends it. */ + assignmentId?: number +} export interface HotelLegs { top: HotelLeg | null; bottom: HotelLeg | null } /** @@ -242,17 +290,19 @@ export function hotelLegsForDay( days: Day[], accommodations: Accommodation[], routeSegments: RouteSegment[], + owners: BookendOwners = {}, ): HotelLegs { const { morning, evening } = getDayBookendHotels(day, days, accommodations) - const legOf = (a: Accommodation | undefined, bookend: 'morning' | 'evening'): HotelLeg | null => { + const legOf = (a: Accommodation | undefined, bookend: 'morning' | 'evening', owner?: number): HotelLeg | null => { if (!a || a.place_lat == null || a.place_lng == null) return null const at: [number, number] = [a.place_lat, a.place_lng] const seg = routeSegments.find(s => s.hotelBookend === bookend && sameCoord(bookend === 'morning' ? s.from : s.to, at)) - return seg ? { seg, name: accommodationName(a) } : null + if (!seg) return null + return { seg, name: accommodationName(a), ...(owner != null ? { assignmentId: owner } : {}) } } // A moving day without stops is one drive from one hotel to the next (#1297). The // calc tags it as the morning leg, so it shows once, at the top (#2476). - return { top: legOf(morning, 'morning'), bottom: legOf(evening, 'evening') } + return { top: legOf(morning, 'morning', owners.top), bottom: legOf(evening, 'evening', owners.bottom) } } /** The day headline as city pills — a "Tokyo → Kyoto" title becomes two pills with an arrow. */ diff --git a/client/src/mobile/screens/trip/plan/useMPlanTimeline.ts b/client/src/mobile/screens/trip/plan/useMPlanTimeline.ts index 37c8f4ca0..983491c89 100644 --- a/client/src/mobile/screens/trip/plan/useMPlanTimeline.ts +++ b/client/src/mobile/screens/trip/plan/useMPlanTimeline.ts @@ -14,8 +14,8 @@ import type { PlannedTransitLeg, TransitLeg } from '../../../../components/Plann import { useTransitLegPlanner } from '../../../../components/Planner/useTransitLegPlanner' import { dayItemOverrun } from '../../../../components/Tours/tourDayTime' import { - buildPlanRows, breaksChronology, findUpNext, hotelChipsForDay, hotelLegsForDay, itemHasTime, - type HotelLegs, type PlanRow, type TransportEntry, + buildPlanTimeline, breaksChronology, findUpNext, hotelChipsForDay, hotelLegsForDay, itemHasTime, + type BookendOwners, type HotelLegs, type PlanRow, type TransportEntry, } from './planTimelineModel' import type { TripPlanner } from '../MTripShell' import type { WeatherResult } from '@trek/shared' @@ -99,16 +99,17 @@ export function useMPlanTimeline(planner: TripPlanner, forDayId?: number | null) tripAccommodations, ) - const rows = useMemo(() => { - if (!day) return [] - return buildPlanRows({ merged, reservations, routeSegments: connSegments, dayId: day.id, toursEnabled: planner.toursEnabled, places: planner.places }) + const timeline = useMemo<{ rows: PlanRow[]; bookendOwners: BookendOwners }>(() => { + if (!day) return { rows: [], bookendOwners: {} } + return buildPlanTimeline({ merged, reservations, routeSegments: connSegments, dayId: day.id, toursEnabled: planner.toursEnabled, places: planner.places }) }, [day, merged, reservations, connSegments, planner.toursEnabled, planner.places]) + const rows = timeline.rows // Accommodation bookend legs (hotel → first stop, last stop → hotel). The // segments already sit in connSegments; hotelLegsForDay picks the two out. const hotelLegs = useMemo( - () => (day ? hotelLegsForDay(day, days, tripAccommodations, connSegments) : { top: null, bottom: null }), - [day, days, tripAccommodations, connSegments], + () => (day ? hotelLegsForDay(day, days, tripAccommodations, connSegments, timeline.bookendOwners) : { top: null, bottom: null }), + [day, days, tripAccommodations, connSegments, timeline.bookendOwners], ) const hotelChips = useMemo( @@ -375,6 +376,17 @@ export function useMPlanTimeline(planner: TripPlanner, forDayId?: number | null) persistLegMode(assignmentId, mode) }, [day, persistLegMode]) + // The same for the leg entering a stop: from a booking's arrival or from the + // morning hotel, which no stop leaves (as on the desktop day plan). + const setIncomingLegMode = useCallback((assignmentId: number, mode: string | null) => { + if (!day) return + const key = String(day.id) + useTripStore.setState(state => ({ + assignments: { ...state.assignments, [key]: (state.assignments[key] || []).map(a => (a.id === assignmentId ? { ...a, incoming_leg_transport_mode: mode } : a)) }, + })) + persistLegMode(assignmentId, mode, 'incoming') + }, [day, persistLegMode]) + // ── Public transit for one leg (#2398) ── // The entry the desktop connector menu carries: the automated search, seeded with // the leg's two ends and the time the stop it leaves is planned for, between two city @@ -394,8 +406,9 @@ export function useMPlanTimeline(planner: TripPlanner, forDayId?: number | null) toursEnabled: planner.toursEnabled, tourOf, onPlan: tripHasDates ? openTransitSearch : undefined, }) const transitLegFor = useCallback((seg: RouteSegment): TransitLeg | null => (day ? legFor(day.id, seg) : null), [day, legFor]) - // `originId` is the stop the leg leaves, which tells two walks ending at one spot apart. - const planTransitLeg = useCallback((leg: TransitLeg, originId: number) => { + // `originId` is the stop the leg leaves, which tells two walks ending at one spot apart; + // a leg that leaves a booking or the hotel has none. + const planTransitLeg = useCallback((leg: TransitLeg, originId?: number) => { if (day) plan(day.id, leg, originId) }, [day, plan]) // A saved journey that now arrives after the walk it leads to starts (CW-08). @@ -414,7 +427,7 @@ export function useMPlanTimeline(planner: TripPlanner, forDayId?: number | null) moveRowTo, addPlace, addBooking, addTransport, optimize, canExportRoute, routeTargets, exportGoogleMaps, exportCoMaps, renameDay, fullPlaceOf, - routeModeOptions, setLegMode, transitLegFor, planTransitLeg, journeyLate, tourOverrun, + routeModeOptions, setLegMode, setIncomingLegMode, transitLegFor, planTransitLeg, journeyLate, tourOverrun, } } diff --git a/client/tests/unit/mobile/trip/MPlanTimeline.test.tsx b/client/tests/unit/mobile/trip/MPlanTimeline.test.tsx index 5933e3102..97a12c833 100644 --- a/client/tests/unit/mobile/trip/MPlanTimeline.test.tsx +++ b/client/tests/unit/mobile/trip/MPlanTimeline.test.tsx @@ -128,6 +128,7 @@ function buildTl(over: Record = {}): MPlanTimelineController { { key: 'plugin:ev/fastest', label: 'EV fastest' }, ], setLegMode: vi.fn(), + setIncomingLegMode: vi.fn(), transitLegFor: vi.fn(() => null), planTransitLeg: vi.fn(), journeyLate: vi.fn(() => null), @@ -506,6 +507,74 @@ describe('MPlanTimeline', () => { expect(screen.getByText('7 min').closest('button')).toBeNull() }) + + // The legs a booking or the hotel starts: the phone used to leave them inert while + // the desktop opened the mode menu of the stop at their other end. + describe('legs that start at a booking or the hotel', () => { + const HOTEL_SEG: RouteSegment = { ...SEG, drivingText: '12 min', walkingText: '35 min', distanceText: '2.7 km' } + const hotelLeg = () => screen.getByText('12 min').closest('button') as HTMLElement + const leg = { from: { name: 'Budapest Keleti', lat: 47.5, lng: 19.08 }, to: { name: 'Basilica apARTment', lat: 47.5, lng: 19.05 }, time: '19:29' } + + it('FE-MOB-PLTL-050: the leg back to the hotel sets the outgoing mode of the last stop', () => { + renderTimeline({ hotelLegs: { top: null, bottom: { seg: HOTEL_SEG, name: 'Basilica', assignmentId: 12 } } }, {}, { mode: 'edit' }) + fireEvent.click(hotelLeg()) + + fireEvent.click(screen.getByText('Walking')) + + expect(mocks.tl.setLegMode).toHaveBeenCalledWith(12, 'walking') + expect(mocks.tl.setIncomingLegMode).not.toHaveBeenCalled() + }) + + it('FE-MOB-PLTL-051: the leg from the hotel sets the incoming mode of the first stop', () => { + renderTimeline({ hotelLegs: { top: { seg: HOTEL_SEG, name: 'Basilica', assignmentId: 11 }, bottom: null } }, {}, { mode: 'edit' }) + fireEvent.click(hotelLeg()) + + fireEvent.click(screen.getByText('dayplan.transportMode.useDefault')) + + expect(mocks.tl.setIncomingLegMode).toHaveBeenCalledWith(11, null) + expect(mocks.tl.setLegMode).not.toHaveBeenCalled() + }) + + it('FE-MOB-PLTL-052: a walk from the train to the hotel that no stop owns offers public transit only', () => { + renderTimeline( + { hotelLegs: { top: null, bottom: { seg: HOTEL_SEG, name: 'Basilica' } }, transitLegFor: vi.fn(() => leg) }, + {}, { mode: 'edit' }, + ) + fireEvent.click(hotelLeg()) + + expect(screen.queryByText('Driving')).not.toBeInTheDocument() + expect(screen.queryByText('dayplan.transportMode.useDefault')).not.toBeInTheDocument() + fireEvent.click(screen.getByText('transit.title')) + + expect(mocks.tl.planTransitLeg).toHaveBeenCalledWith(leg, undefined) + }) + + it('FE-MOB-PLTL-053: without a transit search that walk stays plain text', () => { + renderTimeline({ hotelLegs: { top: null, bottom: { seg: HOTEL_SEG, name: 'Basilica' } } }, {}, { mode: 'edit' }) + + expect(screen.getByText('12 min').closest('button')).toBeNull() + }) + + it('FE-MOB-PLTL-054: the leg from a booking to the next stop sets the incoming mode of that stop', () => { + const rows: PlanRow[] = [ + { key: 'tr-21', kind: 'transport', item: M_FLIGHT, res: FLIGHT }, + { key: 'conn-tr-21', kind: 'conn', seg: HOTEL_SEG, incomingAssignmentId: 12 }, + { key: 'pl-12', kind: 'place', item: M_PLACE2, assignment: PARK, linkedReservations: [] }, + ] + renderTimeline({ rows }, {}, { mode: 'edit' }) + fireEvent.click(hotelLeg()) + + fireEvent.click(screen.getByText('Walking')) + + expect(mocks.tl.setIncomingLegMode).toHaveBeenCalledWith(12, 'walking') + }) + + it('FE-MOB-PLTL-055: go mode keeps the hotel legs read-only', () => { + renderTimeline({ hotelLegs: { top: null, bottom: { seg: HOTEL_SEG, name: 'Basilica', assignmentId: 12 } } }) + + expect(screen.getByText('12 min').closest('button')).toBeNull() + }) + }) }) describe('plugin day schedule', () => { diff --git a/client/tests/unit/mobile/trip/MPlanTimelineRows.test.tsx b/client/tests/unit/mobile/trip/MPlanTimelineRows.test.tsx index e849dad78..11b328869 100644 --- a/client/tests/unit/mobile/trip/MPlanTimelineRows.test.tsx +++ b/client/tests/unit/mobile/trip/MPlanTimelineRows.test.tsx @@ -488,6 +488,23 @@ describe('HotelConnRow', () => { expect(screen.getByText('1 h 5 min')).toBeInTheDocument() expect(screen.queryByText('14 min')).not.toBeInTheDocument() }) + + it('FE-MOB-PLROW-045: the leg is a button when it can be tapped, the stay name stays text', () => { + const onTap = vi.fn() + render() + + const button = screen.getByRole('button') + expect(button.textContent).toContain('14 min') + expect(button.textContent).not.toContain('Hotel Sacher') + fireEvent.click(button) + expect(onTap).toHaveBeenCalledTimes(1) + }) + + it('FE-MOB-PLROW-046: without a tap handler nothing on the row is a button', () => { + render() + + expect(screen.queryByRole('button')).not.toBeInTheDocument() + }) }) describe('NoteRow', () => { diff --git a/client/tests/unit/mobile/trip/planTimelineModel.test.ts b/client/tests/unit/mobile/trip/planTimelineModel.test.ts index b3ca973f0..0899b7c0b 100644 --- a/client/tests/unit/mobile/trip/planTimelineModel.test.ts +++ b/client/tests/unit/mobile/trip/planTimelineModel.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it, vi } from 'vitest' import { - breaksChronology, buildPlanRows, cityPillsForDay, findUpNext, getTransitMeta, hotelChipsForDay, + breaksChronology, buildPlanRows, buildPlanTimeline, cityPillsForDay, findUpNext, getTransitMeta, hotelChipsForDay, hotelLegsForDay, itemHasTime, parseReservationMeta, transportSubtitle, type TransportEntry, } from '../../../../src/mobile/screens/trip/plan/planTimelineModel' @@ -956,3 +956,76 @@ describe('planTimelineModel: a rental car picked up or returned on the day', () expect(connectors(rows).map(s => [s.from, s.to])).toEqual([[at(PICKUP), at(MIRADOR)]]) }) }) + +describe('planTimelineModel: which stop owns a leg that touches a booking or the hotel', () => { + // Day 2 of a stay from day 1 to day 3: the traveller walks from the hotel to the + // museum, takes the train to the lake and walks from the station to the hotel. The + // two legs a booking starts and the two bookend legs are the ones the phone could + // not change before; the desktop takes their mode from the stop at their other end. + const HOTEL = { lat: 47.3769, lng: 8.5417 } + const MUSEUM = { lat: 47.3792, lng: 8.5403 } + const STATION_FROM = { lat: 47.378, lng: 8.54 } + const STATION_TO = { lat: 47.05, lng: 8.31 } + const PIER = { lat: 47.052, lng: 8.309 } + const stay = accommodation({ + id: 40, place_id: 950, place_name: 'Hotel Limmat', place_lat: HOTEL.lat, place_lng: HOTEL.lng, + start_day_id: 1, end_day_id: 3, + }) + const museum = buildAssignment({ id: 31, day_id: 2, order_index: 0, place: place(960, 'Museum', MUSEUM.lat, MUSEUM.lng) }) + const pier = buildAssignment({ id: 32, day_id: 2, order_index: 2, place: place(961, 'Pier', PIER.lat, PIER.lng) }) + const train = (id: number, position: number) => buildReservation({ + id, type: 'train', title: `IR ${id}`, day_id: 2, end_day_id: 2, day_plan_position: position, + reservation_time: '2026-05-02T11:00', reservation_end_time: '2026-05-02T12:00', + endpoints: [ + { role: 'from', sequence: 0, name: 'Zurich HB', code: null, ...STATION_FROM, timezone: null, local_date: null, local_time: null }, + { role: 'to', sequence: 1, name: 'Lucerne', code: null, ...STATION_TO, timezone: null, local_date: null, local_time: null }, + ], + }) + + const timelineOf = (dayAssignments: Assignment[], reservations: Reservation[]) => { + const merged = getMergedItems({ + dayAssignments, + dayNotes: [], + dayTransports: getTransportForDay({ reservations, dayId: 2, dayAssignmentIds: dayAssignments.map(a => a.id), days: DAYS }), + dayId: 2, + }) + const segments = segmentsOf(buildDayRouteRuns(2, { + days: DAYS, assignments: { '2': dayAssignments }, reservations, accommodations: [stay], optimizeFromAccommodation: true, + })) + const { rows, bookendOwners } = buildPlanTimeline({ merged, reservations, routeSegments: segments, dayId: 2 }) + return { rows, legs: hotelLegsForDay(DAY2, DAYS, [stay], segments, bookendOwners) } + } + const conns = (rows: ReturnType) => rows.flatMap(r => (r.kind === 'conn' ? [r] : [])) + + it('FE-MOB-PTLM-064: the leg out of a booking uses the incoming mode of the stop it reaches', () => { + const { rows } = timelineOf([museum, pier], [train(70, 1)]) + expect(rows.map(r => r.kind)).toEqual(['place', 'conn', 'transport', 'conn', 'place']) + const [toStation, toPier] = conns(rows) + // Out of a stop: the stop's own outgoing mode, as before. + expect(toStation).toMatchObject({ assignmentId: 31 }) + expect(toStation.incomingAssignmentId).toBeUndefined() + // Out of the train: no stop leaves it, so the pier's incoming mode is the one it uses. + expect(toPier).toMatchObject({ seg: { from: [STATION_TO.lat, STATION_TO.lng], to: [PIER.lat, PIER.lng] }, incomingAssignmentId: 32 }) + expect(toPier.assignmentId).toBeUndefined() + }) + + it('FE-MOB-PTLM-065: the hotel legs belong to the first and the last stop of the day', () => { + const { legs } = timelineOf([museum, pier], [train(70, 1)]) + expect(legs.top).toMatchObject({ name: 'Hotel Limmat', assignmentId: 31, seg: { from: [HOTEL.lat, HOTEL.lng], to: [MUSEUM.lat, MUSEUM.lng] } }) + expect(legs.bottom).toMatchObject({ name: 'Hotel Limmat', assignmentId: 32, seg: { from: [PIER.lat, PIER.lng], to: [HOTEL.lat, HOTEL.lng] } }) + }) + + it('FE-MOB-PTLM-066: a day that ends with the train has no stop owning the walk to the hotel', () => { + const { legs } = timelineOf([museum], [train(71, 5)]) + expect(legs.bottom).toMatchObject({ seg: { from: [STATION_TO.lat, STATION_TO.lng], to: [HOTEL.lat, HOTEL.lng] } }) + expect(legs.bottom?.assignmentId).toBeUndefined() + expect(legs.top).toMatchObject({ assignmentId: 31 }) + }) + + it('FE-MOB-PTLM-067: a day that starts with the train has no stop owning the walk from the hotel', () => { + const { legs } = timelineOf([pier], [train(72, -1)]) + expect(legs.top).toMatchObject({ seg: { from: [HOTEL.lat, HOTEL.lng], to: [STATION_FROM.lat, STATION_FROM.lng] } }) + expect(legs.top?.assignmentId).toBeUndefined() + expect(legs.bottom).toMatchObject({ assignmentId: 32 }) + }) +})