From 8a46e85672c1a8a41d8adc8396010b4fcbd964bb Mon Sep 17 00:00:00 2001 From: Willie Date: Tue, 17 Mar 2026 17:10:12 +0800 Subject: [PATCH] feat(ui): add Doctor Health Check page with status dashboard Add /doctor route with a health check dashboard that displays: - Summary cards for pass/warning/error counts - "All checks passed" success banner - Filter toggles to narrow by status - Expandable check rows with detail lists - Version info with update-available badge Wired to GET /api/doctor via the typed API client. --- ui/src/App.tsx | 2 + ui/src/api/client.ts | 30 ++++ ui/src/components/Layout.tsx | 2 + ui/src/lib/queryKeys.ts | 2 + ui/src/pages/DoctorPage.tsx | 260 +++++++++++++++++++++++++++++++++++ 5 files changed, 296 insertions(+) create mode 100644 ui/src/pages/DoctorPage.tsx diff --git a/ui/src/App.tsx b/ui/src/App.tsx index 5c555b6f4..ed3af532a 100644 --- a/ui/src/App.tsx +++ b/ui/src/App.tsx @@ -29,6 +29,7 @@ const AuditRulesPage = lazy(() => import('./pages/AuditRulesPage')); const LogPage = lazy(() => import('./pages/LogPage')); const ConfigPage = lazy(() => import('./pages/ConfigPage')); const FilterStudioPage = lazy(() => import('./pages/FilterStudioPage')); +const DoctorPage = lazy(() => import('./pages/DoctorPage')); function Lazy({ children }: { children: React.ReactNode }) { return }>{children}; @@ -65,6 +66,7 @@ export default function App() { } /> } /> } /> + } /> diff --git a/ui/src/api/client.ts b/ui/src/api/client.ts index c38da2572..adaddc6a8 100644 --- a/ui/src/api/client.ts +++ b/ui/src/api/client.ts @@ -408,6 +408,9 @@ export const api = { method: 'POST', body: JSON.stringify(opts ?? {}), }), + + // Doctor + doctor: () => apiFetch('/doctor'), }; // Types @@ -796,6 +799,33 @@ export interface CompiledRulesResponse { patterns: PatternGroup[]; } +// Doctor health check types +export interface DoctorCheck { + name: string; + status: 'pass' | 'warning' | 'error'; + message: string; + details?: string[]; +} + +export interface DoctorSummary { + total: number; + pass: number; + warnings: number; + errors: number; +} + +export interface DoctorVersion { + current: string; + latest?: string; + update_available: boolean; +} + +export interface DoctorResponse { + checks: DoctorCheck[]; + summary: DoctorSummary; + version?: DoctorVersion; +} + // Hub saved config types export interface HubSavedEntry { label: string; diff --git a/ui/src/components/Layout.tsx b/ui/src/components/Layout.tsx index 8383cfb5c..39d6149aa 100644 --- a/ui/src/components/Layout.tsx +++ b/ui/src/components/Layout.tsx @@ -22,6 +22,7 @@ import { Compass, ChevronUp, ChevronDown, + Stethoscope, } from 'lucide-react'; import { radius } from '../design'; import { useAppContext } from '../context/AppContext'; @@ -81,6 +82,7 @@ const navGroups: NavGroup[] = [ items: [ { to: '/log', icon: ScrollText, label: 'Log' }, { to: '/config', icon: Settings, label: 'Config' }, + { to: '/doctor', icon: Stethoscope, label: 'Health Check' }, ], }, ]; diff --git a/ui/src/lib/queryKeys.ts b/ui/src/lib/queryKeys.ts index 2bfeb3df8..9f3aef81b 100644 --- a/ui/src/lib/queryKeys.ts +++ b/ui/src/lib/queryKeys.ts @@ -38,6 +38,7 @@ export const queryKeys = { extras: ['extras'] as const, extrasDiff: (name?: string) => ['extras-diff', name ?? '__all'] as const, + doctor: ['doctor'] as const, }; // Stale times per data type @@ -57,4 +58,5 @@ export const staleTimes = { check: 60 * 1000, // 1min syncMatrix: 30 * 1000, // 30s — changes after filter edits extras: 30 * 1000, // 30s — fast-changing like diff + doctor: 60 * 1000, // 1min — health checks }; diff --git a/ui/src/pages/DoctorPage.tsx b/ui/src/pages/DoctorPage.tsx new file mode 100644 index 000000000..f1f4a3dd9 --- /dev/null +++ b/ui/src/pages/DoctorPage.tsx @@ -0,0 +1,260 @@ +import { useState, useMemo } from 'react'; +import { + Stethoscope, + RefreshCw, + CheckCircle2, + AlertTriangle, + XCircle, + ChevronDown, + ChevronRight, + ArrowUpCircle, + PartyPopper, +} from 'lucide-react'; +import { useQuery, useQueryClient } from '@tanstack/react-query'; +import { api } from '../api/client'; +import type { DoctorCheck, DoctorResponse } from '../api/client'; +import { queryKeys, staleTimes } from '../lib/queryKeys'; +import Card from '../components/Card'; +import Button from '../components/Button'; +import Badge from '../components/Badge'; +import PageHeader from '../components/PageHeader'; +import { PageSkeleton } from '../components/Skeleton'; +import { palette } from '../design'; + +type StatusFilter = 'all' | 'error' | 'warning' | 'pass'; + +function statusIcon(status: DoctorCheck['status'], size = 16) { + switch (status) { + case 'pass': + return ; + case 'warning': + return ; + case 'error': + return ; + } +} + +function statusBadgeVariant(status: DoctorCheck['status']): 'success' | 'warning' | 'danger' { + switch (status) { + case 'pass': return 'success'; + case 'warning': return 'warning'; + case 'error': return 'danger'; + } +} + +function CheckRow({ check }: { check: DoctorCheck }) { + const [expanded, setExpanded] = useState(false); + const hasDetails = check.details && check.details.length > 0; + + return ( +
+ + {expanded && hasDetails && ( +
+
    + {check.details!.map((detail, i) => ( +
  • + • + {detail} +
  • + ))} +
+
+ )} +
+ ); +} + +export default function DoctorPage() { + const queryClient = useQueryClient(); + const { data, isPending, error, isFetching, refetch } = useQuery({ + queryKey: queryKeys.doctor, + queryFn: () => api.doctor(), + staleTime: staleTimes.doctor, + }); + const [filter, setFilter] = useState('all'); + + const filteredChecks = useMemo(() => { + if (!data) return []; + if (filter === 'all') return data.checks; + return data.checks.filter((c) => c.status === filter); + }, [data, filter]); + + const allPassed = data && data.summary.errors === 0 && data.summary.warnings === 0; + + if (isPending) return ; + + if (error) { + return ( +
+ } + /> + +
+ Failed to load health check: {error instanceof Error ? error.message : 'Unknown error'} +
+
+
+ ); + } + + return ( +
+ } + subtitle="Diagnose your skillshare setup" + actions={ + + } + /> + + {/* Summary cards */} +
+ +
+
+ +
+
+
{data!.summary.pass}
+
Passed
+
+
+
+ +
+
+ +
+
+
{data!.summary.warnings}
+
Warnings
+
+
+
+ +
+
+ +
+
+
{data!.summary.errors}
+
Errors
+
+
+
+
+ + {/* All passed banner */} + {allPassed && ( + +
+ +
+
All checks passed!
+
+ Your skillshare setup is healthy. All {data!.summary.total} checks passed. +
+
+
+
+ )} + + {/* Filter toggles */} +
+ {(['all', 'error', 'warning', 'pass'] as StatusFilter[]).map((f) => { + const isActive = filter === f; + const count = f === 'all' + ? data!.summary.total + : f === 'error' + ? data!.summary.errors + : f === 'warning' + ? data!.summary.warnings + : data!.summary.pass; + return ( + + ); + })} +
+ + {/* Checks list */} + + {filteredChecks.length === 0 ? ( +
+ No checks match the selected filter. +
+ ) : ( + filteredChecks.map((check, i) => ( + + )) + )} +
+ + {/* Version info */} + {data!.version && ( + +
+
+
Version
+
+ Current: {data!.version.current} + {data!.version.latest && ( + <> · Latest: {data!.version.latest} + )} +
+
+ {data!.version.update_available && ( + + + Update available + + )} +
+
+ )} +
+ ); +}