MCPcopy
hub / github.com/wavetermdev/waveterm / closeNode

Method closeNode

frontend/layout/lib/layoutModel.ts:1285–1312  ·  view source on GitHub ↗

* Close a given node and update the tree state. * @param nodeId The id of the node that is being closed.

(nodeId: string)

Source from the content-addressed store, hash-verified

1283 * @param nodeId The id of the node that is being closed.
1284 */
1285 async closeNode(nodeId: string) {
1286 const nodeToDelete = findNode(this.treeState.rootNode, nodeId);
1287 if (!nodeToDelete) {
1288 // TODO: clean up the ephemeral node handling
1289 // The ephemeral node is not in the tree, so we need to handle it separately.
1290 const ephemeralNode = this.getter(this.ephemeralNode);
1291 if (ephemeralNode?.id === nodeId) {
1292 this.setter(this.ephemeralNode, undefined);
1293 this.treeState.focusedNodeId = undefined;
1294 this.updateTree(false);
1295 this.setter(this.localTreeStateAtom, { ...this.treeState });
1296 this.persistToBackend();
1297 await this.onNodeDelete?.(ephemeralNode.data);
1298 return;
1299 }
1300 console.error("unable to close node, cannot find it in tree", nodeId);
1301 return;
1302 }
1303 if (nodeId === this.magnifiedNodeId) {
1304 this.magnifyNodeToggle(nodeId);
1305 }
1306 const deleteAction: LayoutTreeDeleteNodeAction = {
1307 type: LayoutTreeActionType.DeleteNode,
1308 nodeId: nodeId,
1309 };
1310 this.treeReducer(deleteAction);
1311 await this.onNodeDelete?.(nodeToDelete.data);
1312 }
1313
1314 /**
1315 * Shorthand function for closing the focused node in a layout.

Callers 6

handleBackendActionMethod · 0.95
getNodeModelMethod · 0.95
closeFocusedNodeMethod · 0.95
newEphemeralNodeMethod · 0.95
NodeBackdropsFunction · 0.80
uxCloseBlockFunction · 0.80

Calls 5

updateTreeMethod · 0.95
persistToBackendMethod · 0.95
magnifyNodeToggleMethod · 0.95
treeReducerMethod · 0.95
findNodeFunction · 0.90

Tested by

no test coverage detected