@@ -2,13 +2,30 @@ import React from 'react';
22import { connect } from 'react-redux' ;
33
44import { NO_TRAIL_FLOW } from 'core/constants' ;
5- import { CodeCrumbedFlowEdge } from 'components/treeDiagram/component/Edge/CodeCrumbEdge' ;
5+ import {
6+ CodeCrumbedFlowEdge ,
7+ ExternalEdge
8+ } from 'components/treeDiagram/component/Edge/CodeCrumbEdge' ;
69
710import { getCheckedState } from 'core/controlsBus/selectors' ;
8- import { getSourceLayout , getCodeCrumbsUserChoice } from 'core/dataBus/selectors' ;
11+ import {
12+ getNamespacesList ,
13+ getSourceLayout ,
14+ getCodeCrumbsUserChoice
15+ } from 'core/dataBus/selectors' ;
916
1017const FlowEdge = props => {
11- const { shiftToCenterPoint, sortedFlowSteps, filesLayoutMap, codeCrumbsMinimize } = props ;
18+ const {
19+ namespace,
20+ areaHeight,
21+ namespacesList,
22+ shiftToCenterPoint,
23+ sortedFlowSteps,
24+ filesLayoutMapNs,
25+ codeCrumbsMinimize
26+ } = props ;
27+
28+ const filesLayoutMap = filesLayoutMapNs [ namespace ] ;
1229
1330 return (
1431 < React . Fragment >
@@ -17,14 +34,55 @@ const FlowEdge = props => {
1734 if ( ! i ) return null ;
1835
1936 const fromItem = list [ i - 1 ] ;
20- const fromFile = filesLayoutMap [ fromItem . filePath ] ;
21- const toFile = filesLayoutMap [ toItem . filePath ] ;
37+ if ( fromItem . namespace !== namespace && toItem . namespace !== namespace ) {
38+ return null ;
39+ }
2240
2341 const edgePoints = [ fromItem , toItem ] . map ( crumb => {
2442 const [ cX , cY ] = [ crumb . y , crumb . x ] ;
2543 return shiftToCenterPoint ( cX , cY ) ;
2644 } ) ;
2745
46+ const namespaceIndex = namespacesList . indexOf ( namespace ) ;
47+
48+ if ( fromItem . namespace === namespace && toItem . namespace !== namespace ) {
49+ const fromFile = filesLayoutMap [ fromItem . filePath ] ;
50+ const toFile = filesLayoutMapNs [ toItem . namespace ] [ toItem . filePath ] ;
51+
52+ return (
53+ < ExternalEdge
54+ key = { `cc-external-edge-${ fromItem . name } -${ toItem . name } ` }
55+ sourcePosition = { edgePoints [ 0 ] }
56+ targetPosition = { edgePoints [ 1 ] }
57+ singleCrumbSource = { fromFile . children . length === 1 }
58+ singleCrumbTarget = { toFile . children . length === 1 }
59+ areaHeight = { areaHeight }
60+ topBottom = { namespaceIndex < namespacesList . indexOf ( toItem . namespace ) }
61+ firstPart = { true }
62+ />
63+ ) ;
64+ }
65+
66+ if ( fromItem . namespace !== namespace && toItem . namespace === namespace ) {
67+ const fromFile = filesLayoutMapNs [ fromItem . namespace ] [ fromItem . filePath ] ;
68+ const toFile = filesLayoutMap [ toItem . filePath ] ;
69+
70+ return (
71+ < ExternalEdge
72+ key = { `cc-external-edge-${ fromItem . name } -${ toItem . name } ` }
73+ sourcePosition = { edgePoints [ 0 ] }
74+ targetPosition = { edgePoints [ 1 ] }
75+ singleCrumbSource = { fromFile . children . length === 1 }
76+ singleCrumbTarget = { toFile . children . length === 1 }
77+ areaHeight = { areaHeight }
78+ topBottom = { namespaceIndex < namespacesList . indexOf ( fromItem . namespace ) }
79+ />
80+ ) ;
81+ }
82+
83+ const fromFile = filesLayoutMap [ fromItem . filePath ] ;
84+ const toFile = filesLayoutMap [ toItem . filePath ] ;
85+
2886 return (
2987 < CodeCrumbedFlowEdge
3088 key = { `cc-flow-edge-${ fromItem . name } -${ toItem . name } ` }
@@ -41,13 +99,23 @@ const FlowEdge = props => {
4199 ) ;
42100} ;
43101
44- const getSortedFlowSteps = ( { codeCrumbedFlowsMap, selectedCrumbedFlowKey, filesLayoutMap } ) => {
102+ const stepSorter = ( a , b ) => a . step - b . step ;
103+
104+ // TODO: this should be done in reducer
105+ const getSortedFlowSteps = ( {
106+ namespace,
107+ codeCrumbedFlowsMap,
108+ selectedCrumbedFlowKey,
109+ filesLayoutMap
110+ } ) => {
45111 const currentFlow = codeCrumbedFlowsMap [ selectedCrumbedFlowKey ] || { } ;
46112 let sortedFlowSteps = [ ] ;
113+
47114 Object . keys ( currentFlow ) . forEach ( filePath => {
48115 const steps = ( ( filesLayoutMap [ filePath ] && filesLayoutMap [ filePath ] . children ) || [ ] )
49116 . filter ( ( { data } ) => data . params . flow === selectedCrumbedFlowKey )
50117 . map ( ( { data, x, y } ) => ( {
118+ namespace,
51119 name : data . name ,
52120 filePath,
53121 step : data . params . flowStep ,
@@ -59,37 +127,59 @@ const getSortedFlowSteps = ({ codeCrumbedFlowsMap, selectedCrumbedFlowKey, files
59127 sortedFlowSteps = sortedFlowSteps . concat ( steps ) ;
60128 } ) ;
61129
62- sortedFlowSteps . sort ( ( a , b ) => a . step - b . step ) ;
130+ sortedFlowSteps . sort ( stepSorter ) ;
63131
64132 return sortedFlowSteps ;
65133} ;
66134
67135const mapStateToProps = ( state , props ) => {
68136 const { codeCrumbsMinimize } = getCheckedState ( state ) ;
69-
137+ const namespacesList = getNamespacesList ( state ) ;
70138 const { namespace } = props ;
71- const namespaceProps = { namespace } ;
72139
73- const { filesLayoutMap } = getSourceLayout ( state , namespaceProps ) ;
74- const { selectedCrumbedFlowKey, codeCrumbedFlowsMap } = getCodeCrumbsUserChoice (
75- state ,
76- namespaceProps
77- ) ;
140+ const { selectedCrumbedFlowKey : currentSelectedCrumbedFlowKey } = getCodeCrumbsUserChoice ( state , {
141+ namespace
142+ } ) ;
78143
79- // TODO: ftw is this
80- const sortedFlowSteps =
81- selectedCrumbedFlowKey !== NO_TRAIL_FLOW
82- ? getSortedFlowSteps ( {
83- codeCrumbedFlowsMap,
84- selectedCrumbedFlowKey,
85- filesLayoutMap
86- } )
87- : [ ] ;
144+ const gatheredFlowsData = namespacesList . reduce (
145+ ( acc , ns ) => {
146+ const namespaceProps = { namespace : ns } ;
147+ const { selectedCrumbedFlowKey, codeCrumbedFlowsMap } = getCodeCrumbsUserChoice (
148+ state ,
149+ namespaceProps
150+ ) ;
151+
152+ if ( currentSelectedCrumbedFlowKey !== selectedCrumbedFlowKey ) {
153+ return acc ;
154+ }
155+
156+ const { filesLayoutMap } = getSourceLayout ( state , namespaceProps ) ;
157+
158+ const sortedFlowSteps =
159+ selectedCrumbedFlowKey !== NO_TRAIL_FLOW
160+ ? getSortedFlowSteps ( {
161+ namespace : ns ,
162+ codeCrumbedFlowsMap,
163+ selectedCrumbedFlowKey,
164+ filesLayoutMap
165+ } )
166+ : [ ] ;
167+
168+ return {
169+ sortedFlowSteps : [ ...acc . sortedFlowSteps , ...sortedFlowSteps ] . sort ( stepSorter ) ,
170+ filesLayoutMapNs : {
171+ ...acc . filesLayoutMapNs ,
172+ [ ns ] : filesLayoutMap
173+ }
174+ } ;
175+ } ,
176+ { filesLayoutMapNs : { } , sortedFlowSteps : [ ] }
177+ ) ;
88178
89179 return {
90- sortedFlowSteps ,
91- filesLayoutMap ,
92- codeCrumbsMinimize
180+ namespacesList ,
181+ codeCrumbsMinimize ,
182+ ... gatheredFlowsData
93183 } ;
94184} ;
95185
0 commit comments