Skip to content

Commit 10801a0

Browse files
authored
Merge pull request #22 from diegovazquezny/fix-del
Added resources folder
2 parents ebf00cb + f4d6724 commit 10801a0

File tree

15 files changed

+122
-17
lines changed

15 files changed

+122
-17
lines changed

app/electron/menu.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var MenuBuilder = function(mainWindow, appName) {
2626
contextIsolation: true,
2727
enableRemoteModule: false,
2828
zoomFactor: 1.0,
29-
devTools: false
29+
// devTools: false
3030
}
3131
});
3232
tutorial.loadURL(`http://localhost:8080/#/tutorial`);

app/src/components/main/Canvas.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import renderChildren from '../../helperFunctions/renderChildren';
88

99
function Canvas() {
1010
const [state, dispatch] = useContext(StateContext);
11+
console.log('state.comps', state.components);
1112

1213
// find the current component to render on the canvas
1314
const currentComponent: Component = state.components.find(

app/src/containers/RightContainer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,9 @@ const RightContainer = (): JSX.Element => {
215215
}
216216

217217
const handleDeleteReusableComponent = () => {
218-
isChildOfPage()
218+
/*isChildOfPage()
219219
? handleDialogError('component')
220-
: dispatch({ type: 'DELETE REUSABLE COMPONENT', payload: {} });
220+
:*/ dispatch({ type: 'DELETE REUSABLE COMPONENT', payload: {} });
221221
};
222222

223223
const isReusable = (configTarget): boolean => {

app/src/helperFunctions/renderChildren.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
import React from 'react';
1+
import React, { useContext } from 'react';
22
import { ChildElement } from '../interfaces/Interfaces';
33
import DirectChildComponent from '../components/main/DirectChildComponent';
44
import DirectChildHTML from '../components/main/DirectChildHTML';
55
import DirectChildHTMLNestable from '../components/main/DirectChildHTMLNestable';
66
import RouteLink from '../components/main/RouteLink';
7+
import { StateContext } from '../context/context';
78

89
// helper method to render all direct children of a component
910
// direct children are clickable and draggable
1011
// direct children may also have their own indirect children (grandchildren, great-grandchildren, etc) which are not draggable and clickable
1112
// there are four types of direct children that can be rendered on the screen
1213
const renderChildren = (children: ChildElement[]) => {
14+
const [state, dispatch] = useContext(StateContext);
1315
return children.map((child: ChildElement, i: number) => {
14-
console.log('child', child);
15-
const { type, typeId, style, childId, children, attributes } = child;
16+
const { type, typeId, style, childId, children, attributes, name } = child;
17+
if (name === '') child.name = state.components[typeId - 1 ].name;
1618
// A DirectChildComponent is an instance of a top level component
1719
// This component will render IndirectChild components (div/components rendered inside a child component)
1820
if (type === 'Component') {
@@ -23,6 +25,7 @@ const renderChildren = (children: ChildElement[]) => {
2325
typeId={typeId}
2426
style={style}
2527
key={'DirChild' + childId.toString()}
28+
name={child.name}
2629
/>
2730
);
2831
}
@@ -35,6 +38,7 @@ const renderChildren = (children: ChildElement[]) => {
3538
typeId={typeId}
3639
style={style}
3740
key={'DirChild' + childId.toString()}
41+
name={child.name}
3842
/>
3943
);
4044
}
@@ -48,6 +52,7 @@ const renderChildren = (children: ChildElement[]) => {
4852
style={style}
4953
children={children}
5054
key={'DirChild' + childId.toString()}
55+
name={child.name}
5156
/>
5257
);
5358
}
@@ -62,6 +67,7 @@ const renderChildren = (children: ChildElement[]) => {
6267
style={style}
6368
children={children}
6469
key={'DirChild' + childId.toString()}
70+
name={child.name}
6571
/>
6672
);
6773
}

app/src/reducers/componentReducer.ts

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,23 @@ const reducer = (state: State, action: Action) => {
8989
};
9090

9191
const updateIds = (components: Component[]) => {
92+
// component IDs should be array index + 1
9293
components.forEach((comp, i) => (comp.id = i + 1));
94+
95+
// create KV pairs of component names and corresponding IDs
96+
const componentIds = {};
97+
components.forEach(component => {
98+
if (!component.isPage ) componentIds[component.name] = component.id;
99+
});
100+
101+
// assign correct ID to components that are children inside of remaining pages
102+
components.forEach(page => {
103+
if (page.isPage) {
104+
page.children.forEach(child => {
105+
if (child.type === 'Component') child.typeId = componentIds[child.name];
106+
});
107+
}
108+
});
93109
};
94110

95111
const updateRoots = (components: Component[]) => {
@@ -110,6 +126,25 @@ const reducer = (state: State, action: Action) => {
110126
}
111127
}
112128

129+
const deleteComponentFromPages = (components, name) => {
130+
const searchNestedComps = (childComponents) => {
131+
console.log(childComponents);
132+
if (childComponents.length === 0) return;
133+
childComponents.forEach((comp, i) => {
134+
if (comp.isPage){
135+
comp.children.forEach((child, i, arr) => {
136+
if (child.name === name) {
137+
arr.splice(i, 1);
138+
}
139+
})
140+
}
141+
searchNestedComps(childComponents.children)
142+
});
143+
}
144+
components.forEach(comp => searchNestedComps(comp.children));
145+
console.log(components);
146+
}
147+
113148
switch (action.type) {
114149
case 'ADD COMPONENT': {
115150
if (
@@ -119,7 +154,7 @@ const reducer = (state: State, action: Action) => {
119154
return state;
120155

121156
const components = [...state.components];
122-
157+
console.log('adding =>', action.payload.componentName);
123158
const newComponent = {
124159
id: state.components.length + 1,
125160
name: action.payload.componentName,
@@ -129,7 +164,7 @@ const reducer = (state: State, action: Action) => {
129164
children: [],
130165
isPage: action.payload.root
131166
};
132-
167+
console.log('new comp =>', newComponent);
133168
components.push(newComponent);
134169

135170
const rootComponents = [...state.rootComponents];
@@ -200,7 +235,7 @@ const reducer = (state: State, action: Action) => {
200235
}
201236
const newChild: ChildElement = {
202237
type,
203-
typeId: components.length + 1,
238+
typeId,
204239
name: newName,
205240
childId: state.nextChildId,
206241
style: {},
@@ -353,8 +388,14 @@ const reducer = (state: State, action: Action) => {
353388
}
354389
case 'DELETE REUSABLE COMPONENT' : {
355390
const id: number = state.canvasFocus.componentId;
391+
const name: string = state.components[id - 1].name;
392+
console.log(name);
356393
const components: Component[] = deleteById(id);
357394
updateIds(components);
395+
396+
// check if reusable comp is inside a page
397+
deleteComponentFromPages(components, name);
398+
358399
const canvasFocus = { componentId: 1, childId: null };
359400

360401
const rootComponents = updateRoots(components);

app/src/tree/TreeChart.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ function TreeChart({ data }) {
2929
// will be called initially and on every data change
3030
useEffect(() => {
3131
const svg = select(svgRef.current);
32-
3332
// use dimensions from useResizeObserver,
3433
// but use getBoundingClientRect on initial render
3534
// (dimensions are null for the first render)
3635
const { width, height } =
37-
dimensions || wrapperRef.current.getBoundingClientRect();
36+
dimensions || wrapperRef.current.getBoundingClientRect();
3837
// transform hierarchical data
3938
const root = hierarchy(data[canvasId - 1]);
4039
const treeLayout = tree().size([height, width - 125]);
40+
//console.log(root);
4141

4242
// Returns a new link generator with horizontal display.
4343
// To visualize links in a tree diagram rooted on the left edge of the display

app/src/tutorial/ComponentTree.tsx

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,80 @@ import AccountTreeIcon from '@material-ui/icons/AccountTree';
55
import { makeStyles } from '@material-ui/core/styles';
66
import Typography from '@material-ui/core/Typography';
77
import Container from '@material-ui/core/Container';
8+
import tree1 from '../../../resources/tree_tutorial_images/tree1.png';
9+
import tree2 from '../../../resources/tree_tutorial_images/tree2.png';
10+
import tree3 from '../../../resources/tree_tutorial_images/tree3.png';
11+
import tree4 from '../../../resources/tree_tutorial_images/tree4.png';
12+
import tree5 from '../../../resources/tree_tutorial_images/tree5.png';
13+
import pages from '../../../resources/tree_tutorial_images/pages.png';
14+
import re_comps from '../../../resources/tree_tutorial_images/re_comps.png';
815
// import Grid from '@material-ui/core/Grid';
916

1017
// import ComponentPanel from '../components/left/ComponentPanel';
1118
// import HTMLPanel from '../components/left/HTMLPanel';
1219

1320
// Left-hand portion of the app, where component options are displayed
14-
const useStyles = makeStyles({});
21+
1522
const ComponentTree: React.FC<RouteComponentProps> = () => {
23+
const body = document.querySelector('body');
24+
body.style.overflowY = 'auto';
25+
const useStyles = makeStyles({
26+
title: {
27+
color: '#14151f',
28+
fontSize: 54
29+
},
30+
text: {
31+
color: '#2e2f3e',
32+
fontSize: 24
33+
},
34+
wrapper: {
35+
margin: '30px 30px 30px 30px',
36+
width: 'auto'
37+
},
38+
img: {
39+
borderRadius: '3px',
40+
// alignSelf: 'center'
41+
},
42+
imgWrapper: {
43+
display: 'flex',
44+
flexDirection: 'row',
45+
alignItems: 'center',
46+
// border: '1px solid black',
47+
width: 'auto'
48+
}
49+
});
50+
const classes = useStyles();
1651
return (
17-
<div>
18-
ComponentTree
52+
<div className={classes.wrapper}>
53+
<h1 className={classes.title}>React Component Tree</h1>
54+
<h2></h2>
55+
<p className={classes.text}>The tree provides the developer with a visual representation of the component hierarchy. The tree updates in real time as the developer adds or deletes components.</p>
56+
<div className={classes.imgWrapper}>
57+
<img className={classes.img} src={tree1}></img>
58+
</div>
59+
<p className={classes.text}>Each tree begins with a root node. The current page that is selected represents the root node.</p>
60+
<div className={classes.imgWrapper}>
61+
{/* <img className={classes.img} src={pages}></img> */}
62+
<img className={classes.img} src={tree2}></img>
63+
</div>
64+
<p className={classes.text}>Reusable components are shown attached to the current page along with their subtrees of components and HTML elements.</p>
65+
<div className={classes.imgWrapper}>
66+
{/* <img className={classes.img} src={re_comps}></img> */}
67+
<img className={classes.img} src={tree3}></img>
68+
</div>
69+
<p className={classes.text}>HTML elements are shown by their tag name.</p>
70+
<div className={classes.imgWrapper}>
71+
<img className={classes.img} src={tree4}></img>
72+
</div>
73+
<p className={classes.text}>You can also view the tree for each reusable component.</p>
74+
<div className={classes.imgWrapper}>
75+
<img className={classes.img} src={tree5}></img>
76+
</div>
1977
<Link to={`/tutorial`}>
2078
<button>Tutorial</button>
2179
</Link>
2280
</div>
2381
);
2482
};
2583

26-
export default withRouter(ComponentTree);
27-
84+
export default withRouter(ComponentTree);
1.32 KB
Loading
2.8 KB
Loading
27 KB
Loading
25.3 KB
Loading
28.8 KB
Loading
25.5 KB
Loading
13.4 KB
Loading

webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ module.exports = {
7979
// url loader converts file into base 64 encoded string that can be passed inline into the file rather than be imported from a seperate file
8080
// you can set limits for the file size at which this inline encoding happens, but there is no limit set currently
8181
{
82-
test: /\.(eot|woff|woff2|ttf|svg|png|jpg|gif)$/,
82+
test: /\.(eot|woff|woff2|ttf|svg|png|jpg|gif)$/i,
8383
use: 'url-loader'
8484
}
8585
]

0 commit comments

Comments
 (0)