fix(planner): a place shows every booking linked to it, not just the first (#2201)

Four render sites resolved the day assignment's booking with find(), while the booking dialog happily links several to the same stop. A shared selector in dayMerge returns them all, time-sorted and stable, and the desktop plan tab, the place inspector, the mobile timeline and the mobile place sheet render the full list; the single-booking case is unchanged pixel for pixel.
This commit is contained in:
Maurice
2026-09-02 19:58:13 +02:00
committed by Maurice
parent 5d849ec292
commit faa27e3608
15 changed files with 425 additions and 217 deletions
@@ -175,7 +175,7 @@ export default function MPlanTimeline({ planner, shell }: MPlanTimelineProps) {
<PlaceRow
assignment={row.assignment}
fullPlace={tl.fullPlaceOf(row.assignment)}
linkedRes={row.linkedRes}
linkedReservations={row.linkedReservations}
chrome={chrome}
reorder={reorderFor(row.item)}
drag={dragFor(row)}
@@ -119,10 +119,10 @@ const TIME_CHIP = 'flex-none whitespace-nowrap rounded-[6px] bg-[color:var(--m-i
// ── b3) Place row ────────────────────────────────────────────────────────────
export function PlaceRow({ assignment, fullPlace, linkedRes, chrome, reorder, drag, onOpen, onEdit, onRemove }: {
export function PlaceRow({ assignment, fullPlace, linkedReservations, chrome, reorder, drag, onOpen, onEdit, onRemove }: {
assignment: Assignment
fullPlace: Place | undefined
linkedRes: Reservation | null
linkedReservations: Reservation[]
chrome: RowChrome
reorder: ReactNode
drag?: RowDrag
@@ -134,11 +134,19 @@ export function PlaceRow({ assignment, fullPlace, linkedRes, chrome, reorder, dr
const place = assignment.place
const CatIcon = getCategoryIcon(place?.category?.icon)
const time = fmtTime(place?.place_time, chrome)
const sub = linkedRes
? [
linkedRes.status === 'confirmed' ? t('dayplan.confirmed') : t('dayplan.pendingRes'),
linkedRes.confirmation_number ? `#${linkedRes.confirmation_number}` : '',
].filter(Boolean).join(' · ')
// One line per booking on the stop (#2201). A single one keeps the bare
// status line it always had; once there are several, the title tells them
// apart, since "Confirmed" twice over says nothing.
const bookingLines = linkedReservations.map(r => ({
id: r.id,
text: [
linkedReservations.length > 1 ? r.title : '',
r.status === 'confirmed' ? t('dayplan.confirmed') : t('dayplan.pendingRes'),
r.confirmation_number ? `#${r.confirmation_number}` : '',
].filter(Boolean).join(' · '),
}))
const sub = bookingLines.length > 0
? bookingLines[0].text
: place?.address || place?.description || ''
return (
@@ -175,7 +183,7 @@ export function PlaceRow({ assignment, fullPlace, linkedRes, chrome, reorder, dr
<div className="flex items-center gap-1.5">
<CatIcon size={12} strokeWidth={2.2} className="flex-none text-m-muted" />
<span className="min-w-0 truncate text-[0.875rem] font-semibold">{place?.name}</span>
{linkedRes && (
{bookingLines.length > 0 && (
<span className="flex flex-none items-center gap-1 rounded-full bg-[color:var(--m-ic)] px-[7px] py-[2px] text-[0.5625rem] font-bold tracking-[.04em]">
<Ticket size={10} strokeWidth={2.2} />
{t('mobileTrip.resBadge')}
@@ -188,6 +196,11 @@ export function PlaceRow({ assignment, fullPlace, linkedRes, chrome, reorder, dr
{sub && <span className="min-w-0 truncate font-geist text-[0.71875rem] text-m-muted">{sub}</span>}
</div>
)}
{bookingLines.slice(1).map(line => (
<div key={line.id} className="mt-[2px] flex min-w-0 items-center gap-1.5">
<span className="min-w-0 truncate font-geist text-[0.71875rem] text-m-muted">{line.text}</span>
</div>
))}
{assignment.notes && (
// Day-specific note on this stop (#2163) — mirror of the desktop
// timeline's caption line, so the phone shows the note exists
@@ -0,0 +1,50 @@
import { describe, expect, it } from 'vitest'
import { buildPlanRows } from './planTimelineModel'
import type { MergedItem } from '../../../../utils/dayMerge'
import type { Reservation } from '../../../../types'
// FE-MOBILE-PLANROWS-001 to FE-MOBILE-PLANROWS-003
const zooStop = [
{ type: 'place', sortKey: 0, data: { id: 11, day_id: 5, order_index: 0, place: { id: 1, name: 'Zoo' } } },
] as unknown as MergedItem[]
describe('buildPlanRows', () => {
it('FE-MOBILE-PLANROWS-001: carries every booking linked to the stop, earliest first (#2201)', () => {
const reservations = [
{ id: 531, assignment_id: 11, title: 'Zoo tickets', reservation_time: '2025-06-01T10:15:00' },
{ id: 530, assignment_id: 11, title: 'Parking pass', reservation_time: '2025-06-01T09:00:00' },
{ id: 532, assignment_id: 12, title: 'Another stop', reservation_time: null },
] as unknown as Reservation[]
const rows = buildPlanRows({ merged: zooStop, reservations, routeSegments: [], dayId: 5 })
expect(rows).toHaveLength(1)
const row = rows[0]
if (row.kind !== 'place') throw new Error('expected a place row')
expect(row.linkedReservations.map(r => r.id)).toEqual([530, 531])
})
it('FE-MOBILE-PLANROWS-002: a stop without bookings gets an empty list', () => {
const reservations = [
{ id: 532, assignment_id: 12, title: 'Another stop', reservation_time: null },
] as unknown as Reservation[]
const rows = buildPlanRows({ merged: zooStop, reservations, routeSegments: [], dayId: 5 })
const row = rows[0]
if (row.kind !== 'place') throw new Error('expected a place row')
expect(row.linkedReservations).toEqual([])
})
it('FE-MOBILE-PLANROWS-003: an unlinked booking stays a transport row of its own', () => {
const merged = [
...zooStop,
{ type: 'transport', sortKey: 1, data: { id: 540, type: 'taxi', day_id: 5, title: 'Cab' } },
] as unknown as MergedItem[]
const reservations = [
{ id: 540, assignment_id: null, type: 'taxi', title: 'Cab', reservation_time: null },
] as unknown as Reservation[]
const rows = buildPlanRows({ merged, reservations, routeSegments: [], dayId: 5 })
expect(rows.map(r => r.kind)).toEqual(['place', 'transport'])
const place = rows[0]
if (place.kind !== 'place') throw new Error('expected a place row')
expect(place.linkedReservations).toEqual([])
})
})
@@ -1,6 +1,6 @@
import { Cloud, CloudDrizzle, CloudLightning, CloudRain, CloudSnow, Sun, Wind } from 'lucide-react'
import type { LucideIcon } from 'lucide-react'
import { getDisplayTimeForDay, getSpanPhase, hidesOnMiddleDay, parseTimeToMinutes } from '../../../../utils/dayMerge'
import { getAssignmentReservations, getDisplayTimeForDay, getSpanPhase, hidesOnMiddleDay, parseTimeToMinutes } from '../../../../utils/dayMerge'
import { getDayBookendHotels, isDayInAccommodationRange } from '../../../../utils/dayOrder'
import type { MergedItem } from '../../../../utils/dayMerge'
import type { TransitLegDisplay } from '../../../../components/Planner/transitDisplay'
@@ -24,7 +24,7 @@ export interface TransitMeta {
}
export type PlanRow =
| { key: string; kind: 'place'; item: MergedItem; assignment: Assignment; linkedRes: Reservation | null }
| { key: string; kind: 'place'; item: MergedItem; assignment: Assignment; linkedReservations: Reservation[] }
| { 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 }
@@ -100,7 +100,10 @@ export function buildPlanRows(opts: {
kind: 'place',
item,
assignment,
linkedRes: reservations.find(r => r.assignment_id === assignment.id) ?? null,
// All of them: a stop can carry a parking pass and the tickets for the same
// attraction, and getTransportForDay keeps every linked booking out of the
// timeline, so anything dropped here is gone from the plan tab (#2201).
linkedReservations: getAssignmentReservations(reservations, assignment.id),
})
} else if (item.type === 'note') {
const note = item.data as DayNote
@@ -11,7 +11,7 @@ const items = [
] as unknown as MergedItem[]
const rowFor = (i: number): PlanRow =>
({ key: `row-${i}`, kind: 'place', item: items[i], assignment: {}, linkedRes: null }) as unknown as PlanRow
({ key: `row-${i}`, kind: 'place', item: items[i], assignment: {}, linkedReservations: [] }) as unknown as PlanRow
const connRow = { key: 'conn-1', kind: 'conn', seg: {} } as unknown as PlanRow
@@ -21,7 +21,8 @@ import { safeHttpUrl } from '../../../../utils/safeUrl'
import { openFile } from '../../../../utils/fileDownload'
import { getNavigationTargets, openNavigationTarget } from '../../../../components/Planner/placeNavigation'
import { NavigationMenu } from '../../../../components/shared/NavigationMenu'
import type { Assignment, Day, TripMember } from '../../../../types'
import { getAssignmentReservations } from '../../../../utils/dayMerge'
import type { Assignment, Day, Reservation, TripMember } from '../../../../types'
import { ActionCircle, Eyebrow, INNER_CLS } from './MTripSheetUi'
/**
@@ -85,28 +86,27 @@ export default function MPlaceSheet({ planner, shell }: MTripSheetsProps) {
? ((planner.selectedAssignmentId ? dayAssignments.find(a => a.id === planner.selectedAssignmentId) : null)
?? dayAssignments.find(a => a.place?.id === place?.id))
: null
// The booking attached to that assignment. The desktop inspector shows this
// The bookings attached to that assignment. The desktop inspector shows this
// strip; the phone sheet never did, so a booking reached from a map marker was
// just as unreachable here, only invisibly so (#2012).
const linkedRes = assignmentInDay
? planner.reservations.find(r => r.assignment_id === assignmentInDay.id) ?? null
: null
// just as unreachable here, only invisibly so (#2012). All of them, because a
// stop can carry a parking pass next to its tickets (#2201).
const linkedReservations = getAssignmentReservations(planner.reservations, assignmentInDay?.id)
// A ferry or a flight has its own form — the reservation modal cannot hold one.
// Resolved up front so a user without the matching right gets no button at all,
// rather than one that does nothing (#2012).
const canOpenLinkedRes = !!linkedRes && planner.can(
planner.TRANSPORT_TYPES.has(linkedRes.type) ? 'day_edit' : 'reservation_edit',
const canOpenRes = (res: Reservation) => planner.can(
planner.TRANSPORT_TYPES.has(res.type) ? 'day_edit' : 'reservation_edit',
planner.trip,
)
const openLinkedRes = () => {
if (!linkedRes || !canOpenLinkedRes) return
if (planner.TRANSPORT_TYPES.has(linkedRes.type)) {
planner.setEditingTransport(linkedRes)
planner.setTransportModalDayId(linkedRes.day_id ?? null)
const openRes = (res: Reservation) => {
if (!canOpenRes(res)) return
if (planner.TRANSPORT_TYPES.has(res.type)) {
planner.setEditingTransport(res)
planner.setTransportModalDayId(res.day_id ?? null)
planner.setTransportModalAutomated(false)
planner.setShowTransportModal(true)
} else {
planner.setEditingReservation(linkedRes)
planner.setEditingReservation(res)
planner.setShowReservationModal(true)
}
// This sheet hangs off the place selection, not the sheet stack, so its own
@@ -452,27 +452,32 @@ export default function MPlaceSheet({ planner, shell }: MTripSheetsProps) {
</>
)}
{/* ── The booking attached to this stop (#2012) ── */}
{linkedRes && (
{/* ── The bookings attached to this stop (#2012, #2201) ── */}
{linkedReservations.length > 0 && (
<>
<Eyebrow className="mb-[6px] mt-3">{t('reservations.title')}</Eyebrow>
<button
type="button"
onClick={openLinkedRes}
disabled={!canOpenLinkedRes}
aria-label={canOpenLinkedRes ? t('inspector.editRes') : undefined}
className={`flex w-full items-center gap-2 rounded-[14px] px-3 py-[10px] text-left ${INNER_CLS}`}
>
<span
className="h-2 w-2 flex-none rounded-full"
style={{ background: linkedRes.status === 'confirmed' ? 'var(--m-st-confirmed)' : 'var(--m-st-pending)' }}
/>
<span className="min-w-0 flex-1 truncate text-[0.8125rem] font-semibold">{linkedRes.title}</span>
<span className="flex-none font-geist text-[0.65625rem] text-m-muted">
{linkedRes.status === 'confirmed' ? t('reservations.confirmed') : t('reservations.pending')}
</span>
{canOpenLinkedRes && <ChevronRight size={14} strokeWidth={2} className="flex-none text-m-faint" />}
</button>
<div className="flex flex-col gap-[6px]">
{linkedReservations.map(res => (
<button
key={res.id}
type="button"
onClick={() => openRes(res)}
disabled={!canOpenRes(res)}
aria-label={canOpenRes(res) ? t('inspector.editRes') : undefined}
className={`flex w-full items-center gap-2 rounded-[14px] px-3 py-[10px] text-left ${INNER_CLS}`}
>
<span
className="h-2 w-2 flex-none rounded-full"
style={{ background: res.status === 'confirmed' ? 'var(--m-st-confirmed)' : 'var(--m-st-pending)' }}
/>
<span className="min-w-0 flex-1 truncate text-[0.8125rem] font-semibold">{res.title}</span>
<span className="flex-none font-geist text-[0.65625rem] text-m-muted">
{res.status === 'confirmed' ? t('reservations.confirmed') : t('reservations.pending')}
</span>
{canOpenRes(res) && <ChevronRight size={14} strokeWidth={2} className="flex-none text-m-faint" />}
</button>
))}
</div>
</>
)}