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
@@ -1,6 +1,9 @@
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { ToggleSwitch } from '@/components/ui/toggle-switch';
|
||||
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
|
||||
// widget's edit-overlay gear. `config` is the widget's opaque block.config;
|
||||
@@ -83,3 +86,72 @@ export function SessionsConfigForm({ config, onChange }: FormProps) {
|
||||
</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>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user