diff --git a/src/workspaces/officerdev/src/apps/Dashboards/DashboardListApp.tsx b/src/workspaces/officerdev/src/apps/Dashboards/DashboardListApp.tsx index ffde057a..1abd9b91 100644 --- a/src/workspaces/officerdev/src/apps/Dashboards/DashboardListApp.tsx +++ b/src/workspaces/officerdev/src/apps/Dashboards/DashboardListApp.tsx @@ -60,9 +60,13 @@ export const DashboardListApp = () => { }) : dashboards; + // Keep ?selected= while editing: you are still on this dashboard, just in edit mode. DashboardPreview + // renders the form over the preview whenever `editing` is set, so there is nothing to clear it for — + // and on mobile `selected` is what opens the right-hand panel the form lives in (DashboardsScreen), + // so clearing it opened the form where you could not see it. Cancelling or refreshing now returns to + // the dashboard you were editing instead of an empty preview. const handleEdit = (ev: React.MouseEvent, ws: DashboardDefinition) => { ev.stopPropagation(); - clearSelected(); setCreating(false); setEditing(ws.id); setName(ws.name); @@ -140,6 +144,12 @@ export const DashboardListApp = () => { > { + setCreating(false); + setEditing(null); + }} className="flex flex-1 items-center gap-2.5 py-2 px-3 min-w-0 cursor-pointer" > diff --git a/src/workspaces/officerdev/src/apps/Dashboards/DashboardPreview.tsx b/src/workspaces/officerdev/src/apps/Dashboards/DashboardPreview.tsx index ca004dc4..ce92281a 100644 --- a/src/workspaces/officerdev/src/apps/Dashboards/DashboardPreview.tsx +++ b/src/workspaces/officerdev/src/apps/Dashboards/DashboardPreview.tsx @@ -446,16 +446,15 @@ const NewDashboardForm = () => { // --- Empty State --- +// Only reached when nothing is selected AND nothing is being created or edited — DashboardPreview checks +// those first now, so this component no longer needs its own creating/editing branch. const DashboardPreviewEmpty = () => { - const [creating, setCreating] = useGlobal(CREATING_DASHBOARD_KEY, false); - const [editingId] = useGlobal(EDITING_DASHBOARD_KEY, null); + const [, setCreating] = useGlobal(CREATING_DASHBOARD_KEY, false); const [, setName] = useGlobal(NEW_DASH_NAME_KEY, ''); const [, setDescription] = useGlobal(NEW_DASH_DESC_KEY, ''); const [, setTemplateIdx] = useGlobal(NEW_DASH_TEMPLATE_KEY, 0); const [, setFilePath] = useUserState('files/currentPath', '/'); - if (creating || editingId) return ; - const handleCreate = () => { setName(generateSlug()); setDescription(''); @@ -492,6 +491,16 @@ export const DashboardPreview = () => { const [searchParams] = useSearchParams(); const selectedId = searchParams.get('selected'); const { value: dashboards } = useDashboardState('workspaces', []); + const [creating] = useGlobal(CREATING_DASHBOARD_KEY, false); + const [editingId] = useGlobal(EDITING_DASHBOARD_KEY, null); + + // The form wins over the preview, but only for the dashboard actually selected. It used to be reachable + // only through the empty state, so editing had to clear ?selected= to get to it — which meant the URL + // forgot which dashboard you were editing, and on mobile it closed the very panel the form renders in. + // The `editingId === selectedId` guard is what stops an abandoned edit from showing over a different + // dashboard reached by back/forward or a pasted link (a click is already handled by the list). + if (creating || (editingId && editingId === selectedId)) return ; + const dashboard = selectedId ? dashboards.find((ws) => ws.id === selectedId) : null; if (!dashboard) return ;