1
1
import { ShowHierarchyBase } from './showHierarchyBase' ;
2
- import { Component , ComponentManager } from '@src' ;
3
- import { ArrowType , Edge , GraphState , Node , NodeType } from '@model' ;
2
+ import { ComponentManager } from '@src' ;
3
+ import { ArrowType , Component , Edge , GraphState , Node , NodeType } from '@model' ;
4
4
import * as fs from 'fs' ;
5
5
import * as path from 'path' ;
6
6
import * as vscode from 'vscode' ;
@@ -54,7 +54,7 @@ export class ShowComponentHierarchy extends ShowHierarchyBase {
54
54
this . extensionContext . subscriptions
55
55
) ;
56
56
57
- const components = ComponentManager . findComponents ( this . directoryPath ) ;
57
+ const components = ComponentManager . scanWorkspaceForComponents ( this . directoryPath ) ;
58
58
59
59
this . nodes = [ ] ;
60
60
this . edges = [ ] ;
@@ -88,21 +88,21 @@ export class ShowComponentHierarchy extends ShowHierarchyBase {
88
88
}
89
89
}
90
90
91
- private addNodesAndEdges ( componentHash : { [ selector : string ] : Component ; } , appendNodes : ( nodeList : Node [ ] ) => void , appendLinks : ( edgeList : Edge [ ] ) => void ) {
92
- for ( let selector in componentHash ) {
93
- const component = componentHash [ selector ] ;
91
+ private addNodesAndEdges ( componentDict : { [ selector : string ] : Component ; } , appendNodes : ( nodeList : Node [ ] ) => void , appendEdges : ( edgeList : Edge [ ] ) => void ) {
92
+ for ( let selector in componentDict ) {
93
+ const component = componentDict [ selector ] ;
94
94
if ( component . isRoot ) {
95
95
this . generateDirectedGraphNodes ( component . subComponents , component , true , '' , appendNodes ) ;
96
- this . generateDirectedGraphEdges ( component . subComponents , selector , "" , appendLinks ) ;
96
+ this . generateDirectedGraphEdges ( componentDict , component . subComponents , component , "" , appendEdges ) ;
97
97
}
98
98
}
99
99
}
100
100
101
101
private generateDirectedGraphNodes ( components : Component [ ] , component : Component , isRoot : boolean , parentSelector : string , appendNodes : ( nodeList : Node [ ] ) => void ) {
102
- let componentFilename = component . tsFilename . replace ( this . directoryPath , '.' ) ;
102
+ let componentFilename = component . filename . replace ( this . directoryPath , '.' ) ;
103
103
componentFilename = componentFilename . split ( '\\' ) . join ( '/' ) ;
104
104
const componentPosition = this . graphState . nodePositions [ component . selector ] ;
105
- appendNodes ( [ new Node ( component . selector , component . selector , componentFilename , component . tsFilename , isRoot , isRoot ? NodeType . rootNode : NodeType . component , componentPosition ) ] ) ;
105
+ appendNodes ( [ new Node ( component . selector , component . selector , componentFilename , component . filename , isRoot , isRoot ? NodeType . rootNode : NodeType . component , componentPosition ) ] ) ;
106
106
if ( components . length > 0 ) {
107
107
components . forEach ( ( subComponent ) => {
108
108
if ( parentSelector !== subComponent . selector ) {
@@ -112,14 +112,20 @@ export class ShowComponentHierarchy extends ShowHierarchyBase {
112
112
}
113
113
}
114
114
115
- private generateDirectedGraphEdges ( subComponents : Component [ ] , selector : string , parentSelector : string , appendLinks : ( edgeList : Edge [ ] ) => void ) {
115
+ private generateDirectedGraphEdges ( componentDict : { [ selector : string ] : Component ; } , subComponents : Component [ ] , currentComponent : Component , parentSelector : string , appendEdges : ( edgeList : Edge [ ] ) => void ) {
116
116
if ( parentSelector . length > 0 ) {
117
117
const id = this . edges . length ;
118
- appendLinks ( [ new Edge ( id . toString ( ) , parentSelector , selector , ArrowType . uses ) ] ) ;
118
+ appendEdges ( [ new Edge ( id . toString ( ) , parentSelector , currentComponent . selector , ArrowType . uses ) ] ) ;
119
119
}
120
- if ( subComponents . length > 0 && selector !== parentSelector ) {
120
+ if ( currentComponent . componentsRoutingToThis !== undefined && currentComponent . componentsRoutingToThis . length > 0 ) {
121
+ currentComponent . componentsRoutingToThis . forEach ( componentRoutingToThis => {
122
+ const id = this . edges . length ;
123
+ appendEdges ( [ new Edge ( id . toString ( ) , componentRoutingToThis . selector , currentComponent . selector , ArrowType . route ) ] ) ;
124
+ } ) ;
125
+ }
126
+ if ( subComponents . length > 0 && currentComponent . selector !== parentSelector ) {
121
127
subComponents . forEach ( ( subComponent ) => {
122
- this . generateDirectedGraphEdges ( subComponent . subComponents , subComponent . selector , selector , appendLinks ) ;
128
+ this . generateDirectedGraphEdges ( componentDict , subComponent . subComponents , subComponent , currentComponent . selector , appendEdges ) ;
123
129
} ) ;
124
130
}
125
131
}
0 commit comments