feat(orchestrator): time range and replay move into the rates panel (015)
The navbar time menu goes; the rates panel holds the presets, a two-handle span slider over the hub's history, replay and Live, and the custom From/To range. A custom range becomes a window length plus an end point, so live windows keep their length. The rates chip lists every metric, and the panel wraps instead of spilling at 390 px. Unit and e2e (Chromium, Firefox, 1920/1366/390) cover the window, the slider and the requests. 🎯 Fix: 94 % 💥 Break: 4 % 💸 Tokens: 100 % ⏱️ Velocity: 100 % 🛡️ Security: 100 % 🏆 Score: 90 🚦 Gate: ✅ 90/5, tokens and velocity <= 100, security 100 % Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
09e3f6dabe
commit
cc6ea7c230
20 files changed
+462
-416
No files matched your search
@@ -1,7 +1,7 @@
|
||||
const SPAN_STEPS = 1000;
|
||||
const SHORTEST = 60;
|
||||
|
||||
function windowQuery() {
|
||||
if (ui.preset === -1) {
|
||||
return `from=${Math.floor(ui.from)}&to=${Math.ceil(ui.to)}`;
|
||||
}
|
||||
const end = ui.asOf === null ? nowSeconds() : ui.asOf;
|
||||
const begin = ui.preset === 0 ? 0 : end - ui.preset;
|
||||
return `from=${Math.floor(begin)}${ui.asOf === null ? "" : `&to=${Math.ceil(end)}`}`;
|
||||
@@ -12,9 +12,34 @@
|
||||
return new Date(date.getTime() - date.getTimezoneOffset() * 60000).toISOString().slice(0, 16);
|
||||
};
|
||||
|
||||
function spanName(seconds) {
|
||||
if (seconds >= DAY) {
|
||||
return `${Math.round(seconds / DAY)} d`;
|
||||
}
|
||||
return seconds >= 3600 ? `${Math.round(seconds / 3600)} h` : `${Math.max(Math.round(seconds / 60), 1)} min`;
|
||||
}
|
||||
|
||||
function windowName() {
|
||||
const preset = PRESETS.find(([seconds]) => seconds === ui.preset);
|
||||
return `${preset ? preset[1] : spanName(ui.preset)}${ui.asOf === null ? "" : " · past"}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} begin the window's start in epoch seconds.
|
||||
* @param {number} end its end; at or after now the window is live and keeps its length.
|
||||
*/
|
||||
function setWindow(begin, end) {
|
||||
stopReplay();
|
||||
const now = nowSeconds();
|
||||
const stop = Math.min(end, now);
|
||||
ui.preset = Math.max(Math.round(stop - begin), SHORTEST);
|
||||
ui.asOf = end >= now ? null : stop;
|
||||
reload();
|
||||
}
|
||||
|
||||
function customRange() {
|
||||
const from = h("input", {type: "datetime-local", "aria-label": "From", value: localInput(ui.from === null ? state.since : ui.from)});
|
||||
const to = h("input", {type: "datetime-local", "aria-label": "To", value: localInput(ui.to === null ? state.until : ui.to)});
|
||||
const from = h("input", {type: "datetime-local", "aria-label": "From", value: localInput(state.since)});
|
||||
const to = h("input", {type: "datetime-local", "aria-label": "To", value: localInput(state.until)});
|
||||
return h("span", {class: "custom"}, from, h("span", {class: "muted"}, "to"), to,
|
||||
h("button", {type: "button", class: "btn small soft", on: {click: () => {
|
||||
const begin = Date.parse(from.value) / 1000;
|
||||
@@ -23,47 +48,45 @@
|
||||
toast("Time range invalid", ["“From” must come before “To”."], false);
|
||||
return;
|
||||
}
|
||||
stopReplay();
|
||||
ui.preset = -1;
|
||||
ui.from = begin;
|
||||
ui.to = end;
|
||||
reload();
|
||||
setWindow(begin, end);
|
||||
}}}, "Apply"));
|
||||
}
|
||||
|
||||
function timeBar() {
|
||||
const bar = document.getElementById("time");
|
||||
function spanSlider() {
|
||||
const [from, to] = ["from", "to"].map((end, index) => h("input", {type: "range", class: `span-${end}`, min: 0, max: SPAN_STEPS, step: 1, value: index * SPAN_STEPS, "aria-label": `Time range ${end}`}));
|
||||
const fill = h("span", {class: "span-fill", "aria-hidden": "true"});
|
||||
const at = (value) => state.first + (Math.max(state.now - state.first, 1) * Number(value)) / SPAN_STEPS;
|
||||
const moved = (event) => {
|
||||
if (Number(from.value) >= Number(to.value)) {
|
||||
event.target.value = String(event.target === from ? Number(to.value) - 1 : Number(from.value) + 1);
|
||||
}
|
||||
setWindow(at(from.value), Number(to.value) >= SPAN_STEPS ? nowSeconds() : at(to.value));
|
||||
};
|
||||
from.addEventListener("input", moved);
|
||||
to.addEventListener("input", moved);
|
||||
return {box: h("div", {class: "span-slider"}, fill, from, to), from, to, fill};
|
||||
}
|
||||
|
||||
function timeSection() {
|
||||
const presets = h("div", {class: "segmented", role: "group", "aria-label": "Time range"});
|
||||
const summary = h("summary", {title: "Time range and replay"});
|
||||
const slider = h("input", {type: "range", min: 0, max: 1000, step: 1, value: 1000, "aria-label": "Replay position"});
|
||||
const play = iconBtn("bi-play-fill", "Replay", "btn small soft", null);
|
||||
const liveButton = h("button", {type: "button", class: "btn small ghost"}, "Live");
|
||||
const label = h("span", {class: "window-label"});
|
||||
for (const [seconds, name] of PRESETS.filter(([seconds]) => seconds !== -1)) {
|
||||
for (const [seconds, name] of PRESETS) {
|
||||
presets.append(h("button", {type: "button", "data-preset": seconds, on: {click: () => choosePreset(seconds)}}, name));
|
||||
}
|
||||
slider.addEventListener("input", () => {
|
||||
stopReplay();
|
||||
const span = state.now - state.first;
|
||||
ui.asOf = Number(slider.value) >= 1000 ? null : state.first + (span * Number(slider.value)) / 1000;
|
||||
reload();
|
||||
});
|
||||
play.addEventListener("click", () => (ui.playing ? stopReplay() : startReplay()));
|
||||
liveButton.addEventListener("click", () => {
|
||||
const slider = spanSlider();
|
||||
const play = iconBtn("bi-play-fill", "Replay", "btn small soft", () => (ui.playing ? stopReplay() : startReplay()));
|
||||
const liveButton = h("button", {type: "button", class: "btn small ghost", on: {click: () => {
|
||||
stopReplay();
|
||||
ui.asOf = null;
|
||||
if (ui.preset === -1) {
|
||||
ui.preset = DAY;
|
||||
}
|
||||
reload();
|
||||
});
|
||||
bar.append(summary, h("div", {class: "menu-box end"}, h("h3", {}, "Time range"), presets, h("h3", {}, "Replay"), h("div", {class: "replay"}, play, slider, liveButton), label,
|
||||
h("p", {class: "muted"}, "Filter ▾ in the stream sets a custom time range.")));
|
||||
timeDom = {summary, presets, slider, play, live: liveButton, label};
|
||||
}}}, "Live");
|
||||
const label = h("span", {class: "window-label"});
|
||||
timeDom = {presets, from: slider.from, to: slider.to, fill: slider.fill, play, live: liveButton, label};
|
||||
return [h("h3", {}, "Time range"), presets, slider.box, h("div", {class: "replay"}, play, liveButton, label), customRange()];
|
||||
}
|
||||
|
||||
function reload() {
|
||||
load();
|
||||
fetchRates();
|
||||
if (ui.screen === "stream") {
|
||||
fetchEvents();
|
||||
}
|
||||
@@ -72,6 +95,7 @@
|
||||
function choosePreset(seconds) {
|
||||
stopReplay();
|
||||
ui.preset = seconds;
|
||||
ui.asOf = null;
|
||||
reload();
|
||||
}
|
||||
|
||||
@@ -80,27 +104,26 @@
|
||||
return;
|
||||
}
|
||||
for (const button of timeDom.presets.children) {
|
||||
button.setAttribute("aria-pressed", String(Number(button.dataset.preset) === ui.preset));
|
||||
button.setAttribute("aria-pressed", String(Number(button.dataset.preset) === ui.preset && ui.asOf === null));
|
||||
}
|
||||
timeDom.summary.textContent = `${(PRESETS.find(([seconds]) => seconds === ui.preset) || [0, "custom"])[1]}${ui.asOf === null ? "" : " · replay"} ▾`;
|
||||
timeDom.slider.disabled = ui.preset === -1;
|
||||
timeDom.play.disabled = ui.preset === -1;
|
||||
timeDom.live.disabled = live();
|
||||
const span = Math.max(state.now - state.first, 1);
|
||||
if (!ui.playing) {
|
||||
timeDom.slider.value = String(ui.asOf === null ? 1000 : Math.round((1000 * (ui.asOf - state.first)) / span));
|
||||
}
|
||||
const end = ui.asOf === null ? state.now : ui.asOf;
|
||||
const place = (t) => Math.min(Math.max(Math.round((SPAN_STEPS * (t - state.first)) / span), 0), SPAN_STEPS);
|
||||
const [low, high] = [place(ui.preset === 0 ? state.first : end - ui.preset), ui.asOf === null ? SPAN_STEPS : place(end)];
|
||||
timeDom.from.value = String(Math.min(low, high - 1));
|
||||
timeDom.to.value = String(high);
|
||||
timeDom.from.classList.toggle("on-top", low > SPAN_STEPS / 2);
|
||||
timeDom.fill.style.left = `${(100 * low) / SPAN_STEPS}%`;
|
||||
timeDom.fill.style.right = `${100 - (100 * high) / SPAN_STEPS}%`;
|
||||
timeDom.live.disabled = live();
|
||||
timeDom.label.textContent = `${absolute.format(stampOf(state.since))} – ${absolute.format(stampOf(state.until))}${live() ? " · live" : ""}`;
|
||||
}
|
||||
|
||||
function startReplay() {
|
||||
if (ui.preset === -1) {
|
||||
return;
|
||||
}
|
||||
const began = state.first;
|
||||
const began = state.first + (ui.preset === 0 ? 0 : ui.preset);
|
||||
const span = Math.max(state.now - began, 1);
|
||||
const resume = ui.asOf !== null && ui.asOf < state.now - 60;
|
||||
let progress = resume ? (ui.asOf - began) / span : 0;
|
||||
let progress = resume ? Math.max((ui.asOf - began) / span, 0) : 0;
|
||||
ui.playing = true;
|
||||
relabel(timeDom.play, "bi-pause-fill", "Pause");
|
||||
const advance = async () => {
|
||||
@@ -109,8 +132,8 @@
|
||||
}
|
||||
progress = Math.min(progress + 1 / 48, 1);
|
||||
ui.asOf = progress >= 1 ? null : began + span * progress;
|
||||
timeDom.slider.value = String(Math.round(progress * 1000));
|
||||
await load();
|
||||
fetchRates();
|
||||
if (ui.screen === "stream") {
|
||||
fetchEvents();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user