mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-21 19:40:34 +00:00
fix(client): keep the seat change clear of the sheet's held ref and of non-null assertions
Client lint was red: passing the ref-held reservation to bookingSeats added a react-hooks/refs warning in MTransportSheet, so the sheet now reads the seats from the legs it already has (seatsOfLegs). The new PDF test used a non-null assertion.
This commit is contained in:
@@ -272,7 +272,7 @@ describe('downloadTripPDF', () => {
|
||||
}),
|
||||
}
|
||||
await downloadTripPDF({ ...richArgs, reservations: [direct, stopover] })
|
||||
const html = getIframe()!.srcdoc
|
||||
const html = getIframe()?.srcdoc ?? ''
|
||||
expect(html).toContain('Air Italia · AI123 · reservations.meta.seat 31A · CDG → FCO')
|
||||
expect(html).toContain('Lufthansa · LH2 · reservations.meta.seat 14C · BER → HND')
|
||||
expect(html).not.toContain('LH1 · reservations.meta.seat')
|
||||
|
||||
@@ -7,7 +7,7 @@ import { useTranslation } from '../../../../i18n'
|
||||
import { useSettingsStore } from '../../../../store/settingsStore'
|
||||
import { RES_ICONS } from '../../../../components/Planner/DayPlanSidebar.constants'
|
||||
import { splitReservationDateTime } from '../../../../utils/formatters'
|
||||
import { bookingSeats, getFlightLegs, getTrainLegs, seatLabel, usesStationRoute, type FlightLeg, type TrainLeg } from '../../../../utils/flightLegs'
|
||||
import { getFlightLegs, getTrainLegs, seatLabel, seatsOfLegs, usesStationRoute, type FlightLeg, type TrainLeg } from '../../../../utils/flightLegs'
|
||||
import { runsOnDay } from '../../../../utils/reservationRoutes'
|
||||
import { filesFor } from '../../../../utils/reservationFiles'
|
||||
import { bookingDayLabel, segmentCodeLabel } from '../../../../components/Planner/transportDetailModel'
|
||||
@@ -171,7 +171,7 @@ export default function MTransportSheet({ planner, shell }: MTripSheetsProps) {
|
||||
|
||||
// Opened from a leg, that leg's own seat; the whole booking lists the seat of
|
||||
// every leg that has one, each under its route, rather than only the first's.
|
||||
const seats: { route: string | null; seat: string }[] = leg ? (legDetail.seat ? [{ route: null, seat: legDetail.seat }] : []) : bookingSeats(res)
|
||||
const seats: { route: string | null; seat: string }[] = leg ? (legDetail.seat ? [{ route: null, seat: legDetail.seat }] : []) : seatsOfLegs(routeLegs, meta.seat)
|
||||
const ownSeat = seats.find(s => s.route == null)?.seat
|
||||
const legSeats = seats.filter(s => s.route != null)
|
||||
// A flight's legs carry no platform of their own, so that stays the booking's.
|
||||
|
||||
@@ -184,11 +184,15 @@ function legSeat(leg: { seat?: unknown } | null | undefined, index: number, meta
|
||||
export function bookingSeats(r: Reservation): { route: string | null; seat: string }[] {
|
||||
const legs: (FlightLeg | TrainLeg)[] =
|
||||
r.type === 'flight' ? getFlightLegs(r) : usesStationRoute(r.type) ? getTrainLegs(r) : []
|
||||
return seatsOfLegs(legs, parseReservationMetadata(r).seat)
|
||||
}
|
||||
|
||||
/** bookingSeats for legs already read (getFlightLegs or getTrainLegs) and the booking's flat seat. */
|
||||
export function seatsOfLegs(legs: readonly (FlightLeg | TrainLeg)[], flatSeat: unknown): { route: string | null; seat: string }[] {
|
||||
if (legs.length > 1) {
|
||||
return legs.flatMap((l) => (l.seat ? [{ route: [l.from, l.to].filter(Boolean).join(' → ') || null, seat: l.seat }] : []))
|
||||
}
|
||||
const seat = parseReservationMetadata(r).seat
|
||||
return typeof seat === 'string' && seat ? [{ route: null, seat }] : []
|
||||
return typeof flatSeat === 'string' && flatSeat ? [{ route: null, seat: flatSeat }] : []
|
||||
}
|
||||
|
||||
/** The label of one of bookingSeats' seats: "Seat", or "Seat FRA → IST" for a leg. */
|
||||
|
||||
Reference in New Issue
Block a user