Files
gitea-nova/Scripts/views/nodes.js
T
thatguygriffandClaude Opus 5 4bc81b59e7
CI / Tests (push) Successful in 1m34s
CI / Generated images (push) Successful in 2m0s
Keep the sidebar's open rows across refreshes
Expanding a workflow run and waiting through one poll closed it again.

Two causes. Nova applies whatever collapsible state getTreeItem returns,
and it returned Collapsed for every row that was not built default-open,
so each reload closed everything the user had opened. On top of that, a
reload fired on every poll whether or not anything had changed, so an
idle tree was rebuilt every 15 to 60 seconds for no reason.

The provider now tracks expansion by node identifier, fed from the tree
view's expand and collapse events. A node built default-open seeds that
set the first time its identifier is seen, so such a section can still be
closed by hand and stay closed.

Node identifiers consequently have to be stable across rebuilds. The
fallback for nodes without an explicit one was a counter, which changed
on every build; it is now derived from the node's kind and name. Step
rows were keyed by step number alone, which collided between jobs, and
are now qualified by the job.

Reloads are also skipped entirely when store.signature() is unchanged.
The signature covers everything drawn, including the branch filter, which
changes the tree without changing any data. A live run contributes a
coarse time bucket so its elapsed clock still ticks, and the explicit
Refresh command always redraws.

Adds twelve checks covering expansion surviving a rebuild, a default-open
section staying closed once closed, and the signature responding to run
state and the branch filter but not to a no-op poll. 143 checks total.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MQuusXgZC2dzwpJJ1qhtti
2026-08-28 20:21:19 -03:00

135 lines
3.9 KiB
JavaScript

//
// Node model shared by every sidebar section. Nova's TreeItem has no badge or
// status colour, so run state is carried by a leading glyph in the item name
// and by descriptive text on the trailing edge.
//
const time = require("../util/time.js");
const RUN_GLYPHS = {
success: "✓",
failure: "✗",
failed: "✗",
error: "✗",
timed_out: "✗",
cancelled: "⊘",
canceled: "⊘",
skipped: "⊝",
running: "●",
in_progress: "●",
queued: "◌",
waiting: "◌",
pending: "◌",
blocked: "◌",
};
function glyphFor(statusOrConclusion) {
const key = String(statusOrConclusion || "").toLowerCase();
return RUN_GLYPHS[key] || "•";
}
/** A completed run reports state via `conclusion`; a live one via `status`. */
function runState(run) {
const conclusion = String(run.conclusion || "").toLowerCase();
if (conclusion) return conclusion;
return String(run.status || "").toLowerCase() || "unknown";
}
function pullRequestGlyph(pull) {
if (pull.merged) return "⤳";
if (pull.state === "closed") return "⊘";
if (pull.draft) return "◌";
return "◆";
}
function reviewGlyph(state) {
const key = String(state || "").toUpperCase();
if (key === "APPROVED") return "✓";
if (key === "REQUEST_CHANGES" || key === "CHANGES_REQUESTED") return "✗";
if (key === "PENDING") return "◌";
return "◆";
}
/**
* Builds a tree node. `children` is a resolved array; `load` is an async
* producer used for rows that fetch on expand.
*/
function node(kind, name, options = {}) {
const value = {
kind: kind,
name: name,
// Identifiers must be stable across rebuilds: Nova matches them to
// work out which rows stay open when the tree reloads.
identifier: options.identifier || `${kind}:${name}`,
descriptiveText: options.description || "",
tooltip: options.tooltip || "",
image: options.image || null,
contextValue: options.contextValue || kind,
command: options.command || null,
path: options.path || null,
data: options.data || null,
repo: options.repo || null,
children: options.children || null,
load: options.load || null,
expanded: options.expanded === true,
parent: null,
};
if (value.children) {
for (const child of value.children) child.parent = value;
}
return value;
}
function message(text, kind = "message") {
return node(kind, text, { contextValue: "message" });
}
function errorNode(text) {
return node("error", `⚠ ${text}`, { contextValue: "message", tooltip: text });
}
/** Formats "12s · 3m ago" style trailing text for a run or job. */
function timingText(entity) {
const parts = [];
const length = time.duration(entity.started_at, entity.completed_at);
if (length) parts.push(length);
const when = time.relative(entity.started_at || entity.created_at || entity.updated_at);
if (when) parts.push(when);
return parts.join(" · ");
}
function runTitle(run) {
return (
run.display_title ||
run.title ||
run.name ||
(run.path ? run.path.split("/").pop() : null) ||
`Run #${run.run_number || run.id}`
);
}
/** Groups runs by their workflow file, falling back to the run's own name. */
function workflowKey(run) {
if (run.path) return run.path;
if (run.workflow_id) return String(run.workflow_id);
return run.name || "Workflow";
}
function workflowLabel(run) {
if (run.path) return run.path.split("/").pop();
return run.name || "Workflow";
}
exports.node = node;
exports.message = message;
exports.errorNode = errorNode;
exports.glyphFor = glyphFor;
exports.runState = runState;
exports.pullRequestGlyph = pullRequestGlyph;
exports.reviewGlyph = reviewGlyph;
exports.timingText = timingText;
exports.runTitle = runTitle;
exports.workflowKey = workflowKey;
exports.workflowLabel = workflowLabel;