Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html)

## [Unreleased]

### Added

- **Copy validation findings (#197):** each finding has a copy button (on hover or focus), and the panel head
has **Copy shown** for every finding at the selected severities. The text reads like `idm validate`'s line:
severity, code, path, message, and the detail under it. Where the browser won't let the page use the
Clipboard API (plain http to another host), it falls back to the copy command, and a refusal says
"copy failed".

## [0.95.0] - 2026-11-20

### Changed
Expand Down
85 changes: 75 additions & 10 deletions web/src/components/ValidationPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useMemo } from "react";
import { useMemo, useState } from "react";
import type { Finding, Validation } from "../types";

export const SEVERITIES = ["error", "warning", "info"] as const;
Expand All @@ -25,6 +25,39 @@ export function moduleOf(path: string): { module: string; rest: string; order: n
return { module: parts[0]!, rest: parts.slice(1).join("/"), order: 3 };
}

/** A finding as text for the clipboard (#197), as `idm validate` prints it: severity, code, path, message, then its detail. */
export function findingText(f: Finding): string {
const head = `${f.severity.toUpperCase()} ${f.code} ${f.path}: ${f.message}`;
return f.detail ? `${head}\n ${f.detail}` : head;
}

/**
* Puts text on the clipboard: the Clipboard API, or, where the page may not use it (plain http on
* another host has no navigator.clipboard), a selected textarea and the copy command.
*/
async function copyText(text: string): Promise<void> {
try {
if (navigator.clipboard) {
await navigator.clipboard.writeText(text);
return;
}
} catch {
// refused: try the copy command
}
const ta = document.createElement("textarea");
ta.value = text;
ta.setAttribute("readonly", "");
ta.style.position = "fixed";
ta.style.opacity = "0";
document.body.appendChild(ta);
ta.select();
const ok = document.execCommand("copy");
document.body.removeChild(ta);
if (!ok) {
throw new Error("the browser refused the copy");
}
}

function pillClass(s: Severity, counts: { error: number }): string {
return "pill " + (s === "error" ? (counts.error > 0 ? "err" : "ok") : s === "warning" ? "warn" : "");
}
Expand Down Expand Up @@ -86,6 +119,16 @@ export function ValidationPanel({ validation, show, onToggle, onOpen, onHide }:
const counts = validation?.counts ?? { error: 0, warning: 0, info: 0 };
const visible = (f: Finding) => show.has(f.severity.toLowerCase() as Severity);
const shown = groups.map((g) => ({ ...g, items: g.items.filter(visible) })).filter((g) => g.items.length > 0);
// the copy button last pressed ("all" or a finding's key) and whether it worked, shown for a moment
const [copied, setCopied] = useState<{ key: string; ok: boolean } | null>(null);
const copy = (key: string, text: string) => {
const show = (ok: boolean) => {
setCopied({ key, ok });
window.setTimeout(() => setCopied((c) => (c?.key === key ? null : c)), ok ? 1500 : 4000);
};
copyText(text).then(() => show(true), () => show(false));
};
const copyLabel = (key: string, idle: string) => (copied?.key === key ? (copied.ok ? "copied" : "copy failed") : idle);

return (
<div className="validation" data-testid="validation">
Expand All @@ -96,6 +139,16 @@ export function ValidationPanel({ validation, show, onToggle, onOpen, onHide }:
</button>
))}
<span className="spacer" />
{shown.length > 0 && (
<button
className="linkish"
onClick={() => copy("all", shown.flatMap((g) => g.items.map(findingText)).join("\n"))}
title="Copy every finding at the selected severities as text"
data-testid="validation-copy-all"
>
{copyLabel("all", "Copy shown")}
</button>
)}
<button className="linkish" onClick={onHide} title="Hide the findings (the counts stay in the top bar)" data-testid="validation-hide">
hide ▸
</button>
Expand All @@ -118,15 +171,27 @@ export function ValidationPanel({ validation, show, onToggle, onOpen, onHide }:
</span>
</summary>
<ul className="findings">
{g.items.map((f, i) => (
<li key={f.path + f.code + i} className={"finding " + f.severity.toLowerCase()}>
<button onClick={() => onOpen(f.path)} title={f.path}>
<span className="code">{f.code}</span>
{f.rest && <span className="path">{f.rest}</span>}
<span className="msg">{f.message}</span>
</button>
</li>
))}
{g.items.map((f, i) => {
const key = f.path + f.code + i;
return (
<li key={key} className={"finding " + f.severity.toLowerCase()}>
<button onClick={() => onOpen(f.path)} title={f.path}>
<span className="code">{f.code}</span>
{f.rest && <span className="path">{f.rest}</span>}
<span className="msg">{f.message}</span>
</button>
<button
className="fcopy linkish"
onClick={() => copy(key, findingText(f))}
title="Copy this finding as text"
aria-label="Copy this finding as text"
data-testid="finding-copy"
>
{copyLabel(key, "copy")}
</button>
</li>
);
})}
</ul>
</details>
))
Expand Down
20 changes: 20 additions & 0 deletions web/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,26 @@ th {
.finding.warning > button {
border-left-color: var(--warn);
}
.finding {
position: relative;
}
/* copy one finding (#197): shown on hover or keyboard focus, beside the message */
.finding > button.fcopy {
display: block;
position: absolute;
top: 6px;
right: 8px;
width: auto;
padding: 0 4px;
border: none;
font-size: 11px;
background: var(--surface);
opacity: 0;
}
.finding:hover > button.fcopy,
.finding:focus-within > button.fcopy {
opacity: 1;
}
.finding .code {
font-family: ui-monospace, Menlo, monospace;
font-size: 11px;
Expand Down
11 changes: 10 additions & 1 deletion web/src/validation.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
import { moduleOf } from "./components/ValidationPanel";
import { findingText, moduleOf } from "./components/ValidationPanel";

describe("moduleOf: the module a finding is grouped under", () => {
it("names the driver for anything under drivers/", () => {
Expand All @@ -16,3 +16,12 @@ describe("moduleOf: the module a finding is grouped under", () => {
expect([moduleOf("drivers/Z/x"), moduleOf("library/y"), moduleOf("driverset")].map((m) => m.order)).toEqual([2, 1, 0]);
});
});

describe("findingText: a finding as text for the clipboard (#197)", () => {
it("reads like idm validate's line, with the detail under it", () => {
expect(findingText({ severity: "ERROR", code: "mapping-table-column", path: "drivers/AD/subscriber/maps", message: "<token-map> names column 'x'" })).toBe(
"ERROR mapping-table-column drivers/AD/subscriber/maps: <token-map> names column 'x'",
);
expect(findingText({ severity: "warning", code: "c", path: "library/L", message: "m", detail: "more" })).toBe("WARNING c library/L: m\n more");
});
});
Loading