fix(day-plan): make the legs from a booking or the hotel tappable on the phone

On the phone timeline only a leg that leaves a stop opened the travel mode
menu. The leg from the morning hotel to the first stop, the leg from the last
stop back to the hotel and the leg from a booking's arrival to the next stop
stayed inert, although the desktop day plan already changes them through the
stop at their other end. A TestFlight tester could not tap the walk from their
train's arrival to the hotel.

The timeline now knows which stop owns each of these legs: the first stop's
incoming mode for the morning hotel leg and for a leg out of a booking, the
last stop's outgoing mode for the evening hotel leg. Tapping them in edit mode
opens the same menu as on the desktop, and the phone sets the incoming mode
the way the desktop does.

A leg no stop owns, such as a booking's arrival to the hotel, has no mode to
store. It follows the day default, and on both the phone and the desktop it
now offers the public transit search where a trip has dates, instead of
reacting to nothing.
This commit is contained in:
Maurice
2026-11-25 10:21:43 +01:00
parent 70af8132ef
commit c1c77d89b5
11 changed files with 415 additions and 74 deletions
@@ -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(
<DayPlanSidebar
{...makeDefaultProps({
days,
assignments: { '11': [buildAssignment({ id: 11, day_id: 11, order_index: 0, place: albertina })] },
accommodations,
reservations: [train],
selectedDayId: 11,
routeShown: true,
onPlanTransitLeg,
})}
/>
);
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 },
})
);
});
});
@@ -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 = <HotelRouteConnector seg={leg.seg} name={leg.name} profile={routeProfile} placement={placement} />
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 (
<Tooltip label={label} placement="top">
<div role="button" tabIndex={0} onClick={open} onKeyDown={e => openLegMenuByKey(e, open)} style={{ cursor: 'pointer' }} aria-label={label}>
{connector}
</div>
</Tooltip>
)
}
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 = <HotelRouteConnector seg={hotelLegs[day.id]!.top!.seg} name={hotelLegs[day.id]!.top!.name} profile={routeProfile} placement="top" />
return canEditDays && targetId != null ? (
<Tooltip label={t('dayplan.transportMode.change')} placement="top">
<div role="button" tabIndex={0} onClick={e => 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}
</div>
</Tooltip>
) : connector
})()}
{hotelLegs[day.id]?.top && hotelLegRow(day.id, hotelLegs[day.id]!.top!, 'top')}
{daySchedule.byPosition[day.id]?.start.map(si => <PluginDayScheduleRow key={`${si.pluginId}:${si.id}`} item={si} />)}
{visibleCount === 0 && !dayNoteUi ? (
<div
@@ -2477,17 +2488,7 @@ const DayPlanSidebar = React.memo(function DayPlanSidebar(props: DayPlanSidebarP
})
)}
{daySchedule.byPosition[day.id]?.end.map(si => <PluginDayScheduleRow key={`${si.pluginId}:${si.id}`} item={si} />)}
{hotelLegs[day.id]?.bottom && (() => {
const targetId = hotelLegs[day.id]?.bottom?.targetId
const connector = <HotelRouteConnector seg={hotelLegs[day.id]!.bottom!.seg} name={hotelLegs[day.id]!.bottom!.name} profile={routeProfile} placement="bottom" />
return canEditDays && targetId != null ? (
<Tooltip label={t('dayplan.transportMode.change')} placement="top">
<div role="button" tabIndex={0} onClick={e => 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}
</div>
</Tooltip>
) : connector
})()}
{hotelLegs[day.id]?.bottom && hotelLegRow(day.id, hotelLegs[day.id]!.bottom!, 'bottom')}
<AssistantDayPreview tripId={tripId} dayId={day.id} />{/* The assistant's waiting changes, then the drop zone at the list end */}
<div
style={{ minHeight: 12, padding: '2px 8px' }}
@@ -34,6 +34,15 @@ export function legModeMenuItems(
];
}
/**
* The menu of a leg no stop owns, a booking's arrival to the night's hotel: nothing
* keeps a mode for it, so it follows the day default and only public transit can be
* planned for it.
*/
export function transitOnlyMenuItems(planTransit: () => void, t: Translate): LegModeMenuItem[] {
return [{ label: t('transit.title'), icon: TramFront, onClick: planTransit }];
}
export interface LegModeDeps {
tripId: number;
toast: { error: (message: string) => void };