MCPcopy Create free account
hub / github.com/bytebase/bytebase / buildSubTree

Function buildSubTree

frontend/src/react/stores/sqlEditor/tree-utils.ts:39–66  ·  view source on GitHub ↗
(
  databaseList: Database[],
  parent: TreeNode | undefined,
  factorList: Factor[],
  factorIndex: number
)

Source from the content-addressed store, hash-verified

37};
38
39const buildSubTree = (
40 databaseList: Database[],
41 parent: TreeNode | undefined,
42 factorList: Factor[],
43 factorIndex: number
44): TreeNode[] => {
45 if (factorIndex === factorList.length) {
46 return databaseList.map((db) => mapTreeNodeByType("database", db, parent));
47 }
48
49 const nodes: TreeNode[] = [];
50 const factor = factorList[factorIndex];
51
52 const groups = groupBy(databaseList, (db) =>
53 getSemanticFactorValue(db, factor)
54 );
55 for (const [value, childrenDatabaseList] of groups) {
56 const groupNode = mapGroupNode(factor, value, parent);
57 groupNode.children = buildSubTree(
58 childrenDatabaseList,
59 groupNode,
60 factorList,
61 factorIndex + 1
62 );
63 nodes.push(groupNode);
64 }
65 return sortNodesIfNeeded(nodes, factor);
66};
67
68const sortNodesIfNeeded = (nodes: TreeNode[], factor: Factor) => {
69 if (factor === "environment") {

Callers 1

buildTreeImplFunction · 0.85

Calls 5

groupByFunction · 0.90
getSemanticFactorValueFunction · 0.85
mapGroupNodeFunction · 0.85
sortNodesIfNeededFunction · 0.85
mapTreeNodeByTypeFunction · 0.70

Tested by

no test coverage detected