feat(webui): config forms for host + connections widgets (B2)
Adds the gear config form to two more overview widgets (stat tiles stay form-less, per plan): - 主机资源 (host): toggle which resource panels show (CPU / 内存 / 运行进程); the grid column count tracks the visible panel count, and an all-off config falls back to all-on (no empty card). - OneBot 连接 (connections): filter by account nickname/uin, an "仅显示异常端点" toggle (drops healthy adapters and emptied accounts), and sort by 默认 / 名称 / 异常优先 (worst status first). Both register in CONFIGURABLE_WIDGETS with parse* validators, render via the existing dialog, and surface on mobile through the same per-widget config map.
This commit is contained in:
3 files changed
+222
-82
No files matched your search
@@ -22,12 +22,14 @@ import { reconcileLayoutItems, useLayout } from '@/contexts/LayoutContext';
|
|||||||
import { useMediaQuery } from '@/hooks/use-media-query';
|
import { useMediaQuery } from '@/hooks/use-media-query';
|
||||||
import {
|
import {
|
||||||
CONFIGURABLE_WIDGETS, GRID_COLS, MOBILE_WIDGET_IDS, mobileHeightOf,
|
CONFIGURABLE_WIDGETS, GRID_COLS, MOBILE_WIDGET_IDS, mobileHeightOf,
|
||||||
parseAlertsConfig, parseSessionsConfig, widgetLabel,
|
parseAlertsConfig, parseConnectionsConfig, parseHostConfig, parseSessionsConfig, widgetLabel,
|
||||||
type AlertsConfig, type SessionsConfig,
|
type AlertsConfig, type ConnectionsConfig, type HostConfig, type SessionsConfig,
|
||||||
} from '@/lib/dashboard-layout';
|
} from '@/lib/dashboard-layout';
|
||||||
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog';
|
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog';
|
||||||
import { DashboardGrid, type GridCoord } from '@/components/pages/dashboard-grid';
|
import { DashboardGrid, type GridCoord } from '@/components/pages/dashboard-grid';
|
||||||
import { AlertsConfigForm, SessionsConfigForm } from '@/components/pages/widget-config-forms';
|
import {
|
||||||
|
AlertsConfigForm, ConnectionsConfigForm, HostConfigForm, SessionsConfigForm,
|
||||||
|
} from '@/components/pages/widget-config-forms';
|
||||||
|
|
||||||
function qqAvatarUrl(uin: string) {
|
function qqAvatarUrl(uin: string) {
|
||||||
return `/avatar/${encodeURIComponent(uin)}`;
|
return `/avatar/${encodeURIComponent(uin)}`;
|
||||||
@@ -36,9 +38,9 @@ function qqAvatarUrl(uin: string) {
|
|||||||
function renderWidget(block: UiLayoutItem): ReactNode {
|
function renderWidget(block: UiLayoutItem): ReactNode {
|
||||||
if (block.id.startsWith('stat:')) return <StatTileWidget id={block.id} />;
|
if (block.id.startsWith('stat:')) return <StatTileWidget id={block.id} />;
|
||||||
switch (block.id) {
|
switch (block.id) {
|
||||||
case 'connections': return <ConnectionsBlock />;
|
case 'connections': return <ConnectionsBlock config={parseConnectionsConfig(block.config)} />;
|
||||||
case 'alerts': return <RecentAlertsCard config={parseAlertsConfig(block.config)} />;
|
case 'alerts': return <RecentAlertsCard config={parseAlertsConfig(block.config)} />;
|
||||||
case 'host': return <HostBlock />;
|
case 'host': return <HostBlock config={parseHostConfig(block.config)} />;
|
||||||
case 'sessions': return <SessionsBlock config={parseSessionsConfig(block.config)} />;
|
case 'sessions': return <SessionsBlock config={parseSessionsConfig(block.config)} />;
|
||||||
default: return null;
|
default: return null;
|
||||||
}
|
}
|
||||||
@@ -180,6 +182,8 @@ export function OverviewPage() {
|
|||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
{configBlock?.id === 'alerts' && <AlertsConfigForm config={configBlock.config} onChange={(c) => setBlockConfig('alerts', c)} />}
|
{configBlock?.id === 'alerts' && <AlertsConfigForm config={configBlock.config} onChange={(c) => setBlockConfig('alerts', c)} />}
|
||||||
{configBlock?.id === 'sessions' && <SessionsConfigForm config={configBlock.config} onChange={(c) => setBlockConfig('sessions', c)} />}
|
{configBlock?.id === 'sessions' && <SessionsConfigForm config={configBlock.config} onChange={(c) => setBlockConfig('sessions', c)} />}
|
||||||
|
{configBlock?.id === 'host' && <HostConfigForm config={configBlock.config} onChange={(c) => setBlockConfig('host', c)} />}
|
||||||
|
{configBlock?.id === 'connections' && <ConnectionsConfigForm config={configBlock.config} onChange={(c) => setBlockConfig('connections', c)} />}
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
</div>
|
</div>
|
||||||
@@ -385,8 +389,11 @@ function StatTileWidget({ id }: { id: string }) {
|
|||||||
|
|
||||||
// ─────────────── host resources ───────────────
|
// ─────────────── host resources ───────────────
|
||||||
|
|
||||||
function HostBlock() {
|
const HOST_GRID_COLS: Record<number, string> = { 1: 'lg:grid-cols-1', 2: 'lg:grid-cols-2', 3: 'lg:grid-cols-3' };
|
||||||
|
|
||||||
|
function HostBlock({ config }: { config: HostConfig }) {
|
||||||
const { systemInfo, refreshSystem } = useAppState();
|
const { systemInfo, refreshSystem } = useAppState();
|
||||||
|
const panelCount = [config.cpu, config.memory, config.runtime].filter(Boolean).length;
|
||||||
return (
|
return (
|
||||||
<Card className="flex h-full flex-col">
|
<Card className="flex h-full flex-col">
|
||||||
<CardHeader className="flex flex-row items-center justify-between gap-3 space-y-0">
|
<CardHeader className="flex flex-row items-center justify-between gap-3 space-y-0">
|
||||||
@@ -402,84 +409,90 @@ function HostBlock() {
|
|||||||
<RefreshCw className="size-3.5" /> 刷新
|
<RefreshCw className="size-3.5" /> 刷新
|
||||||
</Button>
|
</Button>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="grid flex-1 grid-cols-1 gap-4 lg:grid-cols-3">
|
<CardContent className={cn('grid flex-1 grid-cols-1 gap-4', HOST_GRID_COLS[panelCount] ?? 'lg:grid-cols-3')}>
|
||||||
{/* CPU */}
|
{/* CPU */}
|
||||||
<div className="rounded-xl border bg-card/40 p-4">
|
{config.cpu && (
|
||||||
<div className="mb-2 flex items-center justify-between">
|
<div className="rounded-xl border bg-card/40 p-4">
|
||||||
<div className="flex items-center gap-2">
|
<div className="mb-2 flex items-center justify-between">
|
||||||
<Cpu className="size-4 text-primary" />
|
<div className="flex items-center gap-2">
|
||||||
<span className="text-sm font-semibold">CPU 使用率</span>
|
<Cpu className="size-4 text-primary" />
|
||||||
|
<span className="text-sm font-semibold">CPU 使用率</span>
|
||||||
|
</div>
|
||||||
|
<span className="text-sm font-semibold tabular-nums text-primary">
|
||||||
|
{systemInfo ? `${systemInfo.cpu.average.toFixed(1)}%` : '—'}
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<span className="text-sm font-semibold tabular-nums text-primary">
|
<Progress value={systemInfo?.cpu.average ?? 0} />
|
||||||
{systemInfo ? `${systemInfo.cpu.average.toFixed(1)}%` : '—'}
|
<p className="mt-2 text-[11px] text-muted-foreground">
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<Progress value={systemInfo?.cpu.average ?? 0} />
|
|
||||||
<p className="mt-2 text-[11px] text-muted-foreground">
|
|
||||||
负载: {systemInfo ? systemInfo.cpu.loadAvg.map((v) => v.toFixed(2)).join(' / ') : '—'}
|
负载: {systemInfo ? systemInfo.cpu.loadAvg.map((v) => v.toFixed(2)).join(' / ') : '—'}
|
||||||
</p>
|
</p>
|
||||||
{systemInfo && systemInfo.cpu.perCore.length > 0 && (
|
{systemInfo && systemInfo.cpu.perCore.length > 0 && (
|
||||||
<div className="mt-3 grid grid-cols-8 gap-1">
|
<div className="mt-3 grid grid-cols-8 gap-1">
|
||||||
{systemInfo.cpu.perCore.map((p, i) => (
|
{systemInfo.cpu.perCore.map((p, i) => (
|
||||||
<div key={i} title={`Core ${i}: ${p.toFixed(1)}%`} className="h-6 rounded-sm bg-muted overflow-hidden flex items-end">
|
<div key={i} title={`Core ${i}: ${p.toFixed(1)}%`} className="h-6 rounded-sm bg-muted overflow-hidden flex items-end">
|
||||||
<div className="w-full bg-primary/70 transition-[height] duration-500" style={{ height: `${Math.max(4, p)}%` }} />
|
<div className="w-full bg-primary/70 transition-[height] duration-500" style={{ height: `${Math.max(4, p)}%` }} />
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
{/* Memory */}
|
{/* Memory */}
|
||||||
<div className="rounded-xl border bg-card/40 p-4">
|
{config.memory && (
|
||||||
<div className="mb-2 flex items-center justify-between">
|
<div className="rounded-xl border bg-card/40 p-4">
|
||||||
<div className="flex items-center gap-2">
|
<div className="mb-2 flex items-center justify-between">
|
||||||
<MemoryStick className="size-4 text-primary" />
|
<div className="flex items-center gap-2">
|
||||||
<span className="text-sm font-semibold">内存使用</span>
|
<MemoryStick className="size-4 text-primary" />
|
||||||
|
<span className="text-sm font-semibold">内存使用</span>
|
||||||
|
</div>
|
||||||
|
<span className="text-sm font-semibold tabular-nums text-primary">
|
||||||
|
{systemInfo ? `${systemInfo.memory.usagePercent.toFixed(1)}%` : '—'}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<Progress value={systemInfo?.memory.usagePercent ?? 0} />
|
||||||
|
<div className="mt-3 flex items-center justify-between text-[11px] text-muted-foreground tabular-nums">
|
||||||
|
<span>已用 {systemInfo ? formatBytes(systemInfo.memory.used) : '—'}</span>
|
||||||
|
<span>共 {systemInfo ? formatBytes(systemInfo.memory.total) : '—'}</span>
|
||||||
</div>
|
</div>
|
||||||
<span className="text-sm font-semibold tabular-nums text-primary">
|
|
||||||
{systemInfo ? `${systemInfo.memory.usagePercent.toFixed(1)}%` : '—'}
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
<Progress value={systemInfo?.memory.usagePercent ?? 0} />
|
)}
|
||||||
<div className="mt-3 flex items-center justify-between text-[11px] text-muted-foreground tabular-nums">
|
|
||||||
<span>已用 {systemInfo ? formatBytes(systemInfo.memory.used) : '—'}</span>
|
|
||||||
<span>共 {systemInfo ? formatBytes(systemInfo.memory.total) : '—'}</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{/* Runtime */}
|
{/* Runtime */}
|
||||||
<div className="rounded-xl border bg-card/40 p-4">
|
{config.runtime && (
|
||||||
<div className="mb-2 flex items-center justify-between">
|
<div className="rounded-xl border bg-card/40 p-4">
|
||||||
<div className="flex items-center gap-2">
|
<div className="mb-2 flex items-center justify-between">
|
||||||
<Server className="size-4 text-primary" />
|
<div className="flex items-center gap-2">
|
||||||
<span className="text-sm font-semibold">运行进程</span>
|
<Server className="size-4 text-primary" />
|
||||||
|
<span className="text-sm font-semibold">运行进程</span>
|
||||||
|
</div>
|
||||||
|
<span className="text-sm font-semibold tabular-nums text-primary">
|
||||||
|
{systemInfo ? `PID ${systemInfo.runtime.pid}` : '—'}
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<span className="text-sm font-semibold tabular-nums text-primary">
|
{!systemInfo ? (
|
||||||
{systemInfo ? `PID ${systemInfo.runtime.pid}` : '—'}
|
<div className="space-y-2">
|
||||||
</span>
|
<Skeleton className="h-4 w-3/4" />
|
||||||
|
<Skeleton className="h-4 w-1/2" />
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="space-y-1.5 text-xs">
|
||||||
|
<div className="flex items-center justify-between rounded-md bg-background/60 px-2 py-1.5">
|
||||||
|
<span className="text-muted-foreground">RSS</span>
|
||||||
|
<span className="font-medium tabular-nums">{formatBytes(systemInfo.runtime.rss)}</span>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center justify-between rounded-md bg-background/60 px-2 py-1.5">
|
||||||
|
<span className="text-muted-foreground">堆内存</span>
|
||||||
|
<span className="font-medium tabular-nums">
|
||||||
|
{formatBytes(systemInfo.runtime.heapUsed)} / {formatBytes(systemInfo.runtime.heapTotal)}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center justify-between rounded-md bg-background/60 px-2 py-1.5">
|
||||||
|
<span className="text-muted-foreground">外部内存</span>
|
||||||
|
<span className="font-medium tabular-nums">{formatBytes(systemInfo.runtime.external)}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
{!systemInfo ? (
|
)}
|
||||||
<div className="space-y-2">
|
|
||||||
<Skeleton className="h-4 w-3/4" />
|
|
||||||
<Skeleton className="h-4 w-1/2" />
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<div className="space-y-1.5 text-xs">
|
|
||||||
<div className="flex items-center justify-between rounded-md bg-background/60 px-2 py-1.5">
|
|
||||||
<span className="text-muted-foreground">RSS</span>
|
|
||||||
<span className="font-medium tabular-nums">{formatBytes(systemInfo.runtime.rss)}</span>
|
|
||||||
</div>
|
|
||||||
<div className="flex items-center justify-between rounded-md bg-background/60 px-2 py-1.5">
|
|
||||||
<span className="text-muted-foreground">堆内存</span>
|
|
||||||
<span className="font-medium tabular-nums">
|
|
||||||
{formatBytes(systemInfo.runtime.heapUsed)} / {formatBytes(systemInfo.runtime.heapTotal)}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div className="flex items-center justify-between rounded-md bg-background/60 px-2 py-1.5">
|
|
||||||
<span className="text-muted-foreground">外部内存</span>
|
|
||||||
<span className="font-medium tabular-nums">{formatBytes(systemInfo.runtime.external)}</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
@@ -561,25 +574,50 @@ const ADAPTER_KIND_LABEL: Record<AdapterStatus['kind'], string> = {
|
|||||||
httpServer: 'HTTP 服务端', httpClient: 'HTTP 上报', wsServer: 'WS 服务端', wsClient: 'WS 客户端',
|
httpServer: 'HTTP 服务端', httpClient: 'HTTP 上报', wsServer: 'WS 服务端', wsClient: 'WS 客户端',
|
||||||
};
|
};
|
||||||
|
|
||||||
function ConnectionsBlock() {
|
// Worst-status-first ordering (down → warn → disabled → ok).
|
||||||
|
const CONN_STATUS_RANK: Record<AdapterStatusLevel, number> = { down: 0, warn: 1, disabled: 2, ok: 3 };
|
||||||
|
|
||||||
|
function ConnectionsBlock({ config }: { config: ConnectionsConfig }) {
|
||||||
const { connections } = useAppState();
|
const { connections } = useAppState();
|
||||||
|
const list = useMemo(() => {
|
||||||
|
const f = config.filter.trim().toLowerCase();
|
||||||
|
// Optionally drop healthy adapters, then accounts left with none.
|
||||||
|
let arr = connections.map((acc) => ({
|
||||||
|
...acc,
|
||||||
|
adapters: config.onlyIssues ? acc.adapters.filter((a) => a.status !== 'ok') : acc.adapters,
|
||||||
|
}));
|
||||||
|
if (config.onlyIssues) arr = arr.filter((acc) => acc.adapters.length > 0);
|
||||||
|
if (f) arr = arr.filter((acc) => (acc.nickname ?? '').toLowerCase().includes(f) || acc.uin.includes(f));
|
||||||
|
if (config.sort === 'name') {
|
||||||
|
arr = [...arr].sort((a, b) => (a.nickname || a.uin).localeCompare(b.nickname || b.uin));
|
||||||
|
} else if (config.sort === 'status') {
|
||||||
|
const worst = (acc: typeof arr[number]) =>
|
||||||
|
acc.adapters.reduce((m, a) => Math.min(m, CONN_STATUS_RANK[a.status]), 99);
|
||||||
|
arr = [...arr].sort((a, b) => worst(a) - worst(b));
|
||||||
|
}
|
||||||
|
return arr;
|
||||||
|
}, [connections, config.filter, config.onlyIssues, config.sort]);
|
||||||
|
|
||||||
|
const filtered = config.filter.trim() !== '' || config.onlyIssues;
|
||||||
return (
|
return (
|
||||||
<Card className="flex h-full flex-col">
|
<Card className="flex h-full flex-col">
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle className="flex items-center gap-2">
|
<CardTitle className="flex items-center gap-2">
|
||||||
<Cable className="size-4 text-primary" /> OneBot 连接
|
<Cable className="size-4 text-primary" /> OneBot 连接
|
||||||
</CardTitle>
|
</CardTitle>
|
||||||
<CardDescription>各账号协议端点的实时连接状态</CardDescription>
|
<CardDescription>
|
||||||
|
各账号协议端点的实时连接状态{config.onlyIssues ? ' · 仅异常' : ''}{config.filter.trim() ? ` · 筛选:${config.filter.trim()}` : ''}
|
||||||
|
</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="min-h-0 flex-1 overflow-auto">
|
<CardContent className="min-h-0 flex-1 overflow-auto">
|
||||||
{connections.length === 0 ? (
|
{list.length === 0 ? (
|
||||||
<div className="flex flex-col items-center justify-center gap-2 rounded-xl border border-dashed py-10 text-muted-foreground">
|
<div className="flex flex-col items-center justify-center gap-2 rounded-xl border border-dashed py-10 text-muted-foreground">
|
||||||
<Cable className="size-8 opacity-40" strokeWidth={1.5} />
|
<Cable className="size-8 opacity-40" strokeWidth={1.5} />
|
||||||
<p className="text-sm">暂无已接入的账号实例</p>
|
<p className="text-sm">{filtered ? '无匹配的连接' : '暂无已接入的账号实例'}</p>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="flex flex-col gap-4">
|
<div className="flex flex-col gap-4">
|
||||||
{connections.map((acc) => (
|
{list.map((acc) => (
|
||||||
<div key={acc.uin} className="flex flex-col gap-2">
|
<div key={acc.uin} className="flex flex-col gap-2">
|
||||||
<div className="flex items-baseline gap-2">
|
<div className="flex items-baseline gap-2">
|
||||||
<span className="text-sm font-semibold">{acc.nickname || acc.uin}</span>
|
<span className="text-sm font-semibold">{acc.nickname || acc.uin}</span>
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import { Input } from '@/components/ui/input';
|
import { Input } from '@/components/ui/input';
|
||||||
|
import { ToggleSwitch } from '@/components/ui/toggle-switch';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
import { ALL_LOG_LEVELS, parseAlertsConfig, parseSessionsConfig } from '@/lib/dashboard-layout';
|
import {
|
||||||
|
ALL_LOG_LEVELS, parseAlertsConfig, parseConnectionsConfig, parseHostConfig, parseSessionsConfig,
|
||||||
|
} from '@/lib/dashboard-layout';
|
||||||
|
|
||||||
// Per-widget config forms, shown inside a dialog opened from a dashboard
|
// Per-widget config forms, shown inside a dialog opened from a dashboard
|
||||||
// widget's edit-overlay gear. `config` is the widget's opaque block.config;
|
// widget's edit-overlay gear. `config` is the widget's opaque block.config;
|
||||||
@@ -83,3 +86,72 @@ export function SessionsConfigForm({ config, onChange }: FormProps) {
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const HOST_PANELS: { key: 'cpu' | 'memory' | 'runtime'; label: string }[] = [
|
||||||
|
{ key: 'cpu', label: 'CPU 使用率' },
|
||||||
|
{ key: 'memory', label: '内存使用' },
|
||||||
|
{ key: 'runtime', label: '运行进程' },
|
||||||
|
];
|
||||||
|
|
||||||
|
export function HostConfigForm({ config, onChange }: FormProps) {
|
||||||
|
const c = parseHostConfig(config);
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col gap-3">
|
||||||
|
<span className="text-sm text-muted-foreground">显示的指标</span>
|
||||||
|
{HOST_PANELS.map((p) => (
|
||||||
|
<label key={p.key} className="flex items-center justify-between gap-3 text-sm">
|
||||||
|
<span>{p.label}</span>
|
||||||
|
<ToggleSwitch
|
||||||
|
value={c[p.key]}
|
||||||
|
ariaLabel={p.label}
|
||||||
|
onChange={(v) => {
|
||||||
|
// Keep at least one panel on (an all-off card is empty).
|
||||||
|
const next = { ...c, [p.key]: v };
|
||||||
|
if (next.cpu || next.memory || next.runtime) onChange({ [p.key]: v });
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const CONN_SORTS: { key: 'default' | 'name' | 'status'; label: string }[] = [
|
||||||
|
{ key: 'default', label: '默认' },
|
||||||
|
{ key: 'name', label: '名称' },
|
||||||
|
{ key: 'status', label: '异常优先' },
|
||||||
|
];
|
||||||
|
|
||||||
|
export function ConnectionsConfigForm({ config, onChange }: FormProps) {
|
||||||
|
const c = parseConnectionsConfig(config);
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col gap-4">
|
||||||
|
<div className="flex flex-col gap-1.5">
|
||||||
|
<span className="text-sm text-muted-foreground">排序</span>
|
||||||
|
<div className="flex flex-wrap gap-1.5">
|
||||||
|
{CONN_SORTS.map((s) => (
|
||||||
|
<button
|
||||||
|
key={s.key}
|
||||||
|
type="button"
|
||||||
|
onClick={() => onChange({ sort: s.key })}
|
||||||
|
className={cn(
|
||||||
|
'rounded-md border px-2.5 py-1 text-xs transition-colors cursor-pointer',
|
||||||
|
c.sort === s.key ? 'border-primary bg-primary/10 text-primary' : 'border-border text-muted-foreground hover:bg-accent/40',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{s.label}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<label className="flex items-center justify-between gap-3 text-sm">
|
||||||
|
<span className="text-muted-foreground">仅显示异常端点</span>
|
||||||
|
<ToggleSwitch value={c.onlyIssues} ariaLabel="仅显示异常端点" onChange={(v) => onChange({ onlyIssues: v })} />
|
||||||
|
</label>
|
||||||
|
<label className="flex flex-col gap-1.5 text-sm">
|
||||||
|
<span className="text-muted-foreground">筛选(账号昵称 / QQ 号)</span>
|
||||||
|
<Input value={c.filter} placeholder="留空显示全部" maxLength={100} onChange={(e) => onChange({ filter: e.target.value })} className="h-8" />
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -123,12 +123,18 @@ export const ALL_LOG_LEVELS: LogLevel[] = ['trace', 'debug', 'info', 'success',
|
|||||||
|
|
||||||
export interface AlertsConfig { count: number; levels: LogLevel[] }
|
export interface AlertsConfig { count: number; levels: LogLevel[] }
|
||||||
export interface SessionsConfig { sort: 'recent' | 'uin' | 'nickname'; filter: string }
|
export interface SessionsConfig { sort: 'recent' | 'uin' | 'nickname'; filter: string }
|
||||||
|
/** Host widget: which resource sub-panels to show. */
|
||||||
|
export interface HostConfig { cpu: boolean; memory: boolean; runtime: boolean }
|
||||||
|
/** Connections widget: filter + sort + issues-only. */
|
||||||
|
export interface ConnectionsConfig { filter: string; onlyIssues: boolean; sort: 'default' | 'name' | 'status' }
|
||||||
|
|
||||||
export const DEFAULT_ALERTS_CONFIG: AlertsConfig = { count: 5, levels: ['warn', 'error'] };
|
export const DEFAULT_ALERTS_CONFIG: AlertsConfig = { count: 5, levels: ['warn', 'error'] };
|
||||||
export const DEFAULT_SESSIONS_CONFIG: SessionsConfig = { sort: 'recent', filter: '' };
|
export const DEFAULT_SESSIONS_CONFIG: SessionsConfig = { sort: 'recent', filter: '' };
|
||||||
|
export const DEFAULT_HOST_CONFIG: HostConfig = { cpu: true, memory: true, runtime: true };
|
||||||
|
export const DEFAULT_CONNECTIONS_CONFIG: ConnectionsConfig = { filter: '', onlyIssues: false, sort: 'default' };
|
||||||
|
|
||||||
/** Widgets that expose a config form (gear) in the layout editor. */
|
/** Widgets that expose a config form (gear) in the layout editor. */
|
||||||
export const CONFIGURABLE_WIDGETS = new Set(['alerts', 'sessions']);
|
export const CONFIGURABLE_WIDGETS = new Set(['alerts', 'sessions', 'host', 'connections']);
|
||||||
|
|
||||||
export function parseAlertsConfig(config: Record<string, unknown> | undefined): AlertsConfig {
|
export function parseAlertsConfig(config: Record<string, unknown> | undefined): AlertsConfig {
|
||||||
const c = config ?? {};
|
const c = config ?? {};
|
||||||
@@ -149,3 +155,27 @@ export function parseSessionsConfig(config: Record<string, unknown> | undefined)
|
|||||||
const filter = typeof c.filter === 'string' ? c.filter.slice(0, 100) : '';
|
const filter = typeof c.filter === 'string' ? c.filter.slice(0, 100) : '';
|
||||||
return { sort, filter };
|
return { sort, filter };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function parseHostConfig(config: Record<string, unknown> | undefined): HostConfig {
|
||||||
|
const c = config ?? {};
|
||||||
|
const bool = (v: unknown, d: boolean) => (typeof v === 'boolean' ? v : d);
|
||||||
|
const cfg = {
|
||||||
|
cpu: bool(c.cpu, true),
|
||||||
|
memory: bool(c.memory, true),
|
||||||
|
runtime: bool(c.runtime, true),
|
||||||
|
};
|
||||||
|
// Never let every panel be hidden — that leaves an empty card; fall back to all.
|
||||||
|
return cfg.cpu || cfg.memory || cfg.runtime ? cfg : { ...DEFAULT_HOST_CONFIG };
|
||||||
|
}
|
||||||
|
|
||||||
|
export function parseConnectionsConfig(config: Record<string, unknown> | undefined): ConnectionsConfig {
|
||||||
|
const c = config ?? {};
|
||||||
|
const sort = c.sort === 'name' || c.sort === 'status' || c.sort === 'default'
|
||||||
|
? c.sort
|
||||||
|
: DEFAULT_CONNECTIONS_CONFIG.sort;
|
||||||
|
return {
|
||||||
|
filter: typeof c.filter === 'string' ? c.filter.slice(0, 100) : '',
|
||||||
|
onlyIssues: typeof c.onlyIssues === 'boolean' ? c.onlyIssues : false,
|
||||||
|
sort,
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in new issue
Block a user