11import { 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' ;
44import * as fs from 'fs' ;
55import * as path from 'path' ;
66import * as vscode from 'vscode' ;
@@ -54,7 +54,7 @@ export class ShowComponentHierarchy extends ShowHierarchyBase {
5454 this . extensionContext . subscriptions
5555 ) ;
5656
57- const components = ComponentManager . findComponents ( this . directoryPath ) ;
57+ const components = ComponentManager . scanWorkspaceForComponents ( this . directoryPath ) ;
5858
5959 this . nodes = [ ] ;
6060 this . edges = [ ] ;
@@ -88,21 +88,21 @@ export class ShowComponentHierarchy extends ShowHierarchyBase {
8888 }
8989 }
9090
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 ] ;
9494 if ( component . isRoot ) {
9595 this . generateDirectedGraphNodes ( component . subComponents , component , true , '' , appendNodes ) ;
96- this . generateDirectedGraphEdges ( component . subComponents , selector , "" , appendLinks ) ;
96+ this . generateDirectedGraphEdges ( componentDict , component . subComponents , component , "" , appendEdges ) ;
9797 }
9898 }
9999 }
100100
101101 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 , '.' ) ;
103103 componentFilename = componentFilename . split ( '\\' ) . join ( '/' ) ;
104104 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 ) ] ) ;
106106 if ( components . length > 0 ) {
107107 components . forEach ( ( subComponent ) => {
108108 if ( parentSelector !== subComponent . selector ) {
@@ -112,14 +112,20 @@ export class ShowComponentHierarchy extends ShowHierarchyBase {
112112 }
113113 }
114114
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 ) {
116116 if ( parentSelector . length > 0 ) {
117117 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 ) ] ) ;
119119 }
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 ) {
121127 subComponents . forEach ( ( subComponent ) => {
122- this . generateDirectedGraphEdges ( subComponent . subComponents , subComponent . selector , selector , appendLinks ) ;
128+ this . generateDirectedGraphEdges ( componentDict , subComponent . subComponents , subComponent , currentComponent . selector , appendEdges ) ;
123129 } ) ;
124130 }
125131 }
0 commit comments