Keep the sidebar's open rows across refreshes
CI / Tests (push) Successful in 1m34s
CI / Generated images (push) Successful in 2m0s

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
This commit is contained in:
2026-08-28 20:21:19 -03:00
co-authored by Claude Opus 5
parent 87851de921
commit 4bc81b59e7
9 changed files with 267 additions and 19 deletions
+5 -3
View File
@@ -10,10 +10,10 @@ const { isActiveRun } = require("../store.js");
const { node, message } = nodes;
function stepNode(step, index) {
function stepNode(job, step, index) {
const state = nodes.runState(step);
return node("step", `${nodes.glyphFor(state)} ${step.name || `Step ${index + 1}`}`, {
identifier: `step-${step.number || index}`,
identifier: `step-${job.id}-${step.number || index}`,
description: time.duration(step.started_at, step.completed_at),
tooltip: `${step.name || ""}\nStatus: ${state}`,
contextValue: "step",
@@ -39,7 +39,9 @@ function jobNode(store, repo, run, job) {
command: "gitea.viewJobLogs",
repo: repo,
data: { job: job, run: run, repoKey: repo.key },
children: steps.length ? steps.map(stepNode) : null,
children: steps.length
? steps.map((step, index) => stepNode(job, step, index))
: null,
});
}
+3 -4
View File
@@ -50,18 +50,17 @@ function reviewGlyph(state) {
return "◆";
}
let counter = 0;
/**
* 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 = {}) {
counter += 1;
const value = {
kind: kind,
name: name,
identifier: options.identifier || `${kind}-${counter}`,
// 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,
+35 -6
View File
@@ -10,6 +10,35 @@ class NodeProvider {
constructor(store) {
this.store = store;
this._roots = null;
// Expansion has to be tracked here. A reload rebuilds every node, and
// the collapsible state we hand back is what Nova applies, so without
// this every refresh would close whatever the user had opened.
this._expanded = new Set();
this._known = new Set();
}
/** Records what the user opened or closed, keyed by node identifier. */
setExpanded(element, expanded) {
if (!element || !element.identifier) return;
if (expanded) this._expanded.add(element.identifier);
else this._expanded.delete(element.identifier);
}
/**
* Whether a row should render open. A node marked `expanded` seeds the set
* the first time it is seen, so a default-open section can still be closed
* by hand and stay closed.
*/
isExpanded(element) {
const id = element.identifier;
if (!id) return element.expanded === true;
if (!this._known.has(id)) {
this._known.add(id);
if (element.expanded) this._expanded.add(id);
}
return this._expanded.has(id);
}
/** Subclasses return an array of nodes (or a Promise of one). */
@@ -55,12 +84,12 @@ class NodeProvider {
}
getTreeItem(element) {
const collapsible =
element.children || element.load
? element.expanded
? TreeItemCollapsibleState.Expanded
: TreeItemCollapsibleState.Collapsed
: TreeItemCollapsibleState.None;
const expandable = Boolean(element.children || element.load);
const collapsible = !expandable
? TreeItemCollapsibleState.None
: this.isExpanded(element)
? TreeItemCollapsibleState.Expanded
: TreeItemCollapsibleState.Collapsed;
const item = new TreeItem(element.name, collapsible);
item.identifier = element.identifier;