From d6cbfc82d96b3276cb16bd6d0350f070c42744ed Mon Sep 17 00:00:00 2001 From: Willie Date: Wed, 11 Mar 2026 22:00:18 +0800 Subject: [PATCH] feat(ui): add sticky search/filters toolbar on SkillsPage, clean up LogPage Wrap search bar, sort dropdown, view toggle, and filter chips in a sticky container so they stay pinned while scrolling through skills in all three view modes (grid/grouped/table). Also clean up LogPage: remove unused imports, simplify status rendering from Badge to inline dot+text, add pagination page size control, and streamline section comments. --- ui/src/pages/LogPage.tsx | 424 ++++++++---------------------------- ui/src/pages/SkillsPage.tsx | 151 ++++++------- 2 files changed, 173 insertions(+), 402 deletions(-) diff --git a/ui/src/pages/LogPage.tsx b/ui/src/pages/LogPage.tsx index 4e0a28ff3..48b5f475c 100644 --- a/ui/src/pages/LogPage.tsx +++ b/ui/src/pages/LogPage.tsx @@ -1,5 +1,5 @@ import { useState, useEffect, useMemo } from 'react'; -import { ScrollText, Trash2, RefreshCw, Activity, Clock, Terminal, ShieldCheck } from 'lucide-react'; +import { ScrollText, Trash2, RefreshCw } from 'lucide-react'; import { useQuery, useQueryClient } from '@tanstack/react-query'; import { api } from '../api/client'; import type { LogEntry, LogStatsResponse } from '../api/client'; @@ -7,7 +7,6 @@ import { queryKeys, staleTimes } from '../lib/queryKeys'; import Card from '../components/Card'; import Button from '../components/Button'; import PageHeader from '../components/PageHeader'; -import Badge from '../components/Badge'; import ConfirmDialog from '../components/ConfirmDialog'; import EmptyState from '../components/EmptyState'; import { PageSkeleton } from '../components/Skeleton'; @@ -15,11 +14,8 @@ import { useToast } from '../components/Toast'; import { Select } from '../components/Input'; import SegmentedControl from '../components/SegmentedControl'; import Pagination from '../components/Pagination'; -import { radius, shadows } from '../design'; -/* ────────────────────────────────────────────────────────────────────── - * Constants & helpers - * ────────────────────────────────────────────────────────────────────── */ +/* ─── Types & Constants ─── */ type LogTab = 'all' | 'ops' | 'audit'; type TimeRange = '' | '1h' | '24h' | '7d' | '30d'; @@ -33,6 +29,9 @@ const TIME_RANGES: { label: string; value: TimeRange }[] = [ ]; const STATUS_OPTIONS = ['', 'ok', 'error', 'partial', 'blocked'] as const; +const PAGE_SIZES = [10, 25, 50] as const; + +/* ─── Helpers ─── */ function timeRangeToSince(range: TimeRange): string { if (!range) return ''; @@ -56,33 +55,14 @@ function statusColor(status: string): string { } } -function statusBadge(status: string) { - switch (status) { - case 'ok': - return ok; - case 'error': - return error; - case 'partial': - return partial; - case 'blocked': - return blocked; - default: - return {status}; - } -} - function formatTimestamp(ts: string): string { try { const d = new Date(ts); return d.toLocaleString(undefined, { - month: 'short', - day: 'numeric', - hour: '2-digit', - minute: '2-digit', + month: 'short', day: 'numeric', + hour: '2-digit', minute: '2-digit', }); - } catch { - return ts; - } + } catch { return ts; } } function formatDuration(ms?: number): string { @@ -91,6 +71,17 @@ function formatDuration(ms?: number): string { return `${(ms / 1000).toFixed(1)}s`; } +function timeAgo(ts: string): string { + const diff = Date.now() - new Date(ts).getTime(); + const mins = Math.floor(diff / 60000); + if (mins < 1) return 'just now'; + if (mins < 60) return `${mins}m ago`; + const hours = Math.floor(mins / 60); + if (hours < 24) return `${hours}h ago`; + const days = Math.floor(hours / 24); + return `${days}d ago`; +} + function asInt(v: unknown): number | undefined { if (typeof v === 'number' && Number.isFinite(v)) return Math.trunc(v); if (typeof v === 'string') { @@ -110,17 +101,14 @@ function asString(v: unknown): string | undefined { } function asStringArray(v: unknown): string[] { - if (Array.isArray(v)) { - return v.map((it) => String(it).trim()).filter(Boolean); - } + if (Array.isArray(v)) return v.map((it) => String(it).trim()).filter(Boolean); const s = asString(v); return s ? [s] : []; } function summarizeNames(names: string[], limit = 3): string { if (names.length <= limit) return names.join(', '); - const shown = names.slice(0, limit).join(', '); - return `${shown} (+${names.length - limit})`; + return `${names.slice(0, limit).join(', ')} (+${names.length - limit})`; } /* ── Detail formatters ─── */ @@ -176,25 +164,6 @@ function formatAuditDetail(args: Record): string { return parts.join(', '); } -type AuditSkillLists = { - failed: string[]; - warning: string[]; - low: string[]; - info: string[]; -}; - -function getAuditSkillLists(entry: LogEntry): AuditSkillLists { - if (entry.cmd !== 'audit' || !entry.args) { - return { failed: [], warning: [], low: [], info: [] }; - } - return { - failed: asStringArray(entry.args.failed_skills), - warning: asStringArray(entry.args.warning_skills), - low: asStringArray(entry.args.low_skills), - info: asStringArray(entry.args.info_skills), - }; -} - function formatUpdateDetail(args: Record): string { const parts: string[] = []; const mode = asString(args.mode); @@ -234,170 +203,12 @@ function formatDetail(entry: LogEntry): string { ? formatAuditDetail(entry.args) : formatGenericDetail(entry.args) : ''; - if (entry.msg && detail) return `${detail} (${entry.msg})`; + if (entry.msg && detail) return `${detail} — ${entry.msg}`; if (entry.msg) return entry.msg; return detail; } -function renderDetail(entry: LogEntry) { - const summary = formatDetail(entry); - const lists = getAuditSkillLists(entry); - - if (lists.failed.length === 0 && lists.warning.length === 0 && lists.low.length === 0 && lists.info.length === 0) { - return summary; - } - - return ( -
-
{summary}
- {lists.failed.length > 0 && ( -
- failed skills: {summarizeNames(lists.failed, 6)} -
- )} - {lists.warning.length > 0 && ( -
- warning skills: {summarizeNames(lists.warning, 6)} -
- )} - {lists.low.length > 0 && ( -
- low skills: {summarizeNames(lists.low, 6)} -
- )} - {lists.info.length > 0 && ( -
- info skills: {summarizeNames(lists.info, 6)} -
- )} -
- ); -} - -/* ────────────────────────────────────────────────────────────────────── - * LogStatsBar — summary stat cards - * ────────────────────────────────────────────────────────────────────── */ - -function LogStatsBar({ stats }: { stats: LogStatsResponse }) { - const commands = Object.entries(stats.by_command).sort((a, b) => b[1].total - a[1].total); - const rate = stats.total > 0 ? Math.round(stats.success_rate * 100) : 0; - - return ( -
- {/* Success rate */} -
= 90 ? 'var(--color-success)' : rate >= 70 ? 'var(--color-warning)' : 'var(--color-danger)', - boxShadow: shadows.sm, - }} - > -
= 90 ? 'var(--color-success)' : rate >= 70 ? 'var(--color-warning)' : 'var(--color-danger)', - color: rate >= 90 ? 'var(--color-success)' : rate >= 70 ? 'var(--color-warning)' : 'var(--color-danger)', - }} - > - -
-
-

= 90 ? 'var(--color-success)' : rate >= 70 ? 'var(--color-warning)' : 'var(--color-danger)', - }}> - {rate}% -

-

- {stats.total} total -

-
-
- - {/* Top commands */} - {commands.slice(0, 4).map(([cmd, cs]) => { - const hasErrors = cs.error > 0 || cs.blocked > 0; - return ( -
-
- {cmd === 'audit' ? : } -
-
-

- {cmd} -

-
- {cs.total} - {cs.ok > 0 && {cs.ok} ok} - {cs.error > 0 && {cs.error} err} - {cs.partial > 0 && {cs.partial} partial} -
-
-
- ); - })} - - {/* Last operation */} - {stats.last_operation && ( -
-
- -
-
-

- {stats.last_operation.cmd} -

-
- {statusBadge(stats.last_operation.status)} -
-
-
- )} -
- ); -} - -/* ────────────────────────────────────────────────────────────────────── - * LogTable — paginated table with status-colored left stripes - * ────────────────────────────────────────────────────────────────────── */ - -const PAGE_SIZES = [10, 25, 50] as const; +/* ─── LogTable — clean, minimal table ─── */ function LogTable({ entries }: { entries: LogEntry[] }) { const [page, setPage] = useState(0); @@ -412,15 +223,14 @@ function LogTable({ entries }: { entries: LogEntry[] }) { return (
- +
- - - - - - + + + + + + @@ -429,27 +239,25 @@ function LogTable({ entries }: { entries: LogEntry[] }) { key={`${entry.ts}-${entry.cmd}-${start + i}`} className="border-b border-dashed border-muted hover:bg-paper-warm/60 transition-colors" > - {/* Status stripe cell */} - - - - - - @@ -458,12 +266,11 @@ function LogTable({ entries }: { entries: LogEntry[] }) {
- TimeCommandDetailsStatusDuration
TimeCommandDetailsStatusDuration
-
-
+ {formatTimestamp(entry.ts)} + {entry.cmd} - {renderDetail(entry)} + + {formatDetail(entry) || —} - {statusBadge(entry.status)} + + + + {entry.status} + + {formatDuration(entry.ms)}
- {/* Pagination */} {entries.length > PAGE_SIZES[0] && ( setPage(p)} + onPageChange={setPage} rangeText={`${start + 1}–${Math.min(start + pageSize, entries.length)} of ${entries.length}`} pageSize={{ value: pageSize, @@ -476,34 +283,33 @@ function LogTable({ entries }: { entries: LogEntry[] }) { ); } -/* ────────────────────────────────────────────────────────────────────── - * Section — titled group of log entries - * ────────────────────────────────────────────────────────────────────── */ +/* ─── SummaryLine — compact stats in one line ─── */ + +function SummaryLine({ stats, filtered }: { stats?: LogStatsResponse; filtered: boolean }) { + if (!stats || stats.total === 0) return null; + + const rate = Math.round(stats.success_rate * 100); + const rateColor = rate >= 90 ? 'var(--color-success)' : rate >= 70 ? 'var(--color-warning)' : 'var(--color-danger)'; -function Section({ title, entries, emptyLabel, filtered }: { title: string; entries: LogEntry[]; emptyLabel: string; filtered?: boolean }) { return ( -
-

- {title} -

- {entries.length === 0 ? ( - - ) : ( - +

+ {rate}% + {' success · '} + {stats.total} entries + {stats.last_operation && ( + <> + {' · Last: '} + {stats.last_operation.cmd} + {' '} + {timeAgo(stats.last_operation.ts)} + )} -

+ {filtered && ' · filtered'} +

); } -/* ────────────────────────────────────────────────────────────────────── - * LogPage — main page - * ────────────────────────────────────────────────────────────────────── */ +/* ─── LogPage ─── */ export default function LogPage() { const { toast } = useToast(); @@ -511,8 +317,6 @@ export default function LogPage() { const [tab, setTab] = useState('all'); const [clearing, setClearing] = useState(false); const [confirmOpen, setConfirmOpen] = useState(false); - - // Filter state const [cmdFilter, setCmdFilter] = useState(''); const [statusFilter, setStatusFilter] = useState(''); const [timeRange, setTimeRange] = useState(''); @@ -581,38 +385,30 @@ export default function LogPage() { lastOp = audit.last_operation; } } - return { - total, - success_rate: total > 0 ? okTotal / total : 0, - by_command: byCommand, - last_operation: lastOp, - }; + return { total, success_rate: total > 0 ? okTotal / total : 0, by_command: byCommand, last_operation: lastOp }; }, [tab, opsStatsQuery.data, auditStatsQuery.data]); const opsEntries = opsQuery.data?.entries ?? []; - const opsTotal = opsQuery.data?.total ?? 0; - const opsTotalAll = opsQuery.data?.totalAll ?? 0; const auditEntries = auditQuery.data?.entries ?? []; - const auditTotal = auditQuery.data?.total ?? 0; - const auditTotalAll = auditQuery.data?.totalAll ?? 0; + + /* Merged timeline for "all" tab — single chronological view */ + const displayEntries = useMemo(() => { + if (tab === 'ops') return opsEntries; + if (tab === 'audit') return auditEntries; + const merged = [...opsEntries, ...auditEntries]; + merged.sort((a, b) => new Date(b.ts).getTime() - new Date(a.ts).getTime()); + return merged; + }, [tab, opsEntries, auditEntries]); const loading = (tab === 'all' || tab === 'ops') && opsQuery.isPending || (tab === 'all' || tab === 'audit') && auditQuery.isPending; - const hasEntries = tab === 'all' - ? opsEntries.length > 0 || auditEntries.length > 0 - : tab === 'ops' - ? opsEntries.length > 0 - : auditEntries.length > 0; + const hasEntries = displayEntries.length > 0; const knownCommands = useMemo(() => { const cmds = new Set(); - if (opsQuery.data?.commands) { - for (const cmd of opsQuery.data.commands) cmds.add(cmd); - } - if (auditQuery.data?.commands) { - for (const cmd of auditQuery.data.commands) cmds.add(cmd); - } + if (opsQuery.data?.commands) for (const cmd of opsQuery.data.commands) cmds.add(cmd); + if (auditQuery.data?.commands) for (const cmd of auditQuery.data.commands) cmds.add(cmd); return Array.from(cmds).sort(); }, [opsQuery.data?.commands, auditQuery.data?.commands]); @@ -644,28 +440,12 @@ export default function LogPage() { const hasFilter = !!filters; - const totalLabel = (() => { - if (tab === 'all') { - if (hasFilter) { - return `${opsTotal} of ${opsTotalAll} ops / ${auditTotal} of ${auditTotalAll} audit`; - } - return `${opsTotal} ops / ${auditTotal} audit`; - } - const secTotal = tab === 'ops' ? opsTotal : auditTotal; - const secTotalAll = tab === 'ops' ? opsTotalAll : auditTotalAll; - if (hasFilter) { - return `${secTotal} of ${secTotalAll} entries`; - } - return `${secTotal} entries`; - })(); - return ( -
- {/* ─── Header ─── */} +
} title="Operations & Audit Log" - subtitle="Persistent record of CLI and UI operations, including audit findings by skill" + subtitle="Record of CLI and UI operations" actions={ <>