Skip to content

Commit 05cb552

Browse files
fix: peformance for flow steps
1 parent 7d910a0 commit 05cb552

File tree

18 files changed

+174
-155
lines changed

18 files changed

+174
-155
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
"lodash.debounce": "^4.0.8",
4343
"madge": "^3.4.4",
4444
"portscanner": "^2.2.0",
45-
"react": "^16.7.0",
46-
"react-dom": "^16.7.0",
45+
"react": "^16.8.6",
46+
"react-dom": "^16.8.6",
4747
"react-redux": "^5.0.7",
4848
"react-syntax-highlighter": "8.0.1",
4949
"redux": "^4.0.0",

src/public/js/components/sideBar/component/Code/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const PADDING_TOP = 5;
1111
//TODO: add select with several themes
1212
//TODO: scrool to/highlight crumbed lines
1313
//https://github.com/conorhastings/react-syntax-highlighter/blob/master/README.md
14-
export default class extends React.Component {
14+
export default class extends React.PureComponent {
1515
fixScroll() {
1616
const { dependenciesLines = [], crumbedLines = [], lineHeight } = this.props;
1717
if (!this.codeRef || !this.codeRef.scrollTo) {

src/public/js/components/sideBar/component/CrumbsTab/index.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import 'antd/es/alert/style';
88

99
import { NO_TRAIL_FLOW } from '../../../../shared-constants';
1010
import { getCodeCrumbsUserChoice } from '../../../../core/dataBus/selectors';
11-
import { getNamespacesList } from '../../../../core/dataBus/selectors';
12-
import { gatherFlowStepsData } from '../../../treeDiagram/component/Tree/CodeCrumbs/helpers';
11+
import { getSharedFlowStepsData } from '../../../../core/namespaceIntegration/selectors';
1312

1413
import Code from '../Code';
1514
import './index.less';
@@ -58,7 +57,6 @@ const CrumbsTab = props => {
5857
};
5958

6059
const mapStateToProps = (state, props) => {
61-
const namespacesList = getNamespacesList(state);
6260
const { namespace } = props;
6361

6462
const {
@@ -69,10 +67,7 @@ const mapStateToProps = (state, props) => {
6967
namespace
7068
});
7169

72-
const { involvedNsData, sortedFlowSteps } = gatherFlowStepsData(state, {
73-
currentSelectedCrumbedFlowKey,
74-
namespacesList
75-
});
70+
const { involvedNsData, sortedFlowSteps } = getSharedFlowStepsData(state);
7671

7772
if (currentSelectedCrumbedFlowKey === NO_TRAIL_FLOW) {
7873
return {

src/public/js/components/topBar/controls/ViewSwitches/Item/ViewSwitch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import 'antd/es/icon/style';
1212
import { VIEW_TYPES } from '../../../../../core/controlsBus/constants';
1313
import './ViewSwitch.less';
1414

15-
class ViewSwitch extends React.Component {
15+
class ViewSwitch extends React.PureComponent {
1616
renderMenu() {
1717
const {
1818
name,

src/public/js/components/treeDiagram/component/Tree/CodeCrumbs/ExtraInfo/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const DetailsComponent = props => {
3535
};
3636

3737
const ccUnderlayPaddingH = 20;
38-
class CodeComponent extends React.Component {
38+
class CodeComponent extends React.PureComponent {
3939
state = {};
4040

4141
onMouseEnter = () => {
@@ -101,7 +101,7 @@ const ExtraInfoSet = ({
101101
namespace,
102102
language
103103
}) => {
104-
if (!detailsEnabled && !codePreviewEnabled) return null;
104+
if ((!detailsEnabled && !codePreviewEnabled) || !sortedFlowSteps) return null;
105105

106106
const crumbs = sortedFlowSteps.length ? sortedFlowSteps : flowSteps;
107107
return (

src/public/js/components/treeDiagram/component/Tree/CodeCrumbs/FlowEdge.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ export default props => {
1717
selectedCcFlowEdgeNodes
1818
} = props;
1919

20+
if (!involvedNsData || !involvedNsData[namespace]) {
21+
return null;
22+
}
23+
2024
const { codecrumbsLayoutMap } = involvedNsData[namespace];
2125
const ccNamespacesKeys = Object.keys(involvedNsData || {});
2226

src/public/js/components/treeDiagram/component/Tree/CodeCrumbs/Tree.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ const Tree = props => {
1919
selectedCcFlowEdgeNodes
2020
} = props;
2121

22+
if (!ccShiftIndexMap) {
23+
return null;
24+
}
25+
2226
return (
2327
<React.Fragment>
2428
{Object.keys(codecrumbsLayoutMap).map(key => {
Lines changed: 0 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import { getCodeCrumbsUserChoice, getSourceLayout } from '../../../../../core/dataBus/selectors';
2-
import { NO_TRAIL_FLOW } from '../../../../../core/constants';
3-
41
export const isCodeCrumbsEqual = (cc, currentCc) =>
52
cc.name === currentCc.name && cc.flowStep === currentCc.flowStep;
63

@@ -13,100 +10,4 @@ export const isCodeCrumbSelected = (selectedCcFlowEdgeNodes, cc) => {
1310
);
1411
};
1512

16-
const stepSorter = (a, b) => a.step - b.step;
17-
18-
const getFlowSteps = ({
19-
namespace,
20-
codeCrumbedFlowsMap,
21-
selectedCrumbedFlowKey,
22-
codecrumbsLayoutMap
23-
}) => {
24-
const currentFlow = codeCrumbedFlowsMap[selectedCrumbedFlowKey] || {};
25-
26-
return Object.keys(currentFlow).reduce((flowSteps, filePath) => {
27-
const steps = ((codecrumbsLayoutMap[filePath] && codecrumbsLayoutMap[filePath].children) || [])
28-
.filter(({ data }) => data.params.flow === selectedCrumbedFlowKey)
29-
.map(({ data, x, y }) => ({
30-
...data,
31-
namespace,
32-
filePath,
33-
step: data.params.flowStep,
34-
flow: selectedCrumbedFlowKey,
35-
x,
36-
y
37-
}));
38-
39-
return [...flowSteps, ...steps];
40-
}, []);
41-
};
42-
43-
const createCcShiftIndexMap = sortedFlowSteps => {
44-
const ccMap = {};
45-
let shiftOrderIndex = 0;
46-
47-
sortedFlowSteps.forEach((crumb, i, list) => {
48-
if (!i) {
49-
ccMap[crumb.id] = shiftOrderIndex;
50-
return;
51-
}
52-
53-
if (crumb.x < list[i - 1].x) {
54-
shiftOrderIndex++;
55-
}
56-
57-
ccMap[crumb.id] = shiftOrderIndex;
58-
});
59-
60-
return ccMap;
61-
};
62-
63-
export const gatherFlowStepsData = (state, { namespacesList, currentSelectedCrumbedFlowKey }) => {
64-
const flowStepsData = namespacesList.reduce(
65-
(acc, ns) => {
66-
const namespaceProps = { namespace: ns };
67-
const { selectedCrumbedFlowKey, codeCrumbedFlowsMap } = getCodeCrumbsUserChoice(
68-
state,
69-
namespaceProps
70-
);
71-
72-
if (currentSelectedCrumbedFlowKey !== selectedCrumbedFlowKey) {
73-
return acc;
74-
}
75-
76-
const { codecrumbsLayoutMap, ccAlightPoint } = getSourceLayout(state, namespaceProps);
77-
78-
const flowSteps = getFlowSteps({
79-
namespace: ns,
80-
codeCrumbedFlowsMap,
81-
selectedCrumbedFlowKey,
82-
codecrumbsLayoutMap
83-
});
84-
85-
return {
86-
flowSteps,
87-
sortedFlowSteps:
88-
selectedCrumbedFlowKey !== NO_TRAIL_FLOW
89-
? [...acc.sortedFlowSteps, ...flowSteps].sort(stepSorter)
90-
: [],
91-
involvedNsData: {
92-
...acc.involvedNsData,
93-
[ns]: { codecrumbsLayoutMap, ccAlightPoint }
94-
}
95-
};
96-
},
97-
{ involvedNsData: {}, flowSteps: [], sortedFlowSteps: [] }
98-
);
99-
100-
return {
101-
...flowStepsData,
102-
ccShiftIndexMap: createCcShiftIndexMap(flowStepsData.sortedFlowSteps)
103-
};
104-
};
105-
10613
export const getCcPosition = (x, index = 0) => x + 70 * index;
107-
108-
export const getMaxWidthForNs = (state, { namespacesList }) =>
109-
namespacesList.reduce((maxWidth, namespace) => {
110-
const { layoutSize } = getSourceLayout(state, { namespace });
111-
return layoutSize && layoutSize.width > maxWidth ? layoutSize.width : maxWidth;
112-
}, 0);

src/public/js/components/treeDiagram/component/Tree/Source/Tree.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ const SourceTree = props => {
114114
selectedNodeDependencies[path] &&
115115
!selectedNodeDependencies[path].importedModuleNames.length
116116
}
117-
onNodeClick={e => onFileNodeClick(e, fileNode)}
117+
onNodeClick={e => selectedNode !== fileNode && onFileNodeClick(e, fileNode)}
118118
/>
119119
);
120120
} else if (type === DIR_NODE_TYPE) {

src/public/js/components/treeDiagram/component/TreeDiagram.js

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,17 @@ import { UnderLayer } from './UnderLayer';
88
import './TreeDiagram.less';
99

1010
import { buildShiftToPoint } from '../../../core/dataBus/utils/geometry';
11-
import {
12-
getProjectMetadata,
13-
getSourceLayout,
14-
getCodeCrumbsUserChoice,
15-
getNamespacesList
16-
} from '../../../core/dataBus/selectors';
11+
import { getProjectMetadata, getSourceLayout } from '../../../core/dataBus/selectors';
1712
import { getCheckedState, getValuesState } from '../../../core/controlsBus/selectors';
1813
import {
1914
selectDependencyEdge,
2015
selectCcFlowEdge,
2116
saveTreeDiagramContentId
2217
} from '../../../core/dataBus/actions';
2318
import { setActiveNamespace } from '../../../core/namespaceIntegration/actions';
24-
import { gatherFlowStepsData, getMaxWidthForNs } from './Tree/CodeCrumbs/helpers';
19+
import { getSharedFlowStepsData } from '../../../core/namespaceIntegration/selectors';
2520

26-
class TreeDiagram extends React.Component {
21+
class TreeDiagram extends React.PureComponent {
2722
componentDidUpdate(prevProps) {
2823
if (!prevProps.layoutSize && this.props.layoutSize) {
2924
this.props.saveContentId(this.treeDiagramContent.getAttribute('id'));
@@ -121,31 +116,7 @@ const mapStateToProps = (state, props) => {
121116
const { diagramZoom } = getValuesState(state);
122117
const { codeCrumbsDiagramOn } = getCheckedState(state);
123118

124-
let extendedCcProps = {};
125-
if (codeCrumbsDiagramOn) {
126-
const codeCrumbsUserChoice = getCodeCrumbsUserChoice(state, {
127-
namespace
128-
});
129-
130-
const namespacesList = getNamespacesList(state);
131-
const { flowSteps, sortedFlowSteps, involvedNsData, ccShiftIndexMap } = gatherFlowStepsData(
132-
state,
133-
{
134-
currentSelectedCrumbedFlowKey: codeCrumbsUserChoice.selectedCrumbedFlowKey,
135-
namespacesList
136-
}
137-
);
138-
139-
const maxWidth = getMaxWidthForNs(state, { namespacesList });
140-
141-
extendedCcProps = {
142-
flowSteps,
143-
sortedFlowSteps,
144-
involvedNsData,
145-
ccShiftIndexMap,
146-
maxWidth
147-
};
148-
}
119+
const extendedCcProps = codeCrumbsDiagramOn ? getSharedFlowStepsData(state) : {};
149120

150121
return {
151122
namespace,

0 commit comments

Comments
 (0)