Files
archie/ui/src/lib/log.ts
T
sam 5e1e365c05 feat(webui): events counts, YAML reading, log rows and dashboard filters
Four findings from the ui-redesign verification pass, each with the module that
owns the rule and the test that pins it.

- events: the three-step strip's and the tab chips' counts move out of the SFC
  into events/counts.ts -- one read per step, an unreadable count stays blank
  rather than reading as zero (events-counts.test.ts).
- workflows: workflows/workflow-yaml.ts reads the editor's YAML with a real
  parser (the yaml package, not a line scanner) to drive the read-only Steps
  preview and a live validity indicator; the editor gains a line-number gutter
  and light syntax colouring behind the textarea. Step types and their settings
  are not served to the dashboard, so those remain the server's to check on
  save, and a save it refuses still reports its own reason.
- tasks: an ERROR log row is a block rather than only red text (lib/log.ts), the
  log pane ends with "End of attempt N - M lines", and the task head offers
  Archive when the server's own action list offers it (task-actions.ts, and
  TaskRowActions' new `only` narrows the list without inventing a control).
- dashboard: the live activity feed gains the All/Tasks/System filter
  (activity-filter.ts) and every quality-gate row gains a pass bar
  (pass-bar.ts) that is red when the gate is failing.

ui/dist regenerated; ui/package.json carries yaml ^2.9.1.
2026-09-30 11:41:33 +10:00

91 lines
2.9 KiB
TypeScript

import type { StatusKind } from "./status";
/**
* Log-entry vocabulary shared by the daemon-wide log page and a task's own
* attempt log, which render the same entry shape from internal/logging.
*/
/**
* The level filter vocabulary. Server-side level filtering takes a CSV of
* levels (`splitCSV` in internal/webui/api_tasks_logs.go), so the combined
* options are a wire concern too, not a display choice.
*/
export const LOG_LEVELS = [
{ value: "", label: "All levels" },
{ value: "ERROR", label: "Errors" },
{ value: "WARN,ERROR", label: "Warnings and errors" },
{ value: "INFO,WARN,ERROR", label: "Info and above" },
{ value: "DEBUG", label: "Debug only" },
];
/** The kinds a log level uses. Never `ok`: a log line is not a pass. */
export type LevelKind = Exclude<StatusKind, "ok">;
/** One entry as internal/logging serialises it. */
export interface LogEntry {
time: string | number | Date;
level?: string | null;
message?: string;
msg?: string;
fields?: Record<string, unknown>;
}
/** The level label's colour, by kind. One place, so two log panes agree. */
export const LEVEL_COLOR: Record<LevelKind, string> = {
danger: "text-danger",
warn: "text-warn",
info: "text-info",
idle: "text-idle",
};
export function levelKind(level: string | null | undefined): LevelKind {
switch ((level || "").toUpperCase()) {
case "ERROR":
return "danger";
case "WARN":
return "warn";
case "DEBUG":
return "idle";
default:
return "info";
}
}
/**
* The row's own treatment, by level. The level label carries the colour; the row
* carries the weight: an ERROR line is a block the eye lands on, not red text
* in a column of grey. Every row keeps a left edge of the same width, coloured
* or not, so the three columns never shift between rows.
*/
export const LEVEL_ROW: Record<LevelKind, string> = {
danger: "border-l-danger bg-danger-soft",
warn: "border-l-transparent",
info: "border-l-transparent",
idle: "border-l-transparent",
};
/** The classes one row wears for its level. */
export function rowClass(level: string | null | undefined): string {
return LEVEL_ROW[levelKind(level)];
}
/**
* The end of an attempt's log: which attempt, and how much it wrote. The count
* is the lines on screen, so a filtered pane says how much the filter left.
*/
export function attemptFooter(attempt: number, lines: number): string {
const count = Math.max(0, Math.trunc(lines) || 0);
return `End of attempt ${attempt} \u00b7 ${count} line${count === 1 ? "" : "s"}`;
}
export function fmtValue(v: unknown): string {
if (v == null) return "";
return typeof v === "object" ? JSON.stringify(v) : String(v);
}
export function shortTime(value: string | number | Date): string {
const d = value instanceof Date ? value : new Date(value);
if (Number.isNaN(d.getTime())) return "--:--:--";
return d.toTimeString().slice(0, 8);
}