Auto expand tree on search in node library tab (#558)

* Add custom nodelib searchbox

* Auto expand on search

* Support alphabetical sort in filtered tree
This commit is contained in:
Chenlei Hu
2024-08-20 11:01:05 -04:00
committed by GitHub
parent f3ab9cfb8e
commit c4bc0e8430
6 changed files with 96 additions and 44 deletions

View File

@@ -47,3 +47,24 @@ export function flattenTree<T>(tree: TreeNode): T[] {
}
return result
}
export function sortedTree(node: TreeNode): TreeNode {
// Create a new node with the same label and data
const newNode: TreeNode = {
...node
}
if (node.children) {
// Sort the children of the current node
const sortedChildren = [...node.children].sort((a, b) =>
a.label.localeCompare(b.label)
)
// Recursively sort the children and add them to the new node
newNode.children = []
for (const child of sortedChildren) {
newNode.children.push(sortedTree(child))
}
}
return newNode
}