mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 17:41:51 +00:00
fix(booking-import): stop writing an unreadable type down as a hotel (#2076)
When neither the keyword table nor the model produced a type, the router wrote "hotel" and cast whatever string it got to FlatType without checking it. A hotel is a booking type, so a ferry voucher imported from the Transport tab opened the booking form, which offers six chips and not one transport among them, and "other" was the only honest pick left. An unrecognised string got through the cast too and then vanished silently in nuExtractToKiReservations. The type is validated against FLAT_TYPES now. When it cannot be read the item is still extracted with the lodging shape so it survives mapping, but it says so, and the tie-breaker #2080 added finally has something to fire on: isUnplaceableItem only ever matched a type outside both form's vocabularies, and the server can only emit its own eight, so on a real document it never matched at all. The tab travels with the job instead of sitting in component state. The parse deliberately outlives navigation and reload and the review is triggered by the global widget on any page, so by the time it ran the state had remounted back to its default and the context was gone.
This commit is contained in:
@@ -32,11 +32,19 @@ export interface BackgroundImportTask {
|
||||
sourceFiles?: File[]
|
||||
/** Mode this run used — the widget only offers an AI retry if it wasn't already one. Not persisted. */
|
||||
mode?: BookingImportMode
|
||||
/**
|
||||
* Which tab the import was started from. It decides which form an item opens
|
||||
* when its type is guessed (#2076), and unlike the other transient flags it IS
|
||||
* persisted: the parse deliberately outlives navigation and reload, and the
|
||||
* review is triggered by the global widget on any page, so a component-local
|
||||
* value is gone by the time it is needed.
|
||||
*/
|
||||
kind?: 'transports' | 'bookings'
|
||||
}
|
||||
|
||||
interface BackgroundTasksState {
|
||||
tasks: BackgroundImportTask[]
|
||||
addTask: (task: { id: string; tripId: string; label: string; total: number; files?: File[]; mode?: BookingImportMode }) => void
|
||||
addTask: (task: { id: string; tripId: string; label: string; total: number; files?: File[]; mode?: BookingImportMode; kind?: 'transports' | 'bookings' }) => void
|
||||
setProgress: (id: string, tripId: string, done: number, total: number) => void
|
||||
setDone: (id: string, tripId: string, items: BookingImportPreviewItem[], warnings: string[]) => void
|
||||
setError: (id: string, tripId: string, error: string) => void
|
||||
@@ -63,7 +71,7 @@ export const useBackgroundTasksStore = create<BackgroundTasksState>()(
|
||||
|
||||
return {
|
||||
tasks: [],
|
||||
addTask: ({ id, tripId, label, total, files, mode }) => upsert(id, tripId, { label, total, status: 'running', done: 0, sourceFiles: files, mode }),
|
||||
addTask: ({ id, tripId, label, total, files, mode, kind }) => upsert(id, tripId, { label, total, status: 'running', done: 0, sourceFiles: files, mode, kind }),
|
||||
setProgress: (id, tripId, done, total) => upsert(id, tripId, { done, total, status: 'running' }),
|
||||
setDone: (id, tripId, items, warnings) => upsert(id, tripId, { status: 'done', items, warnings, done: items?.length ?? 0 }),
|
||||
setError: (id, tripId, error) => upsert(id, tripId, { status: 'error', error }),
|
||||
@@ -81,7 +89,9 @@ export const useBackgroundTasksStore = create<BackgroundTasksState>()(
|
||||
partialize: (state) => ({
|
||||
tasks: state.tasks
|
||||
.filter((t) => !t.consumed && t.status !== 'error')
|
||||
.map((t) => ({ id: t.id, tripId: t.tripId, label: t.label, status: t.status, done: t.done, total: t.total })),
|
||||
// `kind` rides along: it is not a review flag but the context the review
|
||||
// needs, and without it a reload silently falls back to 'bookings'.
|
||||
.map((t) => ({ id: t.id, tripId: t.tripId, label: t.label, status: t.status, done: t.done, total: t.total, kind: t.kind })),
|
||||
}),
|
||||
},
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user