fix: keep selected map area in view mode

This commit is contained in:
Nico 2026-06-14 23:08:14 -07:00
parent d116129c62
commit 4290b5bb50
2 changed files with 56 additions and 1 deletions

View File

@ -76,7 +76,6 @@ export default function useLocationMapViewControls({
setLayersOpen(false);
if ((mode === "edit" || previewDraft) && (hasUnsavedChanges || mapState?.draft_map)) {
setPreviewDraft(true);
setSelectedObjectKey(null);
return;
}
setPreviewDraft(false);

View File

@ -1238,6 +1238,62 @@ test("admin view mode previews the edited draft when a saved draft exists", asyn
await expect(page.locator(".location-map-object", { hasText: "Draft Bakery" })).toBeVisible();
});
test("admin keeps the selected draft area when switching to view mode", async ({ page }) => {
await mockMapShell(page);
const publishedObjects = [
{
id: 1211,
location_map_id: 901,
zone_id: 501,
zone_name: "Bakery",
type: "zone",
label: "Live Bakery",
x: 40,
y: 40,
width: 260,
height: 160,
rotation: 0,
locked: false,
visible: true,
sort_order: 1,
},
];
const draftObjects = [
{
...publishedObjects[0],
id: 1311,
location_map_id: 900,
label: "Draft Bakery",
x: 80,
y: 80,
},
];
await page.route("**/households/1/locations/10/map", async (route) => {
await route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify(draftAndPublishedMapState(draftObjects, publishedObjects, true)),
});
});
await page.goto("/stores/100/locations/10/map");
await page.getByRole("button", { name: "Edit Draft" }).click();
const draftBakeryArea = page.getByRole("button", { name: "Map area Draft Bakery" });
await draftBakeryArea.click();
await expect(page.locator(".location-map-sheet-header strong")).toHaveText("Draft Bakery");
await expect(page.locator(".location-map-object.is-selected")).toHaveAttribute("data-object-key", "1311");
await page.getByRole("button", { name: "View", exact: true }).click();
await expect(page.locator(".location-map-status")).toHaveText("Viewing Draft");
await expect(page.locator(".location-map-object.is-selected")).toHaveAttribute("data-object-key", "1311");
await expect(page.locator(".location-map-sheet-header strong")).toHaveText("Draft Bakery");
await expect(page.getByRole("button", { name: "Close selected map area" })).toBeVisible();
});
test("admin edit mode hides unavailable draft actions until changes exist", async ({ page }) => {
await mockMapShell(page);