Skip to content

Commit 9fc8c1d

Browse files
authored
Merge pull request #40 from ibeeliot/master
[FIXED: #38] REPUSH: Children added to parent components will have their children props destructured to parents automatically
2 parents 88bbbea + cd7da54 commit 9fc8c1d

File tree

5 files changed

+180
-80
lines changed

5 files changed

+180
-80
lines changed

src/actions/actionCreators.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ export const addComponent = ({ title }: { title: string }) => (
6161
dispatch({ type: ADD_COMPONENT, payload: { title } });
6262
};
6363

64-
export const addProp = (prop: PropInt) => ({
64+
export const addProp = ({ key, type }: { key: string; type: string }) => ({
6565
type: ADD_PROP,
66-
payload: { ...prop }
66+
payload: { key, type }
6767
});
6868

6969
export const changeTutorial = (tutorial: number) => ({

src/components/bottom/BottomTabs.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { ComponentsInt, PropInt, PropsInt } from '../../interfaces/Interfaces';
1111

1212
interface BottomTabsPropsInt extends PropsInt {
1313
deleteProp(id: number): void;
14-
addProp(prop: PropInt): void;
14+
addProp(arg: { key: string; type: string }): void;
1515
classes: any;
1616
changeFocusComponent(arg: { title: string }): void;
1717
updateCode(arg: { componentId: number; code: string }): void;
@@ -165,12 +165,12 @@ class BottomTabs extends Component<BottomTabsPropsInt, StateInt> {
165165
<Tab
166166
disableRipple
167167
classes={{ root: classes.tabRoot, selected: classes.tabSelected }}
168-
label="Application Tree"
168+
label='Application Tree'
169169
/>
170170
<Tab
171171
disableRipple
172172
classes={{ root: classes.tabRoot, selected: classes.tabSelected }}
173-
label="Code Preview"
173+
label='Code Preview'
174174
/>
175175
<Tab
176176
disableRipple
@@ -187,13 +187,13 @@ class BottomTabs extends Component<BottomTabsPropsInt, StateInt> {
187187
<Tab
188188
disableRipple
189189
classes={{ root: classes.tabRoot, selected: classes.tabSelected }}
190-
label="Add Child Props"
190+
label='Add Child Props'
191191
/>
192192
</Tabs>
193193

194194
{value === 0 && (
195195
<div
196-
id="treeWrapper"
196+
id='treeWrapper'
197197
style={{
198198
width: '100%',
199199
height: '100%'

src/components/bottom/DataTable.tsx

Lines changed: 66 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,57 @@ import { IconButton } from '@material-ui/core';
1111

1212
const styles = (theme: Theme) => ({
1313
root: {
14-
width: '80%',
14+
width: '650px',
1515
marginTop: theme.spacing.unit * 3,
16-
marginRight: '100px'
17-
// overflowX: "auto"
16+
borderRadius: '8px',
17+
// boxShadow: '0px 0px 5px 2px #97ffb6'
18+
boxShadow: '0px 0px 5px 2px lightgray'
19+
},
20+
tableContainer: {
21+
borderRadius: '7px',
22+
border: 'none',
23+
backgroundColor: '#55585b'
1824
},
1925
table: {
20-
minWidth: 500,
21-
marginRight: '100px'
26+
minWidth: 300,
27+
borderRadius: '7px',
28+
backgroundColor: '#55585b'
29+
},
30+
tableHeader: {
31+
fontWeight: '900',
32+
fontSize: '25px',
33+
color: '#01d46d',
34+
border: 'none',
35+
textShadow: '2px 2px 5px 5px #8dffce'
2236
},
2337
tableCell: {
38+
fontWeight: '500',
39+
fontSize: '17px',
40+
letterSpacing: '2px',
41+
color: 'lightgray',
42+
padding: '3px',
43+
borderRadius: '7px',
44+
border: 'none',
45+
'&:hover': {
46+
transform: 'scale(1.1)',
47+
color: '#fff'
48+
}
49+
},
50+
tableCellShaded: {
2451
fontWeight: '900',
25-
fontSize: '1.2rem',
52+
fontSize: '15px',
2653
color: '#91D1F9',
27-
border: '1px solid red'
54+
borderRadius: '7px'
55+
},
56+
trashIcon: {
57+
backgroundColor: 'none',
58+
color: 'gray',
59+
'&:hover': {
60+
transform: 'scale(1.08)',
61+
backgroundColor: 'gray',
62+
color: '#b30000',
63+
border: 'none'
64+
}
2865
}
2966
});
3067

@@ -54,7 +91,11 @@ function dataTable(props: dataTableProps) {
5491
const { classes, rowData, rowHeader, deletePropHandler } = props;
5592

5693
const renderHeader = rowHeader.map((col: any, idx: number) => (
57-
<TableCell align={'center'} key={`head_+${idx}`}>
94+
<TableCell
95+
className={classes.tableHeader}
96+
align={'center'}
97+
key={`head_+${idx}`}
98+
>
5899
{col}
59100
</TableCell>
60101
));
@@ -64,18 +105,23 @@ function dataTable(props: dataTableProps) {
64105
// for some reason we must put each value in a div.
65106
return rowHeader.map((header: string, idx: number) => (
66107
<TableCell align={'center'} key={`td_${idx}`}>
67-
{/* <div align={'center'} padding = {'none'} >{typeof row[header] === 'string' ? row[header] : row[header].toString()}</div> */}
68-
{/* {row[header]} */}
69-
{typeof row[header] === 'string' ? row[header] : row[header].toString()}
108+
<div className={classes.tableCell} align={'center'} padding={'none'}>
109+
{row[header]}
110+
</div>
70111
</TableCell>
71112
));
72113
}
73114
// style={{height: 30}}
74115
const renderRows = rowData.map((row: any) => (
75116
<TableRow key={`row-${row.id}`}>
76117
{renderRowCells(row)}
77-
<TableCell align={'center'} padding={'none'}>
118+
<TableCell
119+
style={{ height: '15px', width: '15px' }}
120+
align={'center'}
121+
padding={'none'}
122+
>
78123
<IconButton
124+
className={classes.trashIcon}
79125
color='default'
80126
// fontSize='small' - commented/removed b/c not a valid attribute for IconButton component
81127
onClick={() => deletePropHandler(row.id)}
@@ -89,15 +135,14 @@ function dataTable(props: dataTableProps) {
89135

90136
return (
91137
<Paper className={classes.root}>
92-
<Table
93-
className={classes.table}
94-
// selectable={'true'} - commented/removed b/c not a valid attr for Table (no adverse effects noted)
95-
>
96-
<TableHead>
97-
<TableRow>{renderHeader}</TableRow>
98-
</TableHead>
99-
<TableBody>{renderRows}</TableBody>
100-
</Table>
138+
<div className={classes.tableContainer}>
139+
<Table className={classes.table} selectable={'true'}>
140+
<TableHead>
141+
<TableRow>{renderHeader}</TableRow>
142+
</TableHead>
143+
<TableBody>{renderRows}</TableBody>
144+
</Table>
145+
</div>
101146
</Paper>
102147
);
103148
}

src/components/left/LeftColExpansionPanel.tsx

Lines changed: 71 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,16 @@ import Tooltip from '@material-ui/core/Tooltip';
1414
import Collapse from '@material-ui/core/Collapse';
1515
import Switch from '@material-ui/core/Switch'; // for state/class toggling
1616
import InputLabel from '@material-ui/core/InputLabel'; // labeling of state/class toggles
17-
import { ComponentInt, ComponentsInt, PropsInt } from '../../interfaces/Interfaces'; // unused
17+
import {
18+
ComponentInt,
19+
ComponentsInt,
20+
PropsInt
21+
} from '../../interfaces/Interfaces'; // unused
1822
interface LeftColExpPanPropsInt extends PropsInt {
1923
classes: any;
2024
id?: number;
2125
component: ComponentInt;
26+
addProp(arg: { title: string; type: string }): void;
2227
addChild(arg: { title: string; childType: string; HTMLInfo?: object }): void;
2328
changeFocusComponent(arg: { title: string }): void;
2429
selectableChildren: number[];
@@ -45,6 +50,7 @@ const LeftColExpansionPanel = (props: LeftColExpPanPropsInt) => {
4550
focusComponent,
4651
components,
4752
component,
53+
addProp,
4854
addChild,
4955
changeFocusComponent,
5056
selectableChildren,
@@ -65,8 +71,6 @@ const LeftColExpansionPanel = (props: LeftColExpPanPropsInt) => {
6571
// state/class toggles will be displayed when a component is focused
6672
const focusedToggle = isFocused() === 'focused' ? true : false;
6773

68-
69-
7074
//this function determines whether edit mode for component name should be entered or not
7175
//resets the title if 'escape' key is hit
7276
const handleEdit = () => {
@@ -78,12 +82,54 @@ const LeftColExpansionPanel = (props: LeftColExpPanPropsInt) => {
7882
}
7983
};
8084

85+
// function adds childProps & also addsChild at the same time to the parents and updates state
86+
// to reflect the childrenArray to be update inside the parent as well as the props from the child
87+
// automatically destructured in the parents
88+
const addChildProps = () => {
89+
const addedChildProps = components.find(
90+
(component: ComponentInt) => component.title === title
91+
);
92+
93+
const parentKeys: any[] = [];
94+
if (focusComponent.props.length > 0) {
95+
focusComponent.props.forEach(key => parentKeys.push(key.key));
96+
}
97+
console.log('this is parentKeys', parentKeys);
98+
// sorting through object keys of the focusComponent
99+
100+
let i = 0;
101+
while (i <= addedChildProps.props.length) {
102+
if (addedChildProps.props.length) {
103+
if (i === 0) {
104+
addChild({ title, childType: 'COMP' });
105+
changeFocusComponent({ title: focusComponent.title });
106+
}
107+
if (addedChildProps.props[i]) {
108+
const newKey = addedChildProps.props[i]['key'],
109+
newType = addedChildProps.props[i]['type'];
110+
if (!parentKeys.includes(newKey))
111+
addProp({
112+
key: newKey,
113+
type: newType
114+
});
115+
else console.log('child prop already exists in parent!');
116+
}
117+
} else {
118+
if (i === 0) {
119+
addChild({ title, childType: 'COMP' });
120+
changeFocusComponent({ title: focusComponent.title });
121+
}
122+
}
123+
i++;
124+
}
125+
};
126+
81127
return (
82128
<Grid
83129
container
84-
direction="row"
85-
justify="center"
86-
alignItems="center"
130+
direction='row'
131+
justify='center'
132+
alignItems='center'
87133
style={{
88134
minWidth: '470px'
89135
}}
@@ -106,7 +152,7 @@ const LeftColExpansionPanel = (props: LeftColExpPanPropsInt) => {
106152
in={focusedToggle}
107153
collapsedHeight={'80px'} //The type for the Collapse component is asking for a string, but if you put in a string and not a number, the component itself breaks.
108154
style={{ borderRadius: '5px' }}
109-
timeout="auto"
155+
timeout='auto'
110156
>
111157
{/* NOT SURE WHY COLOR: RED IS USED, TRIED REMOVING IT AND NO VISIBLE CHANGE OCCURED. */}
112158
<Grid
@@ -156,10 +202,10 @@ const LeftColExpansionPanel = (props: LeftColExpPanPropsInt) => {
156202
</Typography>
157203
) : (
158204
<TextField //show a text field for editing instead if edit mode entered
159-
id="filled"
160-
label="Change Component Name"
205+
id='filled'
206+
label='Change Component Name'
161207
defaultValue={title}
162-
variant="outlined"
208+
variant='outlined'
163209
className={classes.text}
164210
InputProps={{
165211
className: classes.light //all of these styling makes the input box border, label, and text default to white.
@@ -191,7 +237,7 @@ const LeftColExpansionPanel = (props: LeftColExpPanPropsInt) => {
191237
{focusedToggle ? (
192238
<span style={{ display: 'inline-flex' }}>
193239
<InputLabel
194-
htmlFor="stateful"
240+
htmlFor='stateful'
195241
style={{
196242
color: '#fff',
197243
marginBottom: '0px',
@@ -210,12 +256,12 @@ const LeftColExpansionPanel = (props: LeftColExpPanPropsInt) => {
210256
toggleComponentState({ id });
211257
changeFocusComponent({ title });
212258
}}
213-
value="stateful"
214-
color="primary"
259+
value='stateful'
260+
color='primary'
215261
// id={props.id.toString()}
216262
/>
217263
<InputLabel
218-
htmlFor="classBased"
264+
htmlFor='classBased'
219265
style={{
220266
color: '#fff',
221267
marginBottom: '0px',
@@ -234,19 +280,19 @@ const LeftColExpansionPanel = (props: LeftColExpPanPropsInt) => {
234280
toggleComponentClass({ id });
235281
changeFocusComponent({ title });
236282
}}
237-
value="classBased"
238-
color="primary"
283+
value='classBased'
284+
color='primary'
239285
/>
240286
</span>
241287
) : (
242288
''
243289
)}
244290
{focusedToggle && component.id !== 1 ? (
245291
<Button
246-
variant="text"
247-
size="small"
248-
color="default"
249-
aria-label="Delete"
292+
variant='text'
293+
size='small'
294+
color='default'
295+
aria-label='Delete'
250296
className={classes.margin}
251297
onClick={() =>
252298
deleteComponent({
@@ -295,15 +341,14 @@ const LeftColExpansionPanel = (props: LeftColExpPanPropsInt) => {
295341
<div />
296342
) : (
297343
<Tooltip
298-
title="add as child"
299-
aria-label="add as child"
300-
placement="left"
344+
title='add as child'
345+
aria-label='add as child'
346+
placement='left'
301347
>
302348
<IconButton
303-
aria-label="Add"
349+
aria-label='Add'
304350
onClick={() => {
305-
addChild({ title, childType: 'COMP' });
306-
changeFocusComponent({ title: focusComponent.title });
351+
addChildProps();
307352
}}
308353
>
309354
<AddIcon style={{ color, float: 'right', marginTop: '10px' }} />

0 commit comments

Comments
 (0)