From 1435076cecb5876692fbc86edbc6bc05aefa0a02 Mon Sep 17 00:00:00 2001 From: Maurice Date: Mon, 30 Nov 2026 12:55:06 +0100 Subject: [PATCH] fix(places): a saved place's edit form no longer undoes its tags and notes The tags card and the notes tab write a list copy's labels and notes directly, but the edit form still sent the label_ids and notes it was seeded with when the place opened, so saving a name change laid the old tags and note back over them. The form now sends only the fields it shows. --- .../useCollectionPlaceForm.test.ts | 30 ++++++------------- .../Collections/useCollectionPlaceForm.ts | 15 ++-------- 2 files changed, 11 insertions(+), 34 deletions(-) diff --git a/client/src/components/Collections/useCollectionPlaceForm.test.ts b/client/src/components/Collections/useCollectionPlaceForm.test.ts index 8696a8fec..28f3cf2aa 100644 --- a/client/src/components/Collections/useCollectionPlaceForm.test.ts +++ b/client/src/components/Collections/useCollectionPlaceForm.test.ts @@ -165,21 +165,16 @@ describe('useCollectionPlaceForm', () => { detail.result.current.setEditing(true); detail.result.current.setName(' '); detail.result.current.setLinks([{ label: ' Map ', url: 'maps.example' }, { url: '' }]); - detail.result.current.toggleLabel(10); detail.result.current.setLat('abc'); }); - // toggleLabel reads the rendered selection, so each pick gets its own render. - act(() => detail.result.current.toggleLabel(11)); await act(async () => { await detail.result.current.save(); }); expect(detail.props.onSave).toHaveBeenCalledWith({ name: 'Louvre', description: 'Museum', - notes: null, links: [{ label: 'Map', url: 'https://maps.example' }], category_id: 3, - label_ids: [11], address: 'Rue de Rivoli', lat: null, lng: 2.33, @@ -193,31 +188,24 @@ describe('useCollectionPlaceForm', () => { expect(sheet.props.onSave).toHaveBeenCalledWith({ name: 'Louvre', description: 'Museum', - notes: null, links: [{ label: 'Site', url: 'https://louvre.example' }], category_id: 3, - label_ids: [10], address: 'Rue de Rivoli', }); }); - it('FE-COMP-COLPLACEHOOK-014: seeds, edits and saves the own notes on a saved place (#3168)', async () => { - const sheet = setup({ place: place({ notes: 'Book a week ahead' }) }); - expect(sheet.result.current.notes).toBe('Book a week ahead'); - act(() => { - sheet.result.current.setEditing(true); - sheet.result.current.setNotes(' Closed on Tuesdays '); - }); + it('FE-COMP-COLPLACEHOOK-014: saving leaves the notes and tags to their own tabs', async () => { + // The tabs changed the place after the form was seeded: a save must not lay the old copy over it. + const first = place({ notes: 'Book a week ahead', label_ids: [10] }); + const sheet = setup({ place: first }); + sheet.rerender({ ...sheet.props, place: { ...first, notes: 'Closed on Tuesdays', label_ids: [10, 11] } }); + act(() => sheet.result.current.setEditing(true)); await act(async () => { await sheet.result.current.save(); }); - expect(sheet.props.onSave).toHaveBeenCalledWith(expect.objectContaining({ notes: 'Closed on Tuesdays' })); - - act(() => sheet.result.current.setNotes(' ')); - await act(async () => { - await sheet.result.current.save(); - }); - expect(sheet.props.onSave).toHaveBeenLastCalledWith(expect.objectContaining({ notes: null })); + const patch = vi.mocked(sheet.props.onSave).mock.calls[0][0]; + expect(patch).not.toHaveProperty('notes'); + expect(patch).not.toHaveProperty('label_ids'); }); it('FE-COMP-COLPLACEHOOK-010: a failed save stays in edit mode and toasts', async () => { diff --git a/client/src/components/Collections/useCollectionPlaceForm.ts b/client/src/components/Collections/useCollectionPlaceForm.ts index 6d3577d94..101500035 100644 --- a/client/src/components/Collections/useCollectionPlaceForm.ts +++ b/client/src/components/Collections/useCollectionPlaceForm.ts @@ -86,10 +86,7 @@ export function useCollectionPlaceForm({ const [name, setName] = useState(shown?.name ?? ''); const [categoryId, setCategoryId] = useState(shown?.category_id ?? null); const [description, setDescription] = useState(shown?.description ?? ''); - // The traveller's own notes on the place (#3168), apart from its description. - const [notes, setNotes] = useState(shown?.notes ?? ''); const [links, setLinks] = useState(shown?.links ?? []); - const [labelIds, setLabelIds] = useState(shown?.label_ids ?? []); const [address, setAddress] = useState(shown?.address ?? ''); const [lat, setLat] = useState(coordText(shown?.lat)); const [lng, setLng] = useState(coordText(shown?.lng)); @@ -108,9 +105,7 @@ export function useCollectionPlaceForm({ setName(p.name); setCategoryId(p.category_id ?? null); setDescription(p.description ?? ''); - setNotes(p.notes ?? ''); setLinks(p.links ?? []); - setLabelIds(p.label_ids ?? []); setAddress(p.address ?? ''); setLat(coordText(p.lat)); setLng(coordText(p.lng)); @@ -194,8 +189,6 @@ export function useCollectionPlaceForm({ const setLink = (i: number, patch: Partial) => setLinks(links.map((l, idx) => (idx === i ? { ...l, ...patch } : l))); - const toggleLabel = (id: number) => - setLabelIds(labelIds.includes(id) ? labelIds.filter((x) => x !== id) : [...labelIds, id]); const cancelEdit = () => { if (shown) resetForm(shown); }; @@ -203,13 +196,13 @@ export function useCollectionPlaceForm({ const save = async () => { if (!shown) return; + // Notes and tags are written by their own tabs (PlaceTagsCard, the notes section), + // so the form sends only the fields it shows and never lays an old copy over them. const base = { name: name.trim() || shown.name, description: description.trim() || null, - notes: notes.trim() || null, links: cleanListLinks(links, normalizeLinkUrl), category_id: categoryId, - label_ids: labelIds, address: address.trim() || null, }; setSaving(true); @@ -235,13 +228,9 @@ export function useCollectionPlaceForm({ setCategoryId, description, setDescription, - notes, - setNotes, links, setLinks, setLink, - labelIds, - toggleLabel, address, setAddress, lat,