From dcafea4a95fe27a73ba332e7661fb5834b40b984 Mon Sep 17 00:00:00 2001 From: Nico Date: Sun, 14 Jun 2026 23:50:34 -0700 Subject: [PATCH] fix: ignore no-op map field edits --- .../src/hooks/useLocationMapObjectActions.js | 22 +++++++++++++++---- frontend/tests/location-map-manager.spec.ts | 6 +++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/frontend/src/hooks/useLocationMapObjectActions.js b/frontend/src/hooks/useLocationMapObjectActions.js index 3b3337a..ca687c2 100644 --- a/frontend/src/hooks/useLocationMapObjectActions.js +++ b/frontend/src/hooks/useLocationMapObjectActions.js @@ -97,6 +97,8 @@ export default function useLocationMapObjectActions({ const handleObjectField = useCallback((field, value) => { if (!selectedObject) return; + if (selectedObject[field] === value) return; + remember(); updateObjects((currentObjects) => currentObjects.map((object) => ( @@ -106,16 +108,28 @@ export default function useLocationMapObjectActions({ }, [remember, selectedObject, updateObjects]); const handleZoneLinkChange = useCallback((zoneId) => { + if (!selectedObject) return; const zone = zones.find((candidate) => String(candidate.id) === String(zoneId)); - handleObjectField("zone_id", zone?.id || null); - setObjects((currentObjects) => + const nextZoneId = zone?.id || null; + const nextZoneName = zone?.name || null; + const nextLabel = selectedObject.label ?? zone?.name ?? ""; + if ( + (selectedObject.zone_id || null) === nextZoneId && + (selectedObject.zone_name || null) === nextZoneName && + selectedObject.label === nextLabel + ) { + return; + } + + remember(); + updateObjects((currentObjects) => currentObjects.map((object) => ( getObjectKey(object) === selectedObjectKey - ? { ...object, zone_name: zone?.name || null, label: object.label ?? zone?.name ?? "" } + ? { ...object, zone_id: nextZoneId, zone_name: nextZoneName, label: object.label ?? zone?.name ?? "" } : object )) ); - }, [handleObjectField, selectedObjectKey, setObjects, zones]); + }, [remember, selectedObject, selectedObjectKey, updateObjects, zones]); return { handleAddObject, diff --git a/frontend/tests/location-map-manager.spec.ts b/frontend/tests/location-map-manager.spec.ts index 8bf1c1a..b3402bf 100644 --- a/frontend/tests/location-map-manager.spec.ts +++ b/frontend/tests/location-map-manager.spec.ts @@ -1721,6 +1721,12 @@ test("admin selecting an object does not mark a draft dirty until it changes", a await expect(page.getByRole("button", { name: "Save Draft" })).toHaveCount(0); await expect(page.getByRole("button", { name: "Undo" })).toBeDisabled(); + await page.getByRole("textbox", { name: "Label" }).fill("Bakery"); + await page.getByLabel("Linked zone").selectOption("501"); + await expect(page.locator(".location-map-status")).toHaveText("Draft"); + await expect(page.getByRole("button", { name: "Save Draft" })).toHaveCount(0); + await expect(page.getByRole("button", { name: "Undo" })).toBeDisabled(); + const objectBox = await bakeryObject.boundingBox(); expect(objectBox).not.toBeNull(); if (!objectBox) throw new Error("Bakery map object was not measurable");