MCPcopy Create free account
hub / github.com/triggerdotdev/jsonhero-web / calculatePathToNode

Function calculatePathToNode

app/hooks/useVirtualTree.ts:745–772  ·  view source on GitHub ↗
(
  nodes: T[],
  searchNode: T,
  path: string[] = []
)

Source from the content-addressed store, hash-verified

743}
744
745function calculatePathToNode<T extends { id: string; children?: T[] }>(
746 nodes: T[],
747 searchNode: T,
748 path: string[] = []
749): string[] | undefined {
750 const nodeIndex = nodes.findIndex((node) => node.id === searchNode.id);
751
752 if (nodeIndex !== -1) {
753 return [...path, searchNode.id];
754 }
755
756 for (const node of nodes) {
757 if (!node.children) {
758 continue;
759 }
760
761 const foundPath = calculatePathToNode(node.children || [], searchNode, [
762 ...path,
763 node.id,
764 ]);
765
766 if (foundPath && foundPath.length > path.length) {
767 return foundPath;
768 }
769 }
770
771 return;
772}

Callers 1

useVirtualTreeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected