fix(planner): route a layover flight per leg, and count linked places as planned

Two v4.0.0 reports, both a surface answering a question with less than it had.

The map built its own waypoint order. It read the BOOKING position and never
expanded metadata.legs, while a multi-leg booking stores its position per leg —
so a Frankfurt to Vancouver flight via Reykjavik was dropped from the list and
the airport before it was joined to the airport after it in one driving run
across the Atlantic. It now takes the order from getMergedItems, the same one
the day plan renders, which brings the span filter and the leg expansion with
it. getMergedItems in turn had never read day_plan_position, the one slot the
map did read, which is how the two could disagree at all.

getTransportRouteEndpoints handed back the booking outermost airports for every
leg. A stop between two legs was therefore routed from the arrival airport back
to the departure one — a drive from Vancouver to Frankfurt with a cafe in
Reykjavik on the way. A leg now spans its own pair, when the endpoints line up
one per stop with the legs; anything ambiguous keeps the role lookup.

Being planned meant one thing: a day_assignments row. A hotel is linked through
its stay and a venue through its booking, and neither is ever dragged onto a
day, so both sat under Unplanned while the day header printed their names. The
three places that asked the question — desktop sidebar, map markers, phone
browser — now ask one helper that also counts a stay and a day-anchored
booking. A booking that names no day still counts as unplanned, because nothing
says when it happens, and the day plan renders nothing for it either.
@
This commit is contained in:
Maurice
2026-08-27 18:56:54 +02:00
committed by Maurice
parent 88c34f6415
commit 4d6820a4d4
12 changed files with 423 additions and 59 deletions
@@ -1,4 +1,4 @@
// FE-PLANNER-PSHOOK-001 to FE-PLANNER-PSHOOK-048
// FE-PLANNER-PSHOOK-001 to FE-PLANNER-PSHOOK-051
import { http, HttpResponse } from 'msw';
import userEvent from '@testing-library/user-event';
import { render, screen, fireEvent, act, waitFor } from '../../../tests/helpers/render';
@@ -137,6 +137,39 @@ describe('usePlacesSidebar filtering', () => {
expect([...S.plannedIds]).toEqual([1]);
});
// #2072 — a hotel is linked through its stay, never dragged onto a day, so the
// pool called it unplanned while the day header printed its name.
it('FE-PLANNER-PSHOOK-049: a place linked to a stay counts as planned', () => {
const hotel = buildPlace({ id: 1, name: 'Hotel' });
const loose = buildPlace({ id: 2, name: 'Loose' });
const accommodations = [{ place_id: 1, start_day_id: 3, end_day_id: 5 }];
render(<Host {...makeProps({ places: [hotel, loose], accommodations })} />);
act(() => { S.setFilter('unplanned'); });
expect(names()).toEqual(['Loose']);
act(() => { S.setFilter('planned'); });
expect(names()).toEqual(['Hotel']);
});
it('FE-PLANNER-PSHOOK-050: a place on a day-anchored booking counts as planned', () => {
const venue = buildPlace({ id: 1, name: 'Venue' });
const loose = buildPlace({ id: 2, name: 'Loose' });
seedStore(useTripStore, { reservations: [{ id: 9, place_id: 1, day_id: 3 }] });
render(<Host {...makeProps({ places: [venue, loose] })} />);
act(() => { S.setFilter('unplanned'); });
expect(names()).toEqual(['Loose']);
});
it('FE-PLANNER-PSHOOK-051: a booking with no day leaves its place unplanned', () => {
const venue = buildPlace({ id: 1, name: 'Venue' });
seedStore(useTripStore, { reservations: [{ id: 9, place_id: 1, day_id: null }] });
render(<Host {...makeProps({ places: [venue] })} />);
act(() => { S.setFilter('unplanned'); });
expect(names()).toEqual(['Venue']);
});
it('FE-PLANNER-PSHOOK-006: the planned filter keeps only assigned places', () => {
const planned = buildPlace({ id: 1, name: 'Planned' });
const loose = buildPlace({ id: 2, name: 'Loose' });
@@ -15,10 +15,16 @@ import { placeToSaveTarget } from '../Collections/saveTarget'
import type { Place, Category, Day, AssignmentsMap } from '../../types'
import { getGoogleMapsUrlForPlace } from './placeGoogleMaps'
import { safeHttpUrl } from '../../utils/safeUrl'
import { plannedPlaceIds, type PlannedAccommodation } from '../../utils/plannedPlaces'
/** Stable identity — a fresh [] default would invalidate the planned memo on every render. */
const NO_ACCOMMODATIONS: PlannedAccommodation[] = []
export interface PlacesSidebarProps {
tripId: number
places: Place[]
/** The trip's stays — hook-local state in useTripPlanner, so it arrives as a prop. */
accommodations?: PlannedAccommodation[]
categories: Category[]
assignments: AssignmentsMap
selectedDayId: number | null
@@ -45,13 +51,15 @@ export interface PlacesSidebarProps {
*/
export function usePlacesSidebar(props: PlacesSidebarProps) {
const {
tripId, places, assignments, selectedDayId,
tripId, places, assignments, selectedDayId, accommodations = NO_ACCOMMODATIONS,
pushUndo, initialScrollTop, onScrollTopChange,
} = props
const { t } = useTranslation()
const toast = useToast()
const ctxMenu = useContextMenu()
const trip = useTripStore((s) => s.trip)
// A booking plans the place it points at, so the pool has to see them (#2072).
const reservations = useTripStore((s) => s.reservations)
const loadTrip = useTripStore((s) => s.loadTrip)
const can = useCanDo()
const canEditPlaces = can('place_edit', trip)
@@ -216,9 +224,10 @@ export function usePlacesSidebar(props: PlacesSidebarProps) {
const hasTracks = useMemo(() => places.some(p => p.route_geometry), [places])
useEffect(() => { if (filter === 'tracks' && !hasTracks) setFilter('all') }, [hasTracks, filter])
const plannedIds = useMemo(() => new Set(
Object.values(assignments).flatMap(da => da.map(a => a.place?.id).filter(Boolean))
), [assignments])
const plannedIds = useMemo(
() => plannedPlaceIds({ assignments, accommodations, reservations }),
[assignments, accommodations, reservations],
)
const filtered = useMemo(() => {
const list = places.filter(p => {