diff --git a/frontend/src/components/maps/LocationMapBottomSheet.jsx b/frontend/src/components/maps/LocationMapBottomSheet.jsx index df30534..05bd701 100644 --- a/frontend/src/components/maps/LocationMapBottomSheet.jsx +++ b/frontend/src/components/maps/LocationMapBottomSheet.jsx @@ -37,7 +37,6 @@ export default function LocationMapBottomSheet({ onAddObject, onSaveDraft, onPublish, - onPreviewDraft, onObjectField, onZoneLinkChange, onDuplicateObject, @@ -124,7 +123,6 @@ export default function LocationMapBottomSheet({ const canPublishDraft = Boolean(mapState?.draft_map || hasUnsavedChanges); const showSaveDraftAction = Boolean(savingAction === "save" || hasUnsavedChanges); const showPublishAction = Boolean(savingAction === "publish" || canPublishDraft); - const showPreviewDraftAction = Boolean((mapState?.draft_map || hasUnsavedChanges) && !showSelectedObjectForm); const mappedItemSummary = assignedItemCount === visibleAssignedItemCount ? String(assignedItemCount) : `${visibleAssignedItemCount} shown`; @@ -178,11 +176,6 @@ export default function LocationMapBottomSheet({ const secondaryDraftActions = showEditorControls ? (
- {showPreviewDraftAction ? ( - - ) : null}
) : null; const editorActions = showEditorControls ? ( diff --git a/frontend/src/hooks/useLocationMapViewControls.js b/frontend/src/hooks/useLocationMapViewControls.js index fa5c5e2..29566f1 100644 --- a/frontend/src/hooks/useLocationMapViewControls.js +++ b/frontend/src/hooks/useLocationMapViewControls.js @@ -87,7 +87,7 @@ export default function useLocationMapViewControls({ setMode("view"); setEditorTool("pan"); setLayersOpen(false); - if (hasUnsavedChanges) { + if ((mode === "edit" || previewDraft) && (hasUnsavedChanges || mapState?.draft_map)) { setPreviewDraft(true); setSelectedObjectKey(null); return; @@ -99,6 +99,8 @@ export default function useLocationMapViewControls({ }, [ hasUnsavedChanges, mapState, + mode, + previewDraft, setEditorTool, setLayersOpen, setMode, diff --git a/frontend/src/pages/LocationMapManager.jsx b/frontend/src/pages/LocationMapManager.jsx index dc6b749..f347190 100644 --- a/frontend/src/pages/LocationMapManager.jsx +++ b/frontend/src/pages/LocationMapManager.jsx @@ -359,7 +359,6 @@ export default function LocationMapManager() { onAddObject={handleAddObject} onSaveDraft={handleSaveDraft} onPublish={handlePublish} - onPreviewDraft={handlePreviewDraft} onObjectField={handleObjectField} onZoneLinkChange={handleZoneLinkChange} onDuplicateObject={handleDuplicateObject} diff --git a/frontend/tests/location-map-manager.spec.ts b/frontend/tests/location-map-manager.spec.ts index 41ee8c6..ed3d261 100644 --- a/frontend/tests/location-map-manager.spec.ts +++ b/frontend/tests/location-map-manager.spec.ts @@ -364,7 +364,7 @@ test("admin creates a map from zones, saves a draft, and publishes it", async ({ await expect(page).toHaveURL(/\/stores\/100\/locations\/10\/map$/); await expect(page.locator(".location-map-status")).toHaveText("Unsaved Draft"); - await page.getByRole("button", { name: "View Draft" }).click(); + await page.getByRole("button", { name: "View", exact: true }).click(); await expect(page.locator(".location-map-object", { hasText: "Bread Wall" })).toBeVisible(); await expect(page.locator(".location-map-status")).toHaveText("Unsaved Draft"); @@ -1172,7 +1172,7 @@ test("admin can add the first area from a blank map canvas", async ({ page }) => await expect(page.getByRole("button", { name: "Save Draft" })).toBeEnabled(); }); -test("admin status follows the visible map when a saved draft exists", async ({ page }) => { +test("admin view mode previews the edited draft when a saved draft exists", async ({ page }) => { await mockMapShell(page); const publishedObjects = [ @@ -1223,13 +1223,13 @@ test("admin status follows the visible map when a saved draft exists", async ({ await expect(page.locator(".location-map-status")).toHaveText("Draft"); await expect(page.locator(".location-map-object", { hasText: "Draft Bakery" })).toBeVisible(); - await page.getByRole("button", { name: "View Draft" }).click(); + 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", { hasText: "Draft Bakery" })).toBeVisible(); await page.getByRole("button", { name: "View" }).click(); - await expect(page.locator(".location-map-status")).toHaveText("Published"); - await expect(page.locator(".location-map-object", { hasText: "Live Bakery" })).toBeVisible(); + await expect(page.locator(".location-map-status")).toHaveText("Viewing Draft"); + await expect(page.locator(".location-map-object", { hasText: "Draft Bakery" })).toBeVisible(); }); test("admin edit mode hides unavailable draft actions until changes exist", async ({ page }) => { @@ -1341,7 +1341,7 @@ test("mode switches close open map layers without resetting filters", async ({ p await page.getByRole("button", { name: "Edit Draft" }).click(); await page.getByRole("button", { name: "Layers, 1 changed" }).click(); await expect(page.locator(".location-map-display-panel")).toBeVisible(); - await page.getByRole("button", { name: "View Draft" }).click(); + await page.getByRole("button", { name: "View", exact: true }).click(); await expect(page.getByRole("button", { name: "Layers, 1 changed" })).toHaveAttribute("aria-expanded", "false"); await expect(page.locator(".location-map-display-panel")).toHaveCount(0); @@ -1390,7 +1390,7 @@ test("mobile keeps viewing draft status compact in the topbar", async ({ page }) await page.goto("/stores/100/locations/10/map"); await page.getByRole("button", { name: "Edit Draft" }).click(); - await page.getByRole("button", { name: "View Draft" }).click(); + await page.getByRole("button", { name: "View", exact: true }).click(); const topbar = page.locator(".location-map-topbar"); const backButton = page.getByRole("button", { name: "Back to grocery list" }); @@ -4073,7 +4073,8 @@ test("mobile editor uses bottom sheet controls instead of desktop object toolbar await expect(primaryActions.getByRole("button", { name: "Save Draft" })).toHaveCount(0); await expect(primaryActions.getByRole("button", { name: "Publish" })).toBeVisible(); await expect(secondaryActions.getByRole("button", { name: "Add Area" })).toBeVisible(); - await expect(secondaryActions.getByRole("button", { name: "View Draft" })).toBeVisible(); + await expect(secondaryActions.getByRole("button", { name: "View Draft" })).toHaveCount(0); + await expect(page.getByRole("button", { name: "View", exact: true })).toBeVisible(); const primaryActionBox = await primaryActions.boundingBox(); const secondaryActionBox = await secondaryActions.boundingBox(); expect(primaryActionBox).not.toBeNull();