dashboard: move the JSON export to the Requests header as a download icon

The history summary row had grown crowded -- the figures, then a "json" button and a "clear"
button -- and the operator asked for the export to live in the Requests panel header instead,
top-left by the title, as a download icon with a "Download JSON file" tooltip. The Requests
header already carries running/waiting on the right, so the export sits opposite it on the
left rather than lumped in with the history figures.

The button is an inline SVG download glyph (a <button>, so it is keyboard-focusable and
announced), in a new .pleft group so the space-between header keeps it on the left with the
title. The handler now saves a file rather than copying to the clipboard: a Blob of the stored
rows, an anchor with a download name, clicked and removed, the object URL revoked after the
click. The old #hjson clipboard button is gone.

This also fixes a clipping bug the previous commit introduced. Making each category a nowrap
span and the separator a padded element removed every whitespace text node between categories,
so the summary line became one unbreakable run: a long line overflowed the row and clipped the
buttons after it -- the "json" the operator saw cut off at the panel edge. A zero-width space
between groups restores a break opportunity: the line can now wrap between categories, while
each category still stays atomic. The break point sits between groups, never inside one, where
nowrap would make it inert.

tests/js/download.test.js, 27 checks, drives the shipped handler against stubs: the button is
in the Requests header on the left of the aside, exactly one of them (a duplicate id would bind
only the first and leave a dead control), tooltip and aria-label present, an icon not a text
label; the handler builds one anchor, names it radiance-history.json, types the blob
application/json, clicks it, attaches it to the document (Firefox needs that), removes it, and
revokes the object URL only after the click. The payload round-trips through JSON.parse.

history.test.js gained the break-point checks: three zero-width spaces between four categories,
each immediately before its group, none buried inside a nowrap group.

Verified by mutation: dropping the download attribute, never clicking, never revoking, a wrong
blob type, changed tooltip text, and moving the button to the right of the aside each fail the
suite. extremes 27, poll_spark 35, history 29, download 27, dashboard_test 241 over 8 cases,
sched_test 62646 over 184, no failures.

Not deployed. Goes to review with the separator commits.

Authored at: Memoria Qwen 3.8 Flash-Next 125B MoE (level not visible) via Open WebUI
This commit is contained in:
Memoria (Noblistic) authored and StillDeadcode committed 2026-11-03 18:09:49 +01:00
1 parent 1554b451e1
commit c36d04d99c
3 files changed
+139 -6

No files matched your search

+26 -4
View File
@@ -587,6 +587,13 @@ h1 { margin:0; font-size:13.5px; font-weight:600; letter-spacing:-.005em; }
.cap { font-size:10.5px; font-weight:600; letter-spacing:.1em; text-transform:uppercase;
color:var(--dim); }
.aside { font-family:var(--mono); font-size:11.5px; color:var(--dim); }
/* A panel header's left side can hold a title plus a control; the header itself is
* space-between, so without this group the control would land in the middle. */
.pleft { display:flex; align-items:baseline; gap:9px; }
.pbtn { background:none; border:0; padding:0; margin:0; color:var(--faint); cursor:pointer;
display:inline-flex; align-items:center; }
.pbtn:hover { color:var(--fg); }
.pbtn:focus-visible { outline:1px solid var(--edge); outline-offset:3px; }
.pbody { padding:14px 16px 16px; }
/* The control vector's switch: a checkbox row with its explanation under it. The two need a gap
@@ -1227,7 +1234,14 @@ nav button.on { color:var(--fg); background:var(--track); }
<div class="body">
<div class="stack">
<section class="panel" id="reqpanel">
<div class="phead"><span class="cap">Requests</span>
<div class="phead"><span class="pleft"><span class="cap">Requests</span>
<button type="button" class="pbtn" id="reqjson"
title="Download JSON file" aria-label="Download JSON file">
<svg width="12" height="12" viewBox="0 0 16 16" aria-hidden="true">
<path d="M8 1.5v8m0 0L4.6 6.1M8 9.5l3.4-3.4M2.2 13.5h11.6"
fill="none" stroke="currentColor" stroke-width="1.6"
stroke-linecap="round" stroke-linejoin="round"/>
</svg></button></span>
<span class="aside" id="reqaside"></span></div>
<div class="pbody">
<div class="hold">
@@ -1240,7 +1254,6 @@ nav button.on { color:var(--fg); background:var(--track); }
<div id="hist">
<div class="hhead"><span class="cap">history</span>
<span class="hsum" id="hsum" title="mean of the per-request figures over all captured rows; each request counts once, so this is not the pooled rate the DECODE tile shows. last 20 and last 5 are the same mean over the most recent 20 and 5 requests. prefill is fresh prompt tokens over the time from admission to first token, so queue wait is not charged to it; on an engine that reports no admission time it falls back to time to first token, which does include queue wait. ttft is the median time to first token, including queue wait."></span>
<span class="hbtn" id="hjson" title="copy the stored rows as JSON">json</span>
<span class="hbtn" id="hclr" title="clear the stored history">clear</span></div>
<div class="hlist">
<table>
@@ -2265,6 +2278,10 @@ function histRender(missed) {
const hsum = $("hsum");
hsum.textContent = "";
parts.forEach((p, i) => {
/* The zero-width space is the line's ONLY break opportunity. The groups are nowrap so they
* cannot split, and with no break point here a long summary overflows the row and clips
* whatever follows it -- which is what the padded separators did to this line. */
if (i) hsum.appendChild(document.createTextNode("\u200b"));
const g = el("span", "hgrp");
/* The dot travels WITH the category it introduces: as a sibling it could be left stranded
* at the end of a line when the category wrapped, which is the orphan this avoids. */
@@ -2308,8 +2325,13 @@ $("hclr").addEventListener("click", () => {
lsSet(HK, "[]"); lsSet(HKN, "0"); lsSet(HKC, String(Date.now()));
hDrawn = null; histRender(0);
});
$("hjson").addEventListener("click", () => {
try { navigator.clipboard.writeText(JSON.stringify(hRows)); } catch (e) {}
$("reqjson").addEventListener("click", () => {
const url = URL.createObjectURL(new Blob([JSON.stringify(hRows, null, 2)],
{ type: "application/json" }));
const a = el("a");
a.href = url; a.download = "radiance-history.json";
document.body.appendChild(a); a.click(); a.remove();
setTimeout(() => URL.revokeObjectURL(url), 1000);
});
histLoad();
histRender(0);
+95
View File
@@ -0,0 +1,95 @@
/* The Requests-header JSON export. It used to be a "json" text button in the history row that
* copied to the clipboard; it is now a download icon that saves a file. A button that looks
* clickable and silently does nothing is the failure this guards: so drive the SHIPPED handler
* against stubs and assert it actually builds a file, names it, clicks it, and cleans up. */
const fs = require("fs");
const path = require("path");
const src = require("./page.js"); // the <script> block: the handler lives here
/* The MARKUP lives in the page body, which page.js does not return (the JS suites have no
reason to read it). Read the whole shipped page for markup assertions. */
const cpp = fs.readFileSync(path.join(__dirname, "..", "..", "core", "server", "dashboard.cpp"), "utf8");
const page = (cpp.match(/R"HTML\(([\s\S]*)\)HTML"/) || [, ""])[1];
const L = src.split("\n");
let fails = 0, checks = 0;
const ok = (c, m) => { checks++; if (!c) { fails++; console.log(" FAIL " + m); } };
const eq = (a, b, m) => { checks++; if (a !== b) { fails++; console.log(" FAIL " + m + ": got " + JSON.stringify(a) + " want " + JSON.stringify(b)); } };
console.log("== the export lives in the Requests header, not the history row ==");
ok(/id="reqjson"/.test(page), "a #reqjson control exists");
ok(!/id="hjson"/.test(page), "the old #hjson button in the history row is gone");
/* The button spans several source lines, so match the whole element, not one line. */
const btn = (page.match(/<button[^>]*id="reqjson"[\s\S]*?<\/button>/) || [""])[0];
ok(btn.length > 0, "found the reqjson button element");
ok(/title="Download JSON file"/.test(btn), "the tooltip says 'Download JSON file'");
ok(/aria-label="Download JSON file"/.test(btn), "and is labelled for assistive tech");
ok(/<svg[\s\S]*<\/svg>/.test(btn), "it holds an icon, not a text label");
ok(!/>\s*json\s*</.test(btn), "no leftover 'json' text label inside the button");
/* It must sit in the Requests header, in the LEFT group, before the right-hand aside. Index
ordering is sturdier than a regex across the whole block. */
const iLeft = page.indexOf('class="pleft"');
const iBtn = page.indexOf('id="reqjson"');
const iAside= page.indexOf('id="reqaside"');
ok(iLeft >= 0 && iBtn > iLeft, "reqjson comes after the phead left-group opens");
ok(iAside > iBtn, "reqjson comes before the right-hand aside (so it sits on the LEFT)");
/* Exactly one: a duplicate id is invalid HTML and getElementById binds only the first, so a
second button would render and do nothing -- the silent-dead-control failure itself. */
const nBtn = (page.match(/id="reqjson"/g) || []).length;
eq(nBtn, 1, "exactly one reqjson control (a duplicate id would leave one dead)");
/* And it is inside the Requests panel, not some other phead: the phead that opens with
class="pleft" is the Requests one (only that header gained the group). */
ok(page.indexOf('<span class="cap">Requests</span>') < iBtn,
"the button is in the Requests header, after its title");
console.log("== the shipped handler builds a real download ==");
const si = L.findIndex((x) => x.startsWith('$("reqjson").addEventListener'));
if (si < 0) throw new Error("no reqjson handler");
let ei = -1;
for (let k = si; k < L.length; k++) if (L[k] === "});") { ei = k; break; }
if (ei < 0) throw new Error("no handler end");
const HANDLER = L.slice(si, ei + 1).join("\n");
/* Stubs: capture the click handler, then invoke it and watch what it builds. */
let clickHandler = null;
const fakeEl = (tag) => ({ tag, href: "", download: "", clicked: 0, removed: 0,
click() { this.clicked++; }, remove() { this.removed++; } });
const anchors = [];
const el = (t) => { const a = fakeEl(t); anchors.push(a); return a; };
const body = { appended: [], appendChild(n) { this.appended.push(n); } };
const created = [];
const URL = { createObjectURL(b) { const u = "blob:fake/" + created.length; created.push({ b, u }); return u; },
revoked: [], revokeObjectURL(u) { this.revoked.push(u); } };
class Blob { constructor(parts, opts) { this.parts = parts; this.type = opts && opts.type; } }
let timeoutFn = null;
const setTimeout = (fn, ms) => { timeoutFn = fn; return 1; };
const hRows = [{ tps: 208, pf: 651, ttft: 796 }, { tps: 190 }];
const $ = (id) => ({ addEventListener(ev, fn) { if (ev === "click") clickHandler = fn; } });
new Function("$", "el", "document", "URL", "Blob", "setTimeout", "hRows", HANDLER)(
$, el, { body }, URL, Blob, setTimeout, hRows);
ok(clickHandler !== null, "a click handler was registered on #reqjson");
clickHandler();
eq(anchors.length, 1, "exactly one anchor built");
const a = anchors[0];
eq(a.tag, "a", "it is an anchor");
eq(a.download, "radiance-history.json", "it names a downloadable file");
ok(a.href.startsWith("blob:"), "href is a blob URL: " + a.href);
eq(a.clicked, 1, "the anchor was clicked (that is what triggers the save)");
eq(body.appended.length, 1, "the anchor was attached to the document (Firefox needs it in the DOM)");
eq(a.removed, 1, "the anchor was removed afterwards");
eq(created[0].b.type, "application/json", "the blob is typed application/json");
const payload = JSON.parse(created[0].b.parts[0]);
ok(Array.isArray(payload) && payload.length === 2, "the file holds the stored rows as JSON");
eq(payload[0].tps, 208, "the row data survived serialization");
ok(created[0].b.parts[0].includes("\n"), "pretty-printed (indented), not one dense line");
console.log("== cleanup: the blob URL is revoked, not leaked ==");
eq(URL.revoked.length, 0, "not revoked synchronously (the click must finish first)");
ok(typeof timeoutFn === "function", "a revoke was scheduled");
timeoutFn();
eq(URL.revoked.length, 1, "the revoke ran and released the blob URL");
eq(URL.revoked[0], a.href, "and revoked exactly the URL it handed the anchor");
console.log(fails ? "\n" + fails + " FAILURE(S) of " + checks : "\nALL " + checks + " CHECKS PASS on the shipped download");
process.exit(fails ? 1 : 0);
+18 -2
View File
@@ -75,9 +75,25 @@ new Function("el", "document", "$", "hRows", "tps", "cnt3", "dur", BLOCK)(
el, doc, () => hsum, rows,
(v) => Math.round(v) + " t/s", (v) => String(Math.round(v)), (v) => v + " ms");
const groups = hsum.kids;
/* #hsum now holds the four category groups AND the zero-width-space break points between them,
so select by class rather than assuming every child is a group. */
const groups = hsum.kids.filter((k) => k.cls === "hgrp");
const zwsps = hsum.kids.filter((k) => k.tag === "#text" && k.txt === "\u200b");
eq(groups.length, 4, "four categories: count, tok/s, prefill, ttft");
ok(groups.every((g) => g.cls === "hgrp"), "every category is a .hgrp (the nowrap unit)");
console.log("== the line has a break point, so a long summary wraps instead of clipping ==");
/* The groups are nowrap; without a break opportunity between them the whole line is one
* unbreakable run that overflows the row and clips whatever follows it. */
eq(zwsps.length, 3, "a zero-width break point between each pair of categories");
ok(hsum.kids.every((k) => k.cls === "hgrp" || (k.tag === "#text" && k.txt === "\u200b")),
"#hsum holds only groups and break points, nothing else");
/* The break point must sit BETWEEN groups, not inside one: a ZWSP inside a nowrap span cannot
* break, so it would buy nothing. */
for (let i = 1; i < groups.length; i++) {
const first = hsum.kids.indexOf(groups[i]);
eq(hsum.kids[first - 1].txt, "\u200b", "break point immediately precedes category " + i);
}
ok(!JSON.stringify(groups.map((g) => g.kids)).includes("\u200b"),
"no break point buried inside a nowrap group, where it could not act");
console.log("== the dot introduces its category and travels with it ==");
eq(groups[0].kids.filter((k) => k.cls === "hsep").length, 0, "the first category carries no leading dot");
[1, 2, 3].forEach((i) => {