fix(planner): keep a parked car off the days between drop-off and pickup

A parking booking spanning the trip showed up on every day, sometimes in between
planned activities. It now appears on its first and last day only, with drop-off
and pickup wording, and contributes nothing to the days in between, not even a
badge in the day header. Applied to the day plan, the mobile timeline, the PDF
export and the shared trip view, so a shared link shows what the app shows.

Rental cars stay as they are. The report names the car's smaller tag as the thing
it does not want for parking, not as something to change, and a car's middle days
move into the day header, which is what people expect from a vehicle they are
driving around.

The distance connector between legs is keyed off the row that gets hidden, so
hiding it naively takes the "2 km" label with it, which is what #1504 was about.
There is a test that fails without that guard.

Each segment of a stopover flight or train can also carry its own booking
reference now, since airlines often issue one per flight rather than one per
booking. Legs already live as a JSON array on the reservation, so this is an
optional field per entry: no migration, no contract change, and a booking without
it renders exactly as before. Readable everywhere it can be entered, desktop and
mobile, through the same blur treatment other booking codes get, plus the PDF and
the calendar description. create_transport and update_transport preserve it too,
otherwise they would accept the field and silently drop it.

Closes #1937
Closes #1943
This commit is contained in:
Maurice
2026-08-17 14:21:44 +02:00
committed by Maurice
parent d156404b84
commit 0a7e460253
51 changed files with 860 additions and 32 deletions
+44 -1
View File
@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest'
import { parseTimeToMinutes, getSpanPhase, getTransportRouteEndpoints, getDisplayTimeForDay, getTransportForDay, getMergedItems } from './dayMerge'
import { parseTimeToMinutes, getSpanPhase, hidesOnMiddleDay, getTransportRouteEndpoints, getDisplayTimeForDay, getTransportForDay, getMergedItems } from './dayMerge'
describe('parseTimeToMinutes', () => {
it('parses HH:MM string', () => {
@@ -34,6 +34,49 @@ describe('getSpanPhase', () => {
})
})
describe('hidesOnMiddleDay', () => {
it('keeps a one-day parking on its only day', () => {
expect(hidesOnMiddleDay({ type: 'parking', day_id: 1, end_day_id: 1 }, 1)).toBe(false)
})
it('keeps a two-day parking on both days (no day in between exists)', () => {
const parking = { type: 'parking', day_id: 1, end_day_id: 2 }
expect(hidesOnMiddleDay(parking, 1)).toBe(false)
expect(hidesOnMiddleDay(parking, 2)).toBe(false)
})
it('hides a three-day parking only on the day in between', () => {
const parking = { type: 'parking', day_id: 1, end_day_id: 3 }
expect(hidesOnMiddleDay(parking, 1)).toBe(false)
expect(hidesOnMiddleDay(parking, 2)).toBe(true)
expect(hidesOnMiddleDay(parking, 3)).toBe(false)
})
it('hides every day in between of a longer parking span (#1937)', () => {
const parking = { type: 'parking', day_id: 1, end_day_id: 5 }
expect([1, 2, 3, 4, 5].map(d => hidesOnMiddleDay(parking, d)))
.toEqual([false, true, true, true, false])
})
it('leaves a car rental visible, since its middle days move to the day header', () => {
expect(hidesOnMiddleDay({ type: 'car', day_id: 1, end_day_id: 3 }, 2)).toBe(false)
})
it('leaves every other booking type alone', () => {
for (const type of ['train', 'cruise', 'event', 'hotel', 'other']) {
expect(hidesOnMiddleDay({ type, day_id: 1, end_day_id: 3 }, 2)).toBe(false)
}
})
it('keeps a parking whose end day is not part of the trip', () => {
expect(hidesOnMiddleDay({ type: 'parking', day_id: 1, end_day_id: 999 }, 1)).toBe(false)
})
it('keeps an unscheduled parking', () => {
expect(hidesOnMiddleDay({ type: 'parking', day_id: null, end_day_id: null }, 2)).toBe(false)
})
})
describe('getTransportRouteEndpoints', () => {
const pickup = { role: 'from', lat: 48.1, lng: 11.5 }
const dropoff = { role: 'to', lat: 52.5, lng: 13.4 }
+20
View File
@@ -29,6 +29,26 @@ export function getSpanPhase(
return 'middle'
}
/**
* Booking types that carry no information on the days between their start and end and
* therefore drop out of the day timeline there. A parked car just stands in the garage:
* you only need to know when you hand it over and when you collect it, so the days in
* between show nothing at all, not even a badge in the day header (#1937).
*
* A car rental is deliberately NOT in this set: its middle days are not dropped but
* moved into the day header, which is what people expect from a vehicle they are
* driving around. Kept as a set so another such type can join without editing every
* render site again.
*/
const MIDDLE_DAY_HIDDEN_TYPES = new Set(['parking'])
export function hidesOnMiddleDay(
r: { type?: string | null; day_id?: number | null; end_day_id?: number | null },
dayId: number
): boolean {
return !!r.type && MIDDLE_DAY_HIDDEN_TYPES.has(r.type) && getSpanPhase(r, dayId) === 'middle'
}
/**
* The route waypoints a transport contributes on a given day, respecting multi-day spans.
* A car rental (or any reservation whose span covers several days) is only routed to on its
+46
View File
@@ -50,3 +50,49 @@ describe('getTrainLegs (#1150)', () => {
expect(legs[0]).toMatchObject({ from: 'FRA', to: 'JFK', airline: 'LH', flight_number: 'LH 400' })
})
})
describe('per-segment booking references (#1943)', () => {
it('reads each segment its own code, and leaves a code-less segment undefined', () => {
const flight = res({
type: 'flight',
confirmation_number: 'BOOK1',
metadata: JSON.stringify({
legs: [
{ from: 'FRA', to: 'BER', confirmation_number: 'ABC123' },
{ from: 'BER', to: 'HND' },
],
}),
})
const legs = getFlightLegs(flight)
expect(legs[0].confirmation_number).toBe('ABC123')
// No fallback to the booking's own code: a segment either has one or it does
// not, and the booking's reference is shown separately.
expect(legs[1].confirmation_number).toBeUndefined()
})
it('reads a train segment code the same way', () => {
const train = res({
metadata: JSON.stringify({
legs: [
{ from: 'Berlin Hbf', to: 'Frankfurt Hbf', confirmation_number: 'DB-1' },
{ from: 'Frankfurt Hbf', to: 'München Hbf', confirmation_number: 'DB-2' },
],
}),
})
expect(getTrainLegs(train).map(l => l.confirmation_number)).toEqual(['DB-1', 'DB-2'])
})
it('gives the derived single leg of a legacy booking the booking code', () => {
const flight = res({
type: 'flight', confirmation_number: 'BOOK1', day_id: 3,
metadata: JSON.stringify({ departure_airport: 'FRA', arrival_airport: 'JFK' }),
})
expect(getFlightLegs(flight)[0].confirmation_number).toBe('BOOK1')
const train = res({
confirmation_number: 'BOOK2',
endpoints: [ep('from', 0, 'Köln Hbf'), ep('to', 1, 'Aachen Hbf')],
metadata: '{}',
})
expect(getTrainLegs(train)[0].confirmation_number).toBe('BOOK2')
})
})
+10
View File
@@ -19,6 +19,8 @@ export interface FlightLeg {
to: string | null
airline?: string
flight_number?: string
/** This segment's own booking reference, when it was booked separately (#1943). */
confirmation_number?: string
dep_day_id?: number | null
dep_time?: string | null // 'HH:mm'
arr_day_id?: number | null
@@ -59,6 +61,7 @@ export function getFlightLegs(r: Reservation): FlightLeg[] {
to: l.to ?? null,
airline: l.airline || undefined,
flight_number: l.flight_number || undefined,
confirmation_number: l.confirmation_number || undefined,
dep_day_id: l.dep_day_id ?? null,
dep_time: l.dep_time ?? null,
arr_day_id: l.arr_day_id ?? null,
@@ -77,6 +80,8 @@ export function getFlightLegs(r: Reservation): FlightLeg[] {
to: toCode,
airline: meta.airline || undefined,
flight_number: meta.flight_number || undefined,
// The single segment IS the booking, so its reference is the booking's.
confirmation_number: r.confirmation_number || undefined,
dep_day_id: r.day_id ?? null,
dep_time: first?.local_time ?? null,
arr_day_id: r.end_day_id ?? r.day_id ?? null,
@@ -95,6 +100,8 @@ export interface TrainLeg {
train_number?: string
platform?: string
seat?: string
/** This segment's own booking reference, when it was booked separately (#1943). */
confirmation_number?: string
dep_day_id?: number | null
dep_time?: string | null
arr_day_id?: number | null
@@ -115,6 +122,7 @@ export function getTrainLegs(r: Reservation): TrainLeg[] {
train_number: l.train_number || undefined,
platform: l.platform || undefined,
seat: l.seat || undefined,
confirmation_number: l.confirmation_number || undefined,
dep_day_id: l.dep_day_id ?? null,
dep_time: l.dep_time ?? null,
arr_day_id: l.arr_day_id ?? null,
@@ -133,6 +141,8 @@ export function getTrainLegs(r: Reservation): TrainLeg[] {
train_number: meta.train_number || undefined,
platform: meta.platform || undefined,
seat: meta.seat || undefined,
// The single segment IS the booking, so its reference is the booking's.
confirmation_number: r.confirmation_number || undefined,
dep_day_id: r.day_id ?? null,
dep_time: first?.local_time ?? null,
arr_day_id: r.end_day_id ?? r.day_id ?? null,