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
109 lines
3.6 KiB
JavaScript
109 lines
3.6 KiB
JavaScript
//
|
|
// Generic TreeDataProvider over the node model. Subclasses only implement
|
|
// roots(); everything else — lazy children, TreeItem mapping — happens here.
|
|
//
|
|
|
|
const log = require("../util/log.js");
|
|
const { message } = require("./nodes.js");
|
|
|
|
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). */
|
|
roots() {
|
|
return [];
|
|
}
|
|
|
|
/** Drops memoised roots so the next getChildren rebuilds from the store. */
|
|
invalidate() {
|
|
this._roots = null;
|
|
}
|
|
|
|
async getChildren(element) {
|
|
try {
|
|
if (!element) {
|
|
if (!this._roots) {
|
|
this._roots = await this.roots();
|
|
// A section may hoist a repository's children to the top
|
|
// level; those nodes must not keep a parent Nova cannot see.
|
|
for (const root of this._roots) root.parent = null;
|
|
}
|
|
return this._roots;
|
|
}
|
|
|
|
if (element.children) return element.children;
|
|
|
|
if (element.load) {
|
|
const children = await element.load();
|
|
element.children = children || [];
|
|
for (const child of element.children) child.parent = element;
|
|
return element.children;
|
|
}
|
|
|
|
return [];
|
|
} catch (error) {
|
|
log.error("tree build failed", String(error && error.stack ? error.stack : error));
|
|
return [message(`⚠ ${error.message || error}`)];
|
|
}
|
|
}
|
|
|
|
getParent(element) {
|
|
return element ? element.parent : null;
|
|
}
|
|
|
|
getTreeItem(element) {
|
|
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;
|
|
item.contextValue = element.contextValue;
|
|
|
|
if (element.descriptiveText) item.descriptiveText = element.descriptiveText;
|
|
if (element.tooltip) item.tooltip = element.tooltip;
|
|
if (element.image) item.image = element.image;
|
|
if (element.path) item.path = element.path;
|
|
if (element.command) item.command = element.command;
|
|
|
|
return item;
|
|
}
|
|
}
|
|
|
|
exports.NodeProvider = NodeProvider;
|