( databaseList: Database[], parent: TreeNode | undefined, factorList: Factor[], factorIndex: number )
| 37 | }; |
| 38 | |
| 39 | const 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 | |
| 68 | const sortNodesIfNeeded = (nodes: TreeNode[], factor: Factor) => { |
| 69 | if (factor === "environment") { |
no test coverage detected