refactor(web/default): adopt drill-in sidebar pattern for System Settings

Replace the ad-hoc "workspace" abstraction with a focused, URL-driven
"sidebar view" registry that implements the modern Vercel / Cloudflare
drill-in pattern: clicking a top-level entry (e.g. System Settings)
swaps the sidebar to a contextual workspace, with a `← Back to
Dashboard` affordance, instead of stacking sub-navigation in the root.

Architecture
------------
- types.ts
    + SidebarView           — declarative nested view config
                              (id, pathPattern, parent, getNavGroups)
    + SidebarViewParent     — back-navigation descriptor
    + ResolvedSidebarView   — { key, view, navGroups } returned by hook
    + SidebarData           — slimmed to { navGroups } only
    - Workspace             — removed (logo/plan never rendered)

- lib/sidebar-view-registry.ts (new, replaces workspace-registry.ts)
    + SIDEBAR_VIEWS array — single source of truth for nested views
    + resolveSidebarView(pathname)
    + getNavGroupsForPath(pathname, t) — back-compat helper for the
      command palette

- config/system-settings.config.ts
    Refactored to export a single SYSTEM_SETTINGS_VIEW (SidebarView)
    with parent `/dashboard/overview` + label `Back to Dashboard`.

- components/sidebar-view-header.tsx (new)
    Renders only the back affordance (chevron + label). Uses the
    default SidebarMenuButton size so its typography matches the
    nav items below; collapses gracefully into icon mode via the
    existing tooltip behavior. The redundant "title + icon" row was
    removed — workspace context is already carried by the nav groups.

- hooks/use-sidebar-view.ts (new)
    Encapsulates view resolution and root-nav filtering:
      · matched view  → returns its nav groups verbatim (route-level
                        beforeLoad guards already enforce access);
      · no match      → returns root nav groups, narrowed by user
                        role (admin gate) and useSidebarConfig
                        (admin × user sidebar_modules overlay).

- components/app-sidebar.tsx
    Now a thin presentation layer: reads { key, view, navGroups }
    from useSidebarView() and orchestrates the view transition via
    AnimatePresence + MOTION_VARIANTS.sidebarSlide (respects
    prefers-reduced-motion). No logic, no role checks, no path
    matching — those live in the hook.

- components/command-menu.tsx
    Switched to the new getNavGroupsForPath() API; behavior preserved.

Cleanup
-------
- Deleted layout/context/workspace-context.tsx (zero consumers).
- Deleted layout/lib/workspace-registry.ts and its
  workspace-registry.example.ts companion (over-abstracted: name/id
  metadata, isInWorkspace / getAllWorkspaces / WORKSPACE_IDS were
  registered but never read).
- Removed `workspaces` field from useSidebarData (never consumed
  after the top-switcher was dropped).
- Dropped WorkspaceProvider from authenticated-layout.tsx.
- Trimmed dead `Manage and configure` translation key from all six
  locale files and from static-keys.ts.

i18n
----
Added the `Back to Dashboard` key to en, zh, fr, ja, ru, vi, and
registered it in static-keys.ts under "Sidebar views".

Verification
------------
- bun run typecheck: passes
- Lint: no new warnings/errors on the touched files
- Adding a new drill-in workspace now only requires registering a
  SidebarView in SIDEBAR_VIEWS — no changes to AppSidebar required.
This commit is contained in:
t0ng7u
2026-05-24 22:09:05 +08:00
parent 49bc3a1175
commit 92a0959448
46 changed files with 515 additions and 591 deletions
@@ -82,9 +82,17 @@ export function PerformanceHealthPanel() {
const summary = useMemo(() => {
return {
avgLatencyMs: Math.round(
simpleAverage(models, 'avg_latency_ms', (v) => Number.isFinite(v) && v > 0)
simpleAverage(
models,
'avg_latency_ms',
(v) => Number.isFinite(v) && v > 0
)
),
avgTps: simpleAverage(
models,
'avg_tps',
(v) => Number.isFinite(v) && v > 0
),
avgTps: simpleAverage(models, 'avg_tps', (v) => Number.isFinite(v) && v > 0),
successRate: simpleAverage(models, 'success_rate', Number.isFinite),
}
}, [models])
@@ -96,7 +104,10 @@ export function PerformanceHealthPanel() {
return (
<section className='bg-card h-full overflow-hidden rounded-2xl border shadow-xs'>
<div className='flex items-center gap-2 border-b px-4 py-3 sm:px-5'>
<HeartPulse className='text-muted-foreground/60 size-4 shrink-0' aria-hidden='true' />
<HeartPulse
className='text-muted-foreground/60 size-4 shrink-0'
aria-hidden='true'
/>
<h3 className='text-sm font-semibold'>{t('Performance health')}</h3>
<span className='text-muted-foreground ml-auto text-xs'>
{t('Performance metrics for the last 24 hours')}
@@ -132,38 +143,43 @@ export function PerformanceHealthPanel() {
<Skeleton key={i} className='h-5 w-full rounded' />
))}
</div>
) : hasData && (
<div>
<span className='text-muted-foreground mb-1 block text-[11px] font-medium'>
{t('Top models by traffic')}
</span>
<div className='grid grid-cols-1 gap-x-4 sm:grid-cols-2'>
{topModels.map((model) => (
<div
key={model.model_name}
className='flex items-center justify-between gap-2 rounded px-1.5 py-1'
>
<span className='min-w-0 flex-1 truncate font-mono text-[11px]'>
{model.model_name}
</span>
<span className='inline-flex shrink-0 items-center gap-1'>
<span
className={cn('size-1.5 rounded-full', rateDotClass(model.success_rate))}
aria-hidden='true'
/>
<span
className={cn(
'font-mono text-[11px] font-semibold tabular-nums',
rateTextClass(model.success_rate)
)}
>
{formatUptimePct(model.success_rate)}
) : (
hasData && (
<div>
<span className='text-muted-foreground mb-1 block text-[11px] font-medium'>
{t('Top models by traffic')}
</span>
<div className='grid grid-cols-1 gap-x-4 sm:grid-cols-2'>
{topModels.map((model) => (
<div
key={model.model_name}
className='flex items-center justify-between gap-2 rounded px-1.5 py-1'
>
<span className='min-w-0 flex-1 truncate font-mono text-[11px]'>
{model.model_name}
</span>
</span>
</div>
))}
<span className='inline-flex shrink-0 items-center gap-1'>
<span
className={cn(
'size-1.5 rounded-full',
rateDotClass(model.success_rate)
)}
aria-hidden='true'
/>
<span
className={cn(
'font-mono text-[11px] font-semibold tabular-nums',
rateTextClass(model.success_rate)
)}
>
{formatUptimePct(model.success_rate)}
</span>
</span>
</div>
))}
</div>
</div>
</div>
)
)}
</div>
</section>
@@ -19,12 +19,7 @@ For commercial licensing, please contact support@quantumnous.com
import { useMemo } from 'react'
import { useQuery } from '@tanstack/react-query'
import { Link } from '@tanstack/react-router'
import {
ArrowRight,
Flame,
ShieldCheck,
TrendingDown,
} from 'lucide-react'
import { ArrowRight, Flame, ShieldCheck, TrendingDown } from 'lucide-react'
import { useTranslation } from 'react-i18next'
import { useAuthStore } from '@/stores/auth-store'
import { getCurrencyLabel, isCurrencyDisplayEnabled } from '@/lib/currency'
@@ -102,7 +97,10 @@ function getSummarySparkline(
return undefined
}
function getRunwayDays(remainQuota: number, recentUsage: number): number | null {
function getRunwayDays(
remainQuota: number,
recentUsage: number
): number | null {
if (remainQuota <= 0 || recentUsage <= 0) return null
const days = remainQuota / recentUsage
if (!Number.isFinite(days)) return null
@@ -111,10 +109,7 @@ function getRunwayDays(remainQuota: number, recentUsage: number): number | null
type HealthLevel = 'healthy' | 'caution' | 'critical'
function getHealthLevel(
remainQuota: number,
recentUsage: number
): HealthLevel {
function getHealthLevel(remainQuota: number, recentUsage: number): HealthLevel {
if (remainQuota <= 0) return 'critical'
const days = getRunwayDays(remainQuota, recentUsage)
if (days !== null && days < 3) return 'caution'
@@ -139,7 +134,6 @@ const HEALTH_CONFIG: Record<
},
}
export function SummaryCards() {
const { t } = useTranslation()
const user = useAuthStore((state) => state.auth.user)
@@ -341,10 +335,7 @@ export function SummaryCards() {
</div>
</div>
<Button
className='justify-between'
render={<Link to='/wallet' />}
>
<Button className='justify-between' render={<Link to='/wallet' />}>
<span>{t('Wallet')}</span>
<ArrowRight data-icon='inline-end' />
</Button>
@@ -96,8 +96,7 @@ function buildLineSparkline(values?: number[]) {
sanitized.length === 1
? width / 2
: (index / (sanitized.length - 1)) * width
const normalized =
range > 0 ? (value - min) / range : max > 0 ? 0.5 : 0
const normalized = range > 0 ? (value - min) / range : max > 0 ? 0.5 : 0
const y = height - padding - normalized * (height - padding * 2)
return { x, y }
+1 -1
View File
@@ -236,7 +236,7 @@ export function Dashboard() {
<div className='flex flex-wrap items-center justify-between gap-1.5 sm:gap-2'>
{showSectionTabs ? (
<Tabs value={activeSection} onValueChange={handleSectionChange}>
<TabsList className='group-data-horizontal/tabs:h-auto max-w-full flex-wrap justify-start'>
<TabsList className='max-w-full flex-wrap justify-start group-data-horizontal/tabs:h-auto'>
{visibleSections.map((section) => (
<TabsTrigger key={section} value={section}>
{t(SECTION_META[section].titleKey)}