From 69ed8fc72257a3ef9eb62c3bc5ad23ae2898cb9e Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Sat, 13 Jun 2026 01:12:22 +0800 Subject: [PATCH] feat(webui): customizable dashboard + nav layout (phase 3) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The "C" half — reorder + show/hide the overview cards and the sidebar nav, persisted to config/ui.json's layout section. - LayoutContext loads the layout (authed GET /api/ui) and persists edits via the section-merge POST /api/ui {layout} (debounced). reconcileLayoutItems keeps stored order/visibility, appends new catalogue entries (forward-compat), and forces pinned items visible. - Overview is refactored into a block registry (stats/connections/alerts/host/ sessions). A 「编辑布局」 mode (motion Reorder — zero new deps) edits both the cards and the nav in place, with per-item show/hide and a reset; an all-hidden dashboard shows an empty state with 恢复默认. - Anti-self-lock: PINNED_NAV = ['/', '/settings'] can be reordered but never hidden — the overview hosts the layout editor and settings hosts account/appearance, so the user can never strand themselves. - api.ui.save now takes Partial (the section-merge contract). A late initial GET can't clobber an in-flight edit (dirtyRef); a pending edit flushes on unmount. Verified across 2 adversarial review rounds. --- .../webui/src/components/layout/sidebar.tsx | 17 +- .../pages/overview-layout-editor.tsx | 126 +++++ .../src/components/pages/overview-page.tsx | 521 +++++++++++------- packages/webui/src/contexts/LayoutContext.tsx | 148 +++++ packages/webui/src/lib/api/types.ts | 5 +- packages/webui/src/router/app-layout.tsx | 21 +- 6 files changed, 613 insertions(+), 225 deletions(-) create mode 100644 packages/webui/src/components/pages/overview-layout-editor.tsx create mode 100644 packages/webui/src/contexts/LayoutContext.tsx diff --git a/packages/webui/src/components/layout/sidebar.tsx b/packages/webui/src/components/layout/sidebar.tsx index 1f3e02dc..37024a0b 100644 --- a/packages/webui/src/components/layout/sidebar.tsx +++ b/packages/webui/src/components/layout/sidebar.tsx @@ -6,6 +6,7 @@ import { Separator } from '@/components/ui/separator'; import { cn } from '@/lib/utils'; import { APP_NAME, APP_VERSION } from '@/types'; import { useAppState } from '@/contexts/AppStateContext'; +import { reconcileLayoutItems, useLayout } from '@/contexts/LayoutContext'; import type { AppPath } from '@/router'; export interface NavItem { @@ -23,6 +24,12 @@ export const NAV_ITEMS: NavItem[] = [ { to: '/settings', label: '系统设置', icon: SlidersHorizontal, description: '主题与账号' }, ]; +// Anti-self-lock: these nav items can be reordered but never hidden. +// '/' — hosts the 「编辑布局」 entry point; hiding it would strand the +// user with no way back to un-hide anything. +// '/settings'— account + appearance. +export const PINNED_NAV: AppPath[] = ['/', '/settings']; + interface SidebarProps { collapsed?: boolean; onItemClick?: () => void; @@ -31,6 +38,14 @@ interface SidebarProps { export function Sidebar({ collapsed = false, onItemClick }: SidebarProps) { const pathname = useRouterState({ select: (s) => s.location.pathname }); const { updateInfo } = useAppState(); + const { navItems } = useLayout(); + + // Render nav in the operator's configured order, hidden items removed, + // pinned items forced on, and forward-compatible with future routes. + const orderedNav = reconcileLayoutItems(navItems, NAV_ITEMS.map((i) => i.to), PINNED_NAV) + .filter((i) => i.visible) + .map((i) => NAV_ITEMS.find((n) => n.to === i.id)) + .filter((n): n is NavItem => !!n); return (
@@ -53,7 +68,7 @@ export function Sidebar({ collapsed = false, onItemClick }: SidebarProps) { {/* Nav */}