MCPcopy Create free account
hub / github.com/pgadmin-org/pgadmin4 / findInTree

Function findInTree

web/pgadmin/static/js/tree/tree.js:608–635  ·  view source on GitHub ↗
(rootNode, path)

Source from the content-addressed store, hash-verified

606 * the new tree to find the node that matches the path
607 */
608export function findInTree(rootNode, path) {
609 if (path === null) {
610 return rootNode;
611 }
612 return (function findInNode(currentNode) {
613
614 /* No point in checking the children if
615 * the path for currentNode itself is not matching
616 */
617 if (currentNode.path !== undefined && path !== undefined
618 && !path.startsWith(currentNode.path)) {
619 return null;
620 }
621
622 for (let i = 0, length = currentNode.children.length; i < length; i++) {
623 const calculatedNode = findInNode(currentNode.children[i]);
624 if (calculatedNode !== null) {
625 return calculatedNode;
626 }
627 }
628
629 if (currentNode.path === path) {
630 return currentNode;
631 } else {
632 return null;
633 }
634 })(rootNode);
635}
636
637const isValidTreeNodeData = (data) => (!_.isEmpty(data));
638

Callers 2

findNodeMethod · 0.90
findNodeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected