From 86e98fde65690b317a0794e06b9ae97c7726a397 Mon Sep 17 00:00:00 2001 From: Maurice Date: Wed, 2 Dec 2026 22:56:54 +0100 Subject: [PATCH] fix(ci): repair trip assistant checks Fix the mobile dashboard import and align the assistant UI with client layer and lint rules. Document the OpenRouter setting, share the reservation status schema, and update coverage for external POI identifiers and the empty costs view. --- client/scripts/format-baseline.json | 1 - .../Assistant/AssistantDayPreview.tsx | 63 +- .../Assistant/AssistantPlaceProposal.tsx | 28 +- .../Assistant/AssistantPlanFields.tsx | 29 +- .../Assistant/assistantPlanFieldsModel.ts | 27 + .../Assistant/cards/ChangeCardSlots.tsx | 109 +-- client/src/components/Budget/CostsPanel.tsx | 10 +- .../src/components/Planner/PlaceFormModal.tsx | 719 ++++++++++-------- .../components/Planner/usePlaceFormModal.ts | 38 +- client/src/hooks/useIsPhone.ts | 52 ++ .../mobile/screens/dashboard/MDashboard.tsx | 2 - client/src/mobile/useIsPhone.ts | 51 +- .../tests/unit/mobile/trip/MCostsTab.test.tsx | 4 +- server/.env.example | 1 + .../src/nest/reservations/reservations.mcp.ts | 7 +- server/tests/e2e/route-row-ids.e2e.test.ts | 1 + .../assistant-attachment-tools.test.ts | 4 +- shared/src/reservation/reservation.schema.ts | 3 + 18 files changed, 635 insertions(+), 514 deletions(-) create mode 100644 client/src/components/Assistant/assistantPlanFieldsModel.ts create mode 100644 client/src/hooks/useIsPhone.ts diff --git a/client/scripts/format-baseline.json b/client/scripts/format-baseline.json index b30d918ff..6a1713f9e 100644 --- a/client/scripts/format-baseline.json +++ b/client/scripts/format-baseline.json @@ -1425,7 +1425,6 @@ "src/mobile/screens/vacay/MVacayShareSheet.tsx", "src/mobile/screens/vacay/useMVacay.ts", "src/mobile/screens/vacay/vacayDayModel.ts", - "src/mobile/useIsPhone.ts", "src/pages/AdminPage.test.tsx", "src/pages/AdminPage.tsx", "src/pages/AtlasPage.tsx", diff --git a/client/src/components/Assistant/AssistantDayPreview.tsx b/client/src/components/Assistant/AssistantDayPreview.tsx index cbab72f52..8a19ca32e 100644 --- a/client/src/components/Assistant/AssistantDayPreview.tsx +++ b/client/src/components/Assistant/AssistantDayPreview.tsx @@ -11,7 +11,7 @@ import type { Place } from '../../types'; import { formatTime } from '../../utils/formatters'; import { TimePill } from '../Planner/planParts'; import { getCategoryIcon } from '../shared/categoryIcons'; -import { isDayNoteProposal, isVisitProposal, planField, proposalNote } from './AssistantPlanFields'; +import { isDayNoteProposal, isVisitProposal, planField, proposalNote } from './assistantPlanFieldsModel'; /** What a waiting change does to one day, as a row of the preview. */ interface PreviewRow { @@ -54,28 +54,57 @@ function rowOf( detail: proposalNote(preview, edits) ?? undefined, }; } + const kind = visitKind(preview, dayId); + if (!kind) return null; const place = places.find((p) => p.id === effect?.placeId); - const row = { - toolCallId, - name: edits?.place?.name ?? effect?.place?.name ?? place?.name ?? subject, - categoryId: - edits?.categoryId === undefined ? (effect?.place?.categoryId ?? place?.category_id ?? null) : edits.categoryId, - categoryName: edits?.categoryId === undefined ? planField(preview, 'category') : undefined, - start: edits?.startTime === undefined ? planField(preview, 'time') : (edits.startTime ?? undefined), - end: edits?.endTime === undefined ? planField(preview, 'endTime') : (edits.endTime ?? undefined), + return { toolCallId, kind, ...visitSubject(preview, place, edits), ...visitDetails(preview, place, edits) }; +} + +function visitSubject( + preview: AssistantChangePreview, + place: Place | undefined, + edits: AssistantPlanEdits | undefined +) { + const proposed = preview.effect?.place; + const categoryId = edits?.categoryId; + return { + name: edits?.place?.name ?? proposed?.name ?? place?.name ?? preview.subject, + categoryId: categoryId === undefined ? (proposed?.categoryId ?? place?.category_id ?? null) : categoryId, + categoryName: categoryId === undefined ? planField(preview, 'category') : undefined, + }; +} + +function editedText(value: string | null | undefined, original: string | undefined): string | undefined { + return value === undefined ? original : (value ?? undefined); +} + +function visitDetails( + preview: AssistantChangePreview, + place: Place | undefined, + edits: AssistantPlanEdits | undefined +) { + return { + start: editedText(edits?.startTime, planField(preview, 'time')), + end: editedText(edits?.endTime, planField(preview, 'endTime')), detail: - (edits?.notes === undefined ? planField(preview, 'notes') : edits.notes) || - (edits?.place?.description === undefined ? planField(preview, 'description') : edits.place.description) || + editedText(edits?.notes, planField(preview, 'notes')) || + editedText(edits?.place?.description, planField(preview, 'description')) || place?.description || - (edits?.place?.address === undefined ? planField(preview, 'address') : edits.place.address) || + editedText(edits?.place?.address, planField(preview, 'address')) || place?.address || undefined, }; - if (!effect) return preview.dayId === dayId && isVisitProposal(preview) ? { ...row, kind: 'add' } : null; - if (effect.dayId === dayId) - return { ...row, kind: effect.kind === 'remove' ? 'remove' : effect.kind === 'move' ? 'in' : 'add' }; - if (effect.kind === 'move' && effect.fromDayId === dayId) return { ...row, kind: 'out' }; - return null; +} + +function visitKind(preview: AssistantChangePreview, dayId: number): PreviewRow['kind'] | null { + const { effect } = preview; + if (!effect) return preview.dayId === dayId && isVisitProposal(preview) ? 'add' : null; + if (effect.dayId === dayId) { + if (effect.kind === 'remove') return 'remove'; + if (effect.kind === 'move') return 'in'; + return 'add'; + } + return effect.kind === 'move' && effect.fromDayId === dayId ? 'out' : null; } const LOOK: Record = { diff --git a/client/src/components/Assistant/AssistantPlaceProposal.tsx b/client/src/components/Assistant/AssistantPlaceProposal.tsx index 2789c0f2e..1d4ccc1bb 100644 --- a/client/src/components/Assistant/AssistantPlaceProposal.tsx +++ b/client/src/components/Assistant/AssistantPlaceProposal.tsx @@ -3,12 +3,12 @@ import { assistantPlanEditsSchema, parsePlaceHours, placeOpeningHoursSchema } fr import { useCallback, useEffect, useState } from 'react'; import { useTranslation } from '../../i18n'; -import { useIsPhone } from '../../mobile/useIsPhone'; +import { useIsPhone } from '../../hooks/useIsPhone'; import { useAssistantStore } from '../../store/assistantStore'; import { useTripStore } from '../../store/tripStore'; import PlaceFormModal from '../Planner/PlaceFormModal'; import { DEFAULT_FORM, formPin, type PlaceFormData } from '../Planner/PlaceFormModal.helpers'; -import { planField } from './AssistantPlanFields'; +import { planField } from './assistantPlanFieldsModel'; import { useAssistantView } from './assistantViewContext'; type PlacePatch = NonNullable; @@ -17,14 +17,16 @@ function originalForm(preview: AssistantChangePreview, rawArgs: unknown, categor const args = rawArgs && typeof rawArgs === 'object' ? (rawArgs as Record) : {}; const value = (key: string) => (typeof args[key] === 'string' ? args[key] : ''); const point = preview.effect?.place; + const coordinate = (key: 'lat' | 'lng') => String(typeof args[key] === 'number' ? args[key] : (point?.[key] ?? '')); + const text = (key: 'address' | 'description') => value(key) || planField(preview, key) || ''; const hours = placeOpeningHoursSchema.safeParse(args.opening_hours); return { ...DEFAULT_FORM, name: value('name') || point?.name || preview.subject, - address: value('address') || planField(preview, 'address') || '', - description: value('description') || planField(preview, 'description') || '', - lat: String(typeof args.lat === 'number' ? args.lat : (point?.lat ?? '')), - lng: String(typeof args.lng === 'number' ? args.lng : (point?.lng ?? '')), + address: text('address'), + description: text('description'), + lat: coordinate('lat'), + lng: coordinate('lng'), category_id: String(categoryId ?? ''), place_time: planField(preview, 'time') ?? '', end_time: planField(preview, 'endTime') ?? '', @@ -53,10 +55,16 @@ function restoreDraft(form: PlaceFormData, edits: AssistantPlanEdits | undefined ...(lng === undefined ? {} : { lng: String(lng ?? '') }), ...(place_notes === undefined ? {} : { notes: place_notes ?? '' }), ...(opening_hours === undefined ? {} : { opening_hours: opening_hours ? JSON.stringify(opening_hours) : '' }), - ...(edits?.startTime === undefined ? {} : { place_time: edits.startTime ?? '' }), - ...(edits?.endTime === undefined ? {} : { end_time: edits.endTime ?? '' }), - ...(edits?.notes === undefined ? {} : { assignment_notes: edits.notes ?? '' }), - ...(edits?.categoryId === undefined ? {} : { category_id: String(edits.categoryId ?? '') }), + ...visitDraft(edits ?? {}), + }; +} + +function visitDraft({ startTime, endTime, notes, categoryId }: AssistantPlanEdits): Partial { + return { + ...(startTime === undefined ? {} : { place_time: startTime ?? '' }), + ...(endTime === undefined ? {} : { end_time: endTime ?? '' }), + ...(notes === undefined ? {} : { assignment_notes: notes ?? '' }), + ...(categoryId === undefined ? {} : { category_id: String(categoryId ?? '') }), }; } diff --git a/client/src/components/Assistant/AssistantPlanFields.tsx b/client/src/components/Assistant/AssistantPlanFields.tsx index 56438a743..0eec0d051 100644 --- a/client/src/components/Assistant/AssistantPlanFields.tsx +++ b/client/src/components/Assistant/AssistantPlanFields.tsx @@ -1,4 +1,4 @@ -import type { AssistantChangeLabelKey, AssistantChangePreview, AssistantPlanEdits } from '@trek/shared'; +import type { AssistantChangePreview, AssistantPlanEdits } from '@trek/shared'; import { Check, Pencil } from 'lucide-react'; import { lazy, Suspense, useEffect, useId, useState } from 'react'; @@ -15,36 +15,11 @@ import { NEUTRAL_TINT, } from '../shared/DialogShell'; import { Tooltip } from '../shared/Tooltip'; +import { isVisitProposal, planField, proposalNote } from './assistantPlanFieldsModel'; import { useAssistantView } from './assistantViewContext'; const AssistantPlaceProposal = lazy(() => import('./AssistantPlaceProposal')); -export function isVisitProposal(preview: AssistantChangePreview | null | undefined) { - return preview?.verbKey === 'addPlaceToDay' || preview?.verbKey === 'assignPlace'; -} - -export function isDayNoteProposal(preview: AssistantChangePreview | null | undefined) { - return preview?.verbKey === 'addDayNote' || preview?.verbKey === 'updateDayNote'; -} - -export function planField(preview: AssistantChangePreview, field: AssistantChangeLabelKey) { - return preview.rows.find((row) => row.labelKey === field)?.after; -} - -export function dayNoteBody(preview: AssistantChangePreview) { - return planField(preview, 'content') ?? (preview.verbKey === 'addDayNote' ? planField(preview, 'time') : undefined); -} - -export function proposalNote(preview: AssistantChangePreview, edits: AssistantPlanEdits | undefined) { - return isVisitProposal(preview) - ? edits?.notes === undefined - ? planField(preview, 'notes') - : edits.notes - : edits?.noteBody === undefined - ? dayNoteBody(preview) - : edits.noteBody; -} - interface ProposalEditProps { preview: AssistantChangePreview; args?: unknown; diff --git a/client/src/components/Assistant/assistantPlanFieldsModel.ts b/client/src/components/Assistant/assistantPlanFieldsModel.ts new file mode 100644 index 000000000..bb73e4d60 --- /dev/null +++ b/client/src/components/Assistant/assistantPlanFieldsModel.ts @@ -0,0 +1,27 @@ +import type { AssistantChangeLabelKey, AssistantChangePreview, AssistantPlanEdits } from '@trek/shared'; + +export function isVisitProposal(preview: AssistantChangePreview | null | undefined) { + return preview?.verbKey === 'addPlaceToDay' || preview?.verbKey === 'assignPlace'; +} + +export function isDayNoteProposal(preview: AssistantChangePreview | null | undefined) { + return preview?.verbKey === 'addDayNote' || preview?.verbKey === 'updateDayNote'; +} + +export function planField(preview: AssistantChangePreview, field: AssistantChangeLabelKey) { + return preview.rows.find((row) => row.labelKey === field)?.after; +} + +export function dayNoteBody(preview: AssistantChangePreview) { + return planField(preview, 'content') ?? (preview.verbKey === 'addDayNote' ? planField(preview, 'time') : undefined); +} + +export function proposalNote(preview: AssistantChangePreview, edits: AssistantPlanEdits | undefined) { + return isVisitProposal(preview) + ? edits?.notes === undefined + ? planField(preview, 'notes') + : edits.notes + : edits?.noteBody === undefined + ? dayNoteBody(preview) + : edits.noteBody; +} diff --git a/client/src/components/Assistant/cards/ChangeCardSlots.tsx b/client/src/components/Assistant/cards/ChangeCardSlots.tsx index a7055f023..8a4f4c38c 100644 --- a/client/src/components/Assistant/cards/ChangeCardSlots.tsx +++ b/client/src/components/Assistant/cards/ChangeCardSlots.tsx @@ -6,12 +6,8 @@ import { useTranslation } from '../../../i18n'; import { Tooltip } from '../../shared/Tooltip'; import AssistantChangeFields from '../AssistantChangeFields'; import type { ChangeItem } from '../assistantParts'; -import AssistantPlanFields, { - isDayNoteProposal, - isVisitProposal, - planField, - proposalNote, -} from '../AssistantPlanFields'; +import AssistantPlanFields from '../AssistantPlanFields'; +import { isDayNoteProposal, isVisitProposal, planField, proposalNote } from '../assistantPlanFieldsModel'; import { useAssistantView } from '../assistantViewContext'; import { useChangeHover } from '../useChangeHover'; import { isSingleBookingDraft } from './booking/bookingCardModel'; @@ -244,15 +240,7 @@ function PendingRow({ const preview = item.preview; const view = item.card ? viewOf(item.card) : null; const inlineBooking = inlineBookingCard(item); - const aside = ; - const visit = isVisitProposal(preview); - const dayNote = isDayNoteProposal(preview); - const editable = preview && (visit || dayNote); - const note = editable ? proposalNote(preview, edits) : null; - const receipt = preview?.verbKey === 'importBooking' ? planField(preview, 'attachedTo') : undefined; - const rows = preview?.rows.filter( - (row) => !(groupedDay && row.labelKey === 'day') && !(dayNote && row.labelKey === 'time') - ); + const editable = preview && (isVisitProposal(preview) || isDayNoteProposal(preview)); return (
} /> ) : preview ? ( - <> - {view?.ownsSubject ? ( - aside - ) : ( - - )} - - {!visit && {verbLabel(preview, t)}} - - {view?.Facts ? ( - } /> - ) : ( - - )} - - {receipt && ( -
-
- )} - {note && {note}} - + ) : (