feat(webui): in-place dashboard edit overlays + inline sidebar reorder

Rework the layout edit mode from a separate panel to in-place affordances:
- Each dashboard widget gets a semi-transparent floating overlay in edit mode:
  a "拖动" grip bar (the whole card is the drag target — forgiving +
  discoverable), an eye to show/hide, and a gear that opens the per-widget
  settings in a dialog. Hidden widgets show as re-enableable "已隐藏" ghosts;
  the bottom-right resize grip is now clearly visible.
- The sidebar nav becomes a drag-to-reorder list directly in the sidebar
  (show/hide + locked pinned items + a 完成 button); editing force-expands the
  sidebar (and disables the collapse toggle). Edit mode is a shared
  LayoutContext flag so one "编辑布局" toggle drives both the grid and the nav.
- The separate editor panel (overview-layout-editor) is removed; the gear
  opens config in a dialog instead.

Also: stat-tile typography tightened (leading-tight, smaller value, overflow
clip) so text no longer hugs the edge on small/short tiles. Verified by an
adversarial review round (no MUST-FIX).
This commit is contained in:
DrSmoothl committed 2026-06-13 21:45:41 +08:00
1 parent 056fff415c
commit a61e0a253d
9 files changed
+339 -349

No files matched your search

@@ -7,6 +7,7 @@ import { Sidebar } from '@/components/layout/sidebar';
import { TopBar } from '@/components/layout/top-bar';
import { useMediaQuery } from '@/hooks/use-media-query';
import { useTheme } from '@/contexts/ThemeContext';
import { useLayout } from '@/contexts/LayoutContext';
import { cn } from '@/lib/utils';
interface MainLayoutProps {
@@ -27,6 +28,10 @@ export function MainLayout({ status, onLogout, children }: MainLayoutProps) {
return appearance.sidebarDefaultCollapsed;
});
const customBg = appearance.background.type !== 'none';
const { editing } = useLayout();
// Force the sidebar open while editing layout so its drag-to-reorder list
// has room (it returns to the user's collapsed pref on 完成).
const effectiveCollapsed = collapsed && !editing;
const [mobileOpen, setMobileOpen] = useState(false);
const pathname = useRouterState({ select: (s) => s.location.pathname });
@@ -40,11 +45,11 @@ export function MainLayout({ status, onLogout, children }: MainLayoutProps) {
{!isMobile && (
<motion.aside
initial={false}
animate={{ width: collapsed ? 64 : 248 }}
animate={{ width: effectiveCollapsed ? 64 : 248 }}
transition={{ type: 'spring', stiffness: 280, damping: 32 }}
className="relative h-full shrink-0 border-r overflow-hidden"
>
<Sidebar collapsed={collapsed} />
<Sidebar collapsed={effectiveCollapsed} />
</motion.aside>
)}
@@ -66,11 +71,12 @@ export function MainLayout({ status, onLogout, children }: MainLayoutProps) {
<div className="flex min-w-0 flex-1 flex-col">
<TopBar
status={status}
collapsed={collapsed}
collapsed={effectiveCollapsed}
onToggleCollapse={() => setCollapsed((v) => !v)}
onOpenMobile={() => setMobileOpen(true)}
onLogout={onLogout}
isMobile={isMobile}
editing={editing}
/>
<main className={cn('flex min-h-0 flex-1 flex-col')}>
+101 -41
View File
@@ -1,5 +1,5 @@
import { LayoutDashboard, PlugZap, Settings, Sparkles, SlidersHorizontal, Terminal } from 'lucide-react';
import { motion } from 'motion/react';
import { Check, Eye, EyeOff, GripVertical, LayoutDashboard, Lock, PlugZap, Settings, Sparkles, SlidersHorizontal, Terminal } from 'lucide-react';
import { motion, Reorder } from 'motion/react';
import { Link, useRouterState } from '@tanstack/react-router';
import { ScrollArea } from '@/components/ui/scroll-area';
import { Separator } from '@/components/ui/separator';
@@ -38,15 +38,23 @@ interface SidebarProps {
export function Sidebar({ collapsed = false, onItemClick }: SidebarProps) {
const pathname = useRouterState({ select: (s) => s.location.pathname });
const { updateInfo } = useAppState();
const { navItems } = useLayout();
const { navItems, setNavItems, editing, setEditing } = 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)
// Full reconciled nav (incl. hidden) — pinned forced visible, forward-compat.
const reconciled = reconcileLayoutItems(navItems, NAV_ITEMS.map((i) => i.to), PINNED_NAV);
// View mode: configured order, hidden removed.
const orderedNav = reconciled
.filter((i) => i.visible)
.map((i) => NAV_ITEMS.find((n) => n.to === i.id))
.filter((n): n is NavItem => !!n);
const reorderNav = (ids: string[]) => {
const byId = new Map(reconciled.map((i) => [i.id, i]));
setNavItems(ids.map((id) => byId.get(id)).filter((x): x is NonNullable<typeof x> => !!x));
};
const toggleNav = (id: string) =>
setNavItems(reconciled.map((i) => (i.id === id ? { ...i, visible: !i.visible } : i)));
return (
<div className="flex h-full w-full flex-col bg-sidebar text-sidebar-foreground">
{/* Brand */}
@@ -67,42 +75,94 @@ export function Sidebar({ collapsed = false, onItemClick }: SidebarProps) {
{/* Nav */}
<ScrollArea className="flex-1 min-h-0" viewportClassName="[&>div]:!block">
<nav className={cn('flex flex-col gap-1 p-2', collapsed && 'items-center')}>
{orderedNav.map(({ to, label, icon: Icon, description }) => {
const isActive = pathname === to;
return (
<Link
key={to}
to={to}
title={collapsed ? label : undefined}
onClick={onItemClick}
aria-current={isActive ? 'page' : undefined}
className={cn(
'group relative flex w-full items-center gap-3 rounded-lg px-3 py-2.5 text-sm font-medium transition-colors cursor-pointer outline-none',
collapsed && 'w-10 justify-center px-0',
isActive
? 'text-sidebar-accent-foreground'
: 'text-muted-foreground hover:bg-sidebar-accent/40 hover:text-foreground',
)}
{editing ? (
<div className="flex flex-col gap-2 p-2">
<div className="flex items-center justify-between px-1">
<span className="text-[11px] font-medium text-muted-foreground">编辑导航</span>
<button
type="button"
onClick={() => setEditing(false)}
className="inline-flex items-center gap-1 rounded-md border border-primary/40 bg-primary/10 px-2 py-0.5 text-[11px] text-primary transition-colors hover:bg-primary/15 cursor-pointer"
>
{isActive && (
<motion.span
layoutId="sidebar-active-pill"
className="absolute inset-0 rounded-lg bg-sidebar-accent ring-1 ring-primary/20"
transition={{ type: 'spring', stiffness: 380, damping: 32 }}
/>
)}
<Icon className={cn('relative z-10 size-4 shrink-0', isActive && 'text-primary')} />
{!collapsed && (
<span className="relative z-10 flex min-w-0 flex-1 flex-col items-start">
<span className="truncate leading-tight">{label}</span>
<span className="text-[10px] font-normal text-muted-foreground truncate">{description}</span>
</span>
)}
</Link>
);
})}
</nav>
<Check className="size-3" /> 完成
</button>
</div>
<Reorder.Group axis="y" values={reconciled.map((i) => i.id)} onReorder={reorderNav} className="flex flex-col gap-1">
{reconciled.map((item) => {
const meta = NAV_ITEMS.find((n) => n.to === item.id);
if (!meta) return null;
const Icon = meta.icon;
const pinned = (PINNED_NAV as string[]).includes(item.id);
return (
<Reorder.Item
key={item.id}
value={item.id}
className={cn(
'flex select-none items-center gap-2 rounded-lg border bg-sidebar-accent/30 px-2 py-2 cursor-grab active:cursor-grabbing',
!item.visible && 'opacity-50',
)}
>
<GripVertical className="size-3.5 shrink-0 text-muted-foreground" />
<Icon className="size-4 shrink-0 text-muted-foreground" />
<span className="min-w-0 flex-1 truncate text-sm">{meta.label}</span>
{pinned ? (
<span title="必选项,不可隐藏" className="inline-flex size-7 items-center justify-center text-muted-foreground/50">
<Lock className="size-3.5" />
</span>
) : (
<button
type="button"
onClick={() => toggleNav(item.id)}
title={item.visible ? '隐藏' : '显示'}
aria-label={item.visible ? '隐藏' : '显示'}
className="inline-flex size-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-sidebar-accent/50 hover:text-foreground cursor-pointer"
>
{item.visible ? <Eye className="size-3.5" /> : <EyeOff className="size-3.5" />}
</button>
)}
</Reorder.Item>
);
})}
</Reorder.Group>
</div>
) : (
<nav className={cn('flex flex-col gap-1 p-2', collapsed && 'items-center')}>
{orderedNav.map(({ to, label, icon: Icon, description }) => {
const isActive = pathname === to;
return (
<Link
key={to}
to={to}
title={collapsed ? label : undefined}
onClick={onItemClick}
aria-current={isActive ? 'page' : undefined}
className={cn(
'group relative flex w-full items-center gap-3 rounded-lg px-3 py-2.5 text-sm font-medium transition-colors cursor-pointer outline-none',
collapsed && 'w-10 justify-center px-0',
isActive
? 'text-sidebar-accent-foreground'
: 'text-muted-foreground hover:bg-sidebar-accent/40 hover:text-foreground',
)}
>
{isActive && (
<motion.span
layoutId="sidebar-active-pill"
className="absolute inset-0 rounded-lg bg-sidebar-accent ring-1 ring-primary/20"
transition={{ type: 'spring', stiffness: 380, damping: 32 }}
/>
)}
<Icon className={cn('relative z-10 size-4 shrink-0', isActive && 'text-primary')} />
{!collapsed && (
<span className="relative z-10 flex min-w-0 flex-1 flex-col items-start">
<span className="truncate leading-tight">{label}</span>
<span className="text-[10px] font-normal text-muted-foreground truncate">{description}</span>
</span>
)}
</Link>
);
})}
</nav>
)}
</ScrollArea>
<Separator />
@@ -15,6 +15,8 @@ interface TopBarProps {
onOpenMobile: () => void;
onLogout: () => void;
isMobile: boolean;
/** Layout edit mode force-expands the sidebar, so collapsing is disabled. */
editing?: boolean;
}
export function TopBar({
@@ -24,6 +26,7 @@ export function TopBar({
onOpenMobile,
onLogout,
isMobile,
editing = false,
}: TopBarProps) {
const [confirmLogout, setConfirmLogout] = useState(false);
const pathname = useRouterState({ select: (s) => s.location.pathname });
@@ -43,8 +46,9 @@ export function TopBar({
variant="ghost"
size="icon-sm"
onClick={onToggleCollapse}
disabled={editing}
aria-label={collapsed ? '展开侧边栏' : '收起侧边栏'}
title={collapsed ? '展开侧边栏' : '收起侧边栏'}
title={editing ? '编辑布局时侧栏保持展开' : collapsed ? '展开侧边栏' : '收起侧边栏'}
>
{collapsed ? <PanelLeftOpen className="size-4" /> : <PanelLeftClose className="size-4" />}
</Button>