Skip to content

Commit cd89395

Browse files
Fix cc flow sorting
1 parent b129dc5 commit cd89395

10 files changed

Lines changed: 190 additions & 163 deletions

File tree

example-project/src/auth/actions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010

1111
function authenticate(provider) {
1212
return dispatch => {
13-
//c1c:#signin#1;firebase auth;on success set
13+
//cc:#signin#1;firebase auth;on success set
1414
firebaseAuth.signInWithPopup(provider)
1515
.then(result => dispatch(signInSuccess(result)))
1616
.catch(error => dispatch(signInError(error)));

example-project/src/auth/reducer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export function authReducer(state = new AuthState(), {payload, type}) {
1313
case INIT_AUTH:
1414
case SIGN_IN_SUCCESS:
1515
return state.merge({
16-
authenticated: !!payload, //c1c:#signin#2;authenticated toggle
16+
authenticated: !!payload, //cc:#signin#2;authenticated toggle
1717
id: payload ? payload.uid : null
1818
});
1919

example-project/src/views/components/require-auth-route/require-auth-route.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { Route, Redirect } from 'react-router-dom'
33

4-
//c1c:#signin#3;authenticated flag
4+
//cc:#signin#3;authenticated flag
55
const RequireAuthRoute = ({component: Component, authenticated, ...rest}) => (
66
<Route
77
{...rest}

example-project/src/views/pages/sign-in/sign-in-page.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ SignInPage.propTypes = {
3333
//-------------------------------------
3434

3535
const mapDispatchToProps = {
36-
signInWithGithub: authActions.signInWithGithub, //c1c:#signin#0;dispatch action
36+
signInWithGithub: authActions.signInWithGithub, //cc:#signin#0;dispatch action
3737
signInWithGoogle: authActions.signInWithGoogle,
3838
signInWithTwitter: authActions.signInWithTwitter
3939
};

src/public/dist/bundle.js

Lines changed: 116 additions & 94 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/public/dist/bundle.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,10 @@
11
import React from 'react';
2+
import { connect } from 'react-redux';
3+
24
import { CodeCrumbedFlowEdge } from 'components/treeDiagram/component/Edge/CodeCrumbEdge';
35

46
const FlowEdge = props => {
5-
const {
6-
shiftToCenterPoint,
7-
fileNodesMap,
8-
selectedCrumbedFlowKey,
9-
codeCrumbedFlowsMap,
10-
codeCrumbsMinimize
11-
} = props;
12-
13-
const currentFlow = codeCrumbedFlowsMap[selectedCrumbedFlowKey] || {};
14-
15-
// TODO: this can be done on flowSelect
16-
let sortedFlowSteps = [];
17-
Object.keys(currentFlow).forEach(filePath => {
18-
const steps = ((fileNodesMap[filePath] && fileNodesMap[filePath].children) || [])
19-
.filter(({ data }) => data.params.flow === selectedCrumbedFlowKey)
20-
.map(({ data, x, y }) => ({
21-
name: data.name,
22-
filePath,
23-
step: data.params.flowStep,
24-
flow: selectedCrumbedFlowKey,
25-
x,
26-
y
27-
}));
28-
29-
sortedFlowSteps = sortedFlowSteps.concat(steps);
30-
});
31-
32-
sortedFlowSteps.sort((a, b) => a.step - b.step);
7+
const { shiftToCenterPoint, sortedFlowSteps, fileNodesMap, codeCrumbsMinimize } = props;
338

349
return (
3510
<React.Fragment>
@@ -62,4 +37,46 @@ const FlowEdge = props => {
6237
);
6338
};
6439

65-
export default FlowEdge;
40+
const getSortedFlowSteps = ({
41+
codeCrumbedFlowsMap,
42+
selectedCrumbedFlowKey,
43+
fileNodesMap
44+
}) => {
45+
const currentFlow = codeCrumbedFlowsMap[selectedCrumbedFlowKey] || {};
46+
let sortedFlowSteps = [];
47+
Object.keys(currentFlow).forEach(filePath => {
48+
const steps = ((fileNodesMap[filePath] && fileNodesMap[filePath].children) || [])
49+
.filter(({ data }) => data.params.flow === selectedCrumbedFlowKey)
50+
.map(({ data, x, y }) => ({
51+
name: data.name,
52+
filePath,
53+
step: data.params.flowStep,
54+
flow: selectedCrumbedFlowKey,
55+
x,
56+
y
57+
}));
58+
59+
sortedFlowSteps = sortedFlowSteps.concat(steps);
60+
});
61+
62+
sortedFlowSteps.sort((a, b) => a.step - b.step);
63+
64+
return sortedFlowSteps;
65+
};
66+
67+
const mapStateToProps = state => {
68+
const { checkedState } = state.viewSwitches;
69+
const { fileNodesMap, selectedCrumbedFlowKey, codeCrumbedFlowsMap } = state.dataBus;
70+
71+
return {
72+
sortedFlowSteps: getSortedFlowSteps({
73+
codeCrumbedFlowsMap,
74+
selectedCrumbedFlowKey,
75+
fileNodesMap
76+
}),
77+
fileNodesMap,
78+
codeCrumbsMinimize: checkedState.codeCrumbsMinimize
79+
};
80+
};
81+
82+
export default connect(mapStateToProps)(FlowEdge);

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@ import React from 'react';
22
import { connect } from 'react-redux';
33

44
import { selectCodeCrumb } from 'components/dataBus/store/actions';
5-
import FlowEdge from './FlowEdge';
65
import Tree from './Tree';
76

87
const mapStateToProps = state => {
98
const { checkedState } = state.viewSwitches;
10-
const { fileNodesMap, filesMap, selectedCrumbedFlowKey, codeCrumbedFlowsMap } = state.dataBus;
9+
const { fileNodesMap, filesMap, selectedCrumbedFlowKey } = state.dataBus;
1110

1211
return {
1312
fileNodesMap,
1413
filesMap,
1514
selectedCrumbedFlowKey,
16-
codeCrumbedFlowsMap,
1715
sourceDiagramOn: checkedState.source,
1816
dependenciesDiagramOn: checkedState.dependencies,
1917
codeCrumbsDiagramOn: checkedState.codeCrumbs,
@@ -26,8 +24,6 @@ const mapDispatchToProps = {
2624
onCodeCrumbSelect: selectCodeCrumb
2725
};
2826

29-
export const CodeCrumbedFlowEdges = connect(mapStateToProps)(FlowEdge);
30-
3127
export default connect(
3228
mapStateToProps,
3329
mapDispatchToProps

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import { Dot } from 'components/treeDiagram/component/Dot/index';
77
import { SourceEdge } from 'components/treeDiagram/component/Edge/SourceEdge';
88

99
import DependenciesTree from '../Dependencies/index';
10-
import CodeCrumbsTree, { CodeCrumbedFlowEdges } from '../CodeCrumbs/index';
10+
import CodeCrumbsTree from '../CodeCrumbs/';
11+
import CodeCrumbedFlowEdges from '../CodeCrumbs/FlowEdge';
1112

1213
const SourceTree = props => {
1314
const {

src/public/js/utils/treeLayout.js

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,49 +13,26 @@ export const getTreeLayout = (
1313
return [];
1414
}
1515

16-
if (openedFolders[data.path] === FOLDER_OPEN_STATE.OPEN_ACTIVE_CHILDREN_ONLY) {
17-
const filteredChildren = data.children.filter(child => activeItemsMap[child.path]);
18-
19-
// TODO: hide .. for folders where it doesn't change anything
20-
data.childrenCollapsed = filteredChildren.length !== data.children.length;
21-
// TODO: refactor sorting of flow steps
22-
if (data.childrenCollapsed && activeCodeCrumbs) {
23-
if (
24-
filteredChildren.length > 1 &&
25-
filteredChildren.filter(
26-
i =>
27-
i.type === FILE_NODE_TYPE &&
28-
i.hasCodecrumbs &&
29-
(i.children || []).find(({ params }) => activeCodeCrumbs[params.original])
30-
).length === filteredChildren.length
31-
) {
32-
filteredChildren.sort(
33-
(a, b) =>
34-
b.children.find(({ params }) => activeCodeCrumbs[params.original]).params
35-
.flowStep -
36-
a.children.find(({ params }) => activeCodeCrumbs[params.original]).params.flowStep
37-
);
38-
}
39-
}
40-
41-
return filteredChildren;
42-
}
16+
const children =
17+
openedFolders[data.path] === FOLDER_OPEN_STATE.OPEN_ACTIVE_CHILDREN_ONLY
18+
? data.children.filter(child => activeItemsMap[child.path])
19+
: data.children;
4320

44-
return data.children;
21+
return children.map(i => i).sort(sortCcFiles(activeCodeCrumbs));
4522
}
4623

4724
if (!includeFileChildren) {
4825
return [];
4926
}
5027

28+
// TODO: handle cc without flow here
5129
return !activeCodeCrumbs
5230
? data.children
5331
: (data.children || []).filter(({ params }) => activeCodeCrumbs[params.original]);
5432
},
5533
nodeSize: node => {
5634
let nameLength = node.data.name.length;
5735

58-
//cc: layout calc
5936
if (node.parent && node.data.type === DIR_NODE_TYPE) {
6037
const children = node.parent.children;
6138
nameLength = children.reduce((max, item) => {
@@ -76,6 +53,20 @@ export const getTreeLayout = (
7653
return layoutStructure(tree);
7754
};
7855

56+
export const sortCcFiles = activeCodeCrumbs => (a, b) => {
57+
if (a.type !== FILE_NODE_TYPE || b.type !== FILE_NODE_TYPE || (!a.children && !b.children)) {
58+
return 0;
59+
}
60+
61+
const bCc = (b.children || []).find(({ params = {} }) => activeCodeCrumbs[params.original]);
62+
const aCc = (a.children || []).find(({ params = {} }) => activeCodeCrumbs[params.original]);
63+
if (!bCc || !aCc) {
64+
return (bCc && !aCc) || (aCc && !bCc) ? -1 : 0;
65+
}
66+
67+
return bCc.params.flowStep > aCc.params.flowStep ? 1 : -1;
68+
};
69+
7970
export const getFileNodesMap = layoutNodes => {
8071
const map = {};
8172

0 commit comments

Comments
 (0)