From 11e4fe6ae3495de084e19950e1c61a1c774c7a6a Mon Sep 17 00:00:00 2001 From: Maurice Date: Fri, 13 Nov 2026 09:15:20 +0100 Subject: [PATCH] feat(dawarich): preselect the stay's day in the accept dialog (#3068) The accept dialog opened on "not on a day yet" although the stay carries its local date. It now picks the trip day whose date matches, on open and when the trip is switched, and falls back to no day when the trip has none that matches. --- .../Dawarich/DawarichAcceptDialog.test.tsx | 61 ++++++++++++++++++- .../Dawarich/DawarichAcceptDialog.tsx | 23 ++++++- .../src/components/Planner/PlacesSidebar.tsx | 1 + .../screens/trip/places/MPlacesBrowser.tsx | 1 + 4 files changed, 82 insertions(+), 4 deletions(-) diff --git a/client/src/components/Dawarich/DawarichAcceptDialog.test.tsx b/client/src/components/Dawarich/DawarichAcceptDialog.test.tsx index d409c3629..c4baaa362 100644 --- a/client/src/components/Dawarich/DawarichAcceptDialog.test.tsx +++ b/client/src/components/Dawarich/DawarichAcceptDialog.test.tsx @@ -1,4 +1,4 @@ -// FE-DAWARICH-ACCEPT-001 to FE-DAWARICH-ACCEPT-026 +// FE-DAWARICH-ACCEPT-001 to FE-DAWARICH-ACCEPT-029 /** * The review step between a detector's guess and a row in somebody's trip. * @@ -95,6 +95,20 @@ const DAYS: Record = { } const daysForTrip = (tripId: number): AcceptTargetOption[] => DAYS[tripId] ?? [] +// The same trips with their calendar dates, as the planner hands them over: the +// stay fell on 10 Sept, which is day 2 of the Rhineland trip and day 1 of a +// second trip that started that morning. +const DATED_DAYS: Record = { + 31: [ + { id: 401, label: 'Day 1', badge: '09 Sept', date: '2026-09-09' }, + { id: 402, label: 'Day 2', badge: '10 Sept', date: '2026-09-10' }, + ], + 32: [{ id: 501, label: 'Alpine day', badge: '10 Sept', date: '2026-09-10' }], + 33: [{ id: 601, label: 'Coast day', badge: '01 Oct', date: '2026-10-01' }], +} +const datedDaysForTrip = (tripId: number): AcceptTargetOption[] => DATED_DAYS[tripId] ?? [] +const DATED_TRIPS: AcceptTargetOption[] = [...TRIPS, { id: 33, label: 'Coast' }] + const JOURNALS: AcceptTargetOption[] = [ { id: 71, label: 'Rhine notebook' }, { id: 72, label: 'Alpine notebook' }, @@ -565,4 +579,49 @@ describe('DawarichAcceptDialog', () => { fireEvent.click(screen.getByRole('button', { name: 'Add place' })) expect(onConfirm).toHaveBeenLastCalledWith({ target: 'place', tripId: 31, time: '10:15', endTime: '12:40' }) }) + + it('FE-DAWARICH-ACCEPT-027: the day picker opens on the trip day the stay was recorded on (#3068)', () => { + const { onConfirm } = open({ trips: DATED_TRIPS, daysForTrip: datedDaysForTrip }) + + // Day 2 is 10 Sept, the stay's own local date: accepting with the defaults + // files the place where it was actually visited. + expect(screen.getByRole('button', { name: /Day 2/ })).toBeInTheDocument() + fireEvent.click(screen.getByRole('button', { name: 'Add place' })) + expect(onConfirm).toHaveBeenCalledWith({ target: 'place', tripId: 31, dayId: 402, time: '10:15', endTime: '12:40' }) + }) + + it("FE-DAWARICH-ACCEPT-028: switching the trip moves the preselection to that trip's day, or to none", () => { + const { onConfirm } = open({ trips: DATED_TRIPS, daysForTrip: datedDaysForTrip }) + + pick('Rhineland', 'Alps') + expect(screen.getByRole('button', { name: /Alpine day/ })).toBeInTheDocument() + + // The coast trip has no day on 10 Sept, so nothing is guessed for it. + pick('Alps', 'Coast') + expect(screen.getByRole('button', { name: 'Not on a day yet' })).toBeInTheDocument() + + fireEvent.click(screen.getByRole('button', { name: 'Add place' })) + expect(onConfirm).toHaveBeenCalledWith({ target: 'place', tripId: 33, time: '10:15', endTime: '12:40' }) + }) + + it('FE-DAWARICH-ACCEPT-029: a preselected day can still be undone, and a new stay is matched afresh', () => { + const { onConfirm, update } = open({ trips: DATED_TRIPS, daysForTrip: datedDaysForTrip }) + + // Unplanned stays a deliberate answer next to the preselection. + pick(/Day 2/, 'Not on a day yet') + fireEvent.click(screen.getByRole('button', { name: 'Add place' })) + expect(onConfirm).toHaveBeenLastCalledWith({ target: 'place', tripId: 31, time: '10:15', endTime: '12:40' }) + + // The next stay fell on the 9th: its own day, not the one cleared above. + update({ + suggestion: stay({ + id: 4, + localDate: '2026-09-09', + startedAt: '2026-09-09T10:15:00+02:00', + endedAt: '2026-09-09T12:40:00+02:00', + }), + }) + fireEvent.click(screen.getByRole('button', { name: 'Add place' })) + expect(onConfirm).toHaveBeenLastCalledWith({ target: 'place', tripId: 31, dayId: 401, time: '10:15', endTime: '12:40' }) + }) }) diff --git a/client/src/components/Dawarich/DawarichAcceptDialog.tsx b/client/src/components/Dawarich/DawarichAcceptDialog.tsx index 985c7196a..c2571d1f1 100644 --- a/client/src/components/Dawarich/DawarichAcceptDialog.tsx +++ b/client/src/components/Dawarich/DawarichAcceptDialog.tsx @@ -19,6 +19,8 @@ export interface AcceptTargetOption { label: string /** Secondary half of the label — a day's date beside its number. */ badge?: string + /** A day's ISO date, so the day the stay fell on can be preselected (#3068). */ + date?: string } export interface DawarichAcceptDialogProps { @@ -81,6 +83,14 @@ export default function DawarichAcceptDialog({ // always describe the row the user just pressed rather than the previous one. const [seededFor, setSeededFor] = useState(null) + // The stay already knows the date it was recorded on, so the day picker opens + // on the trip day that matches it (#3068). Without one it stays unplanned: + // a guessed day would be worse than none. + function dayOfStay(forTrip: number | '', localDate: string): number | '' { + if (typeof forTrip !== 'number' || !daysForTrip) return '' + return daysForTrip(forTrip).find(day => day.date === localDate)?.id ?? '' + } + if (suggestion && seededFor !== suggestion.id) { setSeededFor(suggestion.id) setName(suggestion.name) @@ -88,8 +98,9 @@ export default function DawarichAcceptDialog({ setDate(suggestion.localDate) setTime(clockOf(suggestion.startedAt)) setEndTime(clockOf(suggestion.endedAt)) - setTripId(suggestion.tripId ?? (trips[0]?.id ?? '')) - setDayId('') + const seededTrip = suggestion.tripId ?? (trips[0]?.id ?? '') + setTripId(seededTrip) + setDayId(dayOfStay(seededTrip, suggestion.localDate)) setJournalId(journals[0]?.id ?? '') } @@ -272,7 +283,13 @@ export default function DawarichAcceptDialog({ { setTripId(typeof next === 'number' ? next : ''); setDayId('') }} + onChange={next => { + const nextTrip = typeof next === 'number' ? next : '' + setTripId(nextTrip) + // The old day belongs to the old trip; the new trip's own day + // for the stay takes its place, if it has one. + setDayId(dayOfStay(nextTrip, suggestion.localDate)) + }} options={trips.map(trip => ({ value: trip.id, label: trip.label }))} placeholder={t('dawarich.accept.pickTrip')} style={{ width: '100%' }} diff --git a/client/src/components/Planner/PlacesSidebar.tsx b/client/src/components/Planner/PlacesSidebar.tsx index 45aec1b19..e125621f3 100644 --- a/client/src/components/Planner/PlacesSidebar.tsx +++ b/client/src/components/Planner/PlacesSidebar.tsx @@ -60,6 +60,7 @@ const PlacesSidebar = React.memo(function PlacesSidebar(props: PlacesSidebarProp daysForTrip={() => days.map(day => ({ id: day.id, ...formatDayOption(day.day_number, day.date, locale, t), + date: day.date ?? undefined, }))} // The place it just created belongs on the map and in the list // now, not after a reload. diff --git a/client/src/mobile/screens/trip/places/MPlacesBrowser.tsx b/client/src/mobile/screens/trip/places/MPlacesBrowser.tsx index 333192148..2c7a12d12 100644 --- a/client/src/mobile/screens/trip/places/MPlacesBrowser.tsx +++ b/client/src/mobile/screens/trip/places/MPlacesBrowser.tsx @@ -243,6 +243,7 @@ export default function MPlacesBrowser({ planner, shell }: MPlacesBrowserProps) daysForTrip={() => days.map(day => ({ id: day.id, ...formatDayOption(day.day_number, day.date, locale, t), + date: day.date ?? undefined, }))} // The place it just created belongs on the map and in the list // now, not after a reload.