Passed
Pull Request — master (#37)
by
unknown
03:48
created

src/details/details-mappers.ts   A

Complexity

Total Complexity 1
Complexity/F 1

Size

Lines of Code 17
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 13
mnd 0
bc 0
fnc 1
dl 0
loc 17
rs 10
bpm 0
cpm 1
noi 0
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A details-mappers.ts ➔ mapNodeToTreeStructure 0 7 1
1
import { TreeNode } from '../components/types';
2
3
export interface TreeStructure {
4
    name: string;
5
    children?: TreeStructure[];
6
}
7
8
type TreeNodeWithVisitedFlag = TreeNode & { isVisited?: boolean };
9
10
export function mapNodeToTreeStructure(node: TreeNodeWithVisitedFlag, linksType: 'consumers' | 'providers'): TreeStructure {
11
    node.isVisited = true;
12
    const unvisitedLinks = node[linksType].filter((linkedNode: TreeNodeWithVisitedFlag) => !linkedNode.isVisited && linkedNode[linksType]);
13
    const children = unvisitedLinks.map(nestedNode => mapNodeToTreeStructure(nestedNode, linksType));
14
    node.isVisited = undefined;
15
    return { name: node.name, children };
16
}
17