Watch
0
0
Fork
You've already forked hyperhive
0

frontend: one time wording for the swarm UI and the dashboard, and no HTML strings in the dashboard's busy buttons

fmtAgo, fmtUntil and durationLabel move to @hive/shared/time.js. The swarm UI's util.ts is deleted and its importers (RelativeTime, ReviewRuns, BuildsPage) read the shared module directly. The dashboard's own copies are gone: its fmtAgeSecs (a third phrasing, used for two status lines) becomes the shared fmtAgo, and the dashboard util.js lost fmtAgo, fmtElapsed, epochSec and truncate, which nothing called. asyncBtn and the bulk action buttons mark themselves busy with markBusy: a spinner node before the label and aria-busy, in place of replacing the button's innerHTML with a string (and the label, so the button changed width and lost its name). The el() helper loses its html attribute.
This commit is contained in:
iris 2026-11-19 19:21:15 +01:00
commit 3be4ec069c

View file

@ -4,8 +4,10 @@
// job-queue-rollup ops. See docs/4-implementation/web-ui/dashboard.md::Container row for the
// rendering contract.
import { $, buttonClass, form, fmtAgeSecs } from "./common.js";
import { fmtAgo } from "@hive/shared/time.js";
import { $, buttonClass, form } from "./common.js";
import { el } from "@hive/shared/dom.js";
import { markBusy } from "@hive/shared/forms.js";
import { themedConfirm, themedToast } from "@hive/shared/modal.js";
import { h, render } from "preact";
import { JobqRollup } from "@hive/shared/jobq-rollup.js";
@ -396,7 +398,7 @@ function buildContainerLi(c, opts) {
const nowUnix = Math.floor(Date.now() / 1000);
const ageStr =
ds.status_set_at != null
? ` (set ${fmtAgeSecs(nowUnix - ds.status_set_at)} ago)`
? ` (set ${fmtAgo(nowUnix - ds.status_set_at)})`
: "";
// Stamp data-set-at so the 30s ticker below keeps the age
// label current even when the row is reused from the cache.
@ -837,8 +839,7 @@ function addBulkButton(parent, tone, label, enabled, selected, opts) {
graceful = !!r.graceful;
}
btn.disabled = true;
const original = btn.innerHTML;
btn.innerHTML = '<span class="spinner">◐</span> ' + label;
const unbusy = markBusy(btn);
const failures = [];
// Sequential POSTs to keep server-side serialisation predictable
// (rebuild_queue dedups but other endpoints don't); the loop is
@ -875,7 +876,7 @@ function addBulkButton(parent, tone, label, enabled, selected, opts) {
}
}
btn.disabled = false;
btn.innerHTML = original;
unbusy();
if (failures.length) {
themedToast(
`${label} completed with ${failures.length} failure${failures.length === 1 ? "" : "s"}:\n\n` +
@ -896,13 +897,13 @@ function addBulkButton(parent, tone, label, enabled, selected, opts) {
// 30s ticker for agent status-age chips. Renderers stamp `data-set-at`
// (unix seconds) on the `.status-age` span. Keyed container rows persist
// across re-renders, so without this ticker the "(set N ago)" label would
// become stale as time passes. 30s granularity matches fmtAgeSecs precision
// become stale as time passes. 30s granularity matches fmtAgo precision
// (sub-minute values round to seconds, coarser above that).
setInterval(() => {
const now = Math.floor(Date.now() / 1000);
document.querySelectorAll(".status-age[data-set-at]").forEach((node) => {
const setAt = Number(node.dataset.setAt);
if (!Number.isFinite(setAt) || setAt === 0) return;
node.textContent = ` (set ${fmtAgeSecs(now - setAt)} ago)`;
node.textContent = ` (set ${fmtAgo(now - setAt)})`;
});
}, 30_000);