* Close a given node and update the tree state. * @param nodeId The id of the node that is being closed.
(nodeId: string)
| 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. |
no test coverage detected