From f3324371ecfdf0810488b00fc3afa6699ecd882f Mon Sep 17 00:00:00 2001 From: Zakk Date: Tue, 15 Sep 2026 05:44:31 +1000 Subject: [PATCH] feat(ui): bring the remaining pages into the themed kit Port tables, forms, dialogs, tabs and detail cards to the themed pages. Align node tiles, palette labels and control spacing across the pages. --- src/rp/RuleDialog.tsx | 25 ++++++++ src/rp/Shell.tsx | 30 ++++++---- src/rp/pages/Clients.tsx | 18 ++++++ src/rp/pages/ConfigPage.tsx | 56 +++++++++++++++++ src/rp/pages/Connections.tsx | 55 +++++++++++++++++ src/rp/pages/Dns.tsx | 42 +++++++++++++ src/rp/pages/Events.tsx | 32 ++++++++++ src/rp/pages/Overview.tsx | 48 +++++++++++++++ src/rp/pages/Policies.tsx | 41 +++++++++++++ src/rp/pages/Resources.tsx | 33 ++++++++++ src/rp/pages/Rules.tsx | 41 +++++++++++++ src/rp/pages/types.ts | 2 + src/rp/theme.css | 112 ++++++++++++++++++++++++++++++---- src/rp/ui.tsx | 113 ++++++++++++++++++++++++++++++++++- 14 files changed, 624 insertions(+), 24 deletions(-) create mode 100644 src/rp/RuleDialog.tsx create mode 100644 src/rp/pages/Clients.tsx create mode 100644 src/rp/pages/ConfigPage.tsx create mode 100644 src/rp/pages/Connections.tsx create mode 100644 src/rp/pages/Dns.tsx create mode 100644 src/rp/pages/Events.tsx create mode 100644 src/rp/pages/Overview.tsx create mode 100644 src/rp/pages/Policies.tsx create mode 100644 src/rp/pages/Resources.tsx create mode 100644 src/rp/pages/Rules.tsx create mode 100644 src/rp/pages/types.ts diff --git a/src/rp/RuleDialog.tsx b/src/rp/RuleDialog.tsx new file mode 100644 index 00000000..323d11e7 --- /dev/null +++ b/src/rp/RuleDialog.tsx @@ -0,0 +1,25 @@ +// "Add rule" dialog shared by connections, clients and rules, on the Rosé Pine kit. +import {useState, type ReactElement} from 'react'; +import {groups, runtime} from '../app/mock'; +import {Button, LabeledSelect, ModalDialog, Switch, TextField, toast} from './ui'; + +export type Preset = {label: string, cond: string}; +export function RuleDialog({trigger, presets}: {trigger: ReactElement, presets: Preset[]}) { + const [i, setI] = useState('0'); + const [cond, setCond] = useState(presets[0].cond); + const [target, setTarget] = useState('direct'); + const [pos, setPos] = useState('before-fallback'); + const [must, setMust] = useState(false); + const targets = ['direct', 'block', ...groups.map(g => g.name)].map(t => ({id: t, label: t})); + return ( + <>}> +
+ {presets.length > 1 && { setI(k); setCond(presets[Number(k)].cond); }} items={presets.map((p, j) => ({id: String(j), label: p.label}))} />} + + + + must,全域與直連模式下仍然生效 +
+
+ ); +} diff --git a/src/rp/Shell.tsx b/src/rp/Shell.tsx index c9fddd82..966d413d 100644 --- a/src/rp/Shell.tsx +++ b/src/rp/Shell.tsx @@ -1,5 +1,5 @@ // Rosé Pine shell: same frame as the S2 panel (top bar, side nav, rounded main), plain CSS and react-aria-components. -import {useEffect, useState} from 'react'; +import {useEffect, useState, type ReactElement} from 'react'; import {Button as RButton, Dialog, Modal, ModalOverlay, SearchField, Input, ListBox, ListBoxItem, ListBoxSection, Header} from 'react-aria-components'; import Search from '@react-spectrum/s2/icons/Search'; import Refresh from '@react-spectrum/s2/icons/Refresh'; @@ -22,18 +22,26 @@ import {LangContext, LANGS, readLang, useT, type Lang} from '../app/i18n'; import {conns, groups, rules} from '../app/mock'; import {Button, MenuButton} from './ui'; import {Activity} from './Activity'; -import {Provider} from '@react-spectrum/s2'; -import {ToastContainer} from '@react-spectrum/s2/Toast'; import Color from '@react-spectrum/s2/icons/Color'; -import {S2_LOCALE} from '../app/i18n'; -import {PAGES} from '../app/Shell'; +import {Overview} from './pages/Overview'; +import {Connections} from './pages/Connections'; +import {Clients} from './pages/Clients'; +import {Policies} from './pages/Policies'; +import {Rules} from './pages/Rules'; +import {Dns} from './pages/Dns'; +import {Resources} from './pages/Resources'; +import {ConfigPage} from './pages/ConfigPage'; +import {Events} from './pages/Events'; +import {Toasts} from './ui'; +import type {PageProps} from './pages/types'; +const PAGES: Record ReactElement> = {overview: Overview, connections: Connections, clients: Clients, policies: Policies, rules: Rules, dns: Dns, resources: Resources, config: ConfigPage, events: Events}; type Scheme = 'system' | 'light' | 'dark'; // A palette is a family plus its dark flavour; the light flavour is fixed per family (Dawn, Latte, Nord light). type PaletteId = 'rose-pine/main' | 'rose-pine/moon' | 'catppuccin/frappe' | 'catppuccin/macchiato' | 'catppuccin/mocha' | 'nord/nord'; const PALETTES: Array<{title: string, items: Array<{id: PaletteId, label: string, desc?: string}>}> = [ - {title: 'Rosé Pine', items: [{id: 'rose-pine/main', label: 'Rosé Pine', desc: 'Dawn'}, {id: 'rose-pine/moon', label: 'Moon', desc: 'Dawn'}]}, - {title: 'Catppuccin', items: [{id: 'catppuccin/frappe', label: 'Frappé', desc: 'Latte'}, {id: 'catppuccin/macchiato', label: 'Macchiato', desc: 'Latte'}, {id: 'catppuccin/mocha', label: 'Mocha', desc: 'Latte'}]}, + {title: 'Rosé Pine', items: [{id: 'rose-pine/moon', label: 'Moon', desc: '暗版較柔'}, {id: 'rose-pine/main', label: 'Main', desc: '暗版最深'}]}, + {title: 'Catppuccin', items: [{id: 'catppuccin/frappe', label: 'Frappé', desc: '暗版最淺'}, {id: 'catppuccin/macchiato', label: 'Macchiato', desc: '暗版'}, {id: 'catppuccin/mocha', label: 'Mocha', desc: '暗版最深'}]}, {title: 'Nord', items: [{id: 'nord/nord', label: 'Nord'}]} ]; const NAV: Array<[string, Array<[string, string, typeof Home]>]> = [ @@ -92,21 +100,21 @@ export function Shell() { const [searchOpen, setSearchOpen] = useState(false); useEffect(() => { const on = () => setRoute(location.hash.replace(/^#\/?/, '').split('?')[0] || 'activity'); addEventListener('hashchange', on); return () => removeEventListener('hashchange', on); }, []); useEffect(() => { const on = (e: KeyboardEvent) => { if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'k') { e.preventDefault(); setSearchOpen(true); } }; addEventListener('keydown', on); return () => removeEventListener('keydown', on); }, []); - const go = (p: string) => { location.hash = '#/' + p; }; + const go = (p: string, q?: string) => { location.hash = '#/' + p + (q ? '?' + q : ''); }; const pickLang = (l: Lang) => { setLang(l); try { localStorage.setItem('doona-lang', l); } catch { /* private mode */ } }; const mac = navigator.platform.startsWith('Mac'); return ( setSearchOpen(true)} mac={mac} /> setSearchOpen(false)} go={go} /> + ); } function Frame({lang, pickLang, ap, route, go, openSearch, mac}: {lang: Lang, pickLang: (l: Lang) => void, ap: ReturnType, route: string, go: (p: string) => void, openSearch: () => void, mac: boolean}) { const t = useT(); - const s2Page = PAGES[route]; - const S2Page = route === 'activity' ? null : s2Page?.[1]; + const Page = route === 'activity' ? null : PAGES[route]; const titleKey = NAV.flatMap(([, items]) => items).find(([k]) => k === route)?.[1] ?? 'nav.activity'; return (
@@ -135,7 +143,7 @@ function Frame({lang, pickLang, ap, route, go, openSearch, mac}: {lang: Lang, pi

{t(titleKey as 'nav.activity')}

- {S2Page ?
{ location.hash = h; }}}>
: } + {Page ? : }
diff --git a/src/rp/pages/Clients.tsx b/src/rp/pages/Clients.tsx new file mode 100644 index 00000000..21985a6a --- /dev/null +++ b/src/rp/pages/Clients.tsx @@ -0,0 +1,18 @@ +import Add from '@react-spectrum/s2/icons/Add'; +import LinkIcon from '@react-spectrum/s2/icons/Link'; +import {clients, runtime} from '../../app/mock'; +import {Button, DataTable} from '../ui'; +import {RuleDialog} from '../RuleDialog'; +import type {PageProps} from './types'; + +export function Clients({go}: PageProps) { + return ( +
+

從可見連線聚合,只列本次觀察({runtime.window})裡有連線的來源 IP,不持久;MAC 只在 eBPF 看得到時才有。不做 DHCP 清單、命名與累計流量。

+ ({...c, id: c.ip}))} + cols={[{id: 'ip', label: '來源 IP', width: 140, isRowHeader: true}, {id: 'mac', label: 'MAC', width: 190}, {id: 'active', label: '活動連線', width: 100}, {id: 'sampled', label: '採樣位元組', width: 120}, {id: 'first', label: '首次看到'}, {id: 'act', label: '操作', width: 230}]} + render={c => [{c.ip}, c.mac ? {c.mac} : '未知', c.active, c.sampled, c.firstSeen, + 加規則} presets={[{label: '來源 ' + c.ip, cond: 'sip(' + c.ip + ')'}, ...(c.mac ? [{label: 'MAC ' + c.mac, cond: 'mac(' + c.mac + ')'}] : [])]} />]} /> +
+ ); +} diff --git a/src/rp/pages/ConfigPage.tsx b/src/rp/pages/ConfigPage.tsx new file mode 100644 index 00000000..95575ccc --- /dev/null +++ b/src/rp/pages/ConfigPage.tsx @@ -0,0 +1,56 @@ +import {useState} from 'react'; +import {sources, diagnostics, restartItems, runtime} from '../../app/mock'; +import {Badge, Button, DaeLine, Frame, LabeledSelect, Line, Switch, TextArea, toast} from '../ui'; +import type {PageProps} from './types'; + +export function ConfigPage({query}: PageProps) { + const q = new URLSearchParams(query); + const wanted = sources.find(s => s.path.endsWith(q.get('src') || '#')); + const [srcId, setSrcId] = useState(wanted ? wanted.id : 'main'); + const [edit, setEdit] = useState(false); + const [text, setText] = useState(''); + const [dirty, setDirty] = useState(false); + const src = sources.find(s => s.id === srcId)!; + const errs = diagnostics.filter(d => d.source === src.id); + const startEdit = (on: boolean) => { setEdit(on); if (on) setText(src.lines.join('\n')); }; + return ( +
+
+
+
+
+ { setSrcId(k); setEdit(false); setDirty(false); }} items={sources.map(s => ({id: s.id, label: s.path}))} /> + 磁碟 r{runtime.diskRevision} + 執行中 r{runtime.activeRevision} + {dirty && 未儲存} +
+
+ + + +
+
+ {errs.map(e =>
第 {e.line} 行:{e.msg.split(';')[0]}{e.msg.split(';')[1]}
)} + {edit + ?