Skip to content

Commit f04de67

Browse files
Merge pull request #8 from oslabs-beta/c2
C2 merge to dev-46 branch
2 parents ac24d84 + a6e835f commit f04de67

File tree

12 files changed

+191
-106
lines changed

12 files changed

+191
-106
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Download for [MacOS](https://github.com/team-reactype/ReacType/releases), [Windo
8181
- Delete Project: Command + Backspace
8282
- Open Project: Command + o
8383

84-
**Windows**:
84+
**Windows**:
8585
- Export Project: Control + e
8686
- Undo: Control + z
8787
- Redo: Control + Shift + z
@@ -90,7 +90,7 @@ Download for [MacOS](https://github.com/team-reactype/ReacType/releases), [Windo
9090
- Delete HTML Tag on Canvas: Backspace
9191
- Delete Project: Control + Backspace
9292
- Open Project: Control + o
93-
93+
9494
#### Contributors
9595

9696
[Alex Yu](https://www.linkedin.com/in/alexjihunyu/) [@buddhajjigae](https://github.com/buddhajjigae)
@@ -111,8 +111,12 @@ Download for [MacOS](https://github.com/team-reactype/ReacType/releases), [Windo
111111

112112
[Chelsey Fewer](https://www.linkedin.com/in/chelsey-fewer/) [@chelseyeslehc](https://github.com/chelseyeslehc)
113113

114+
[Chris Tang] (https://www.linkedin.com/in/chrisjtang/) [@chrisjtang](https://github.com/chrisjtang)
115+
114116
[Christian Padilla](https://linkedin.com/in/ChristianEdwardPadilla) [@ChristianEdwardPadilla](https://github.com/ChristianEdwardPadilla)
115117

118+
[Crys Lim] (https://linkedin.com/in/crystallim) [@crlim](https://github.com/crlim)
119+
116120
[Danial Reilley](https://linkedin.com/in/daniel-reilley)
117121
[@dreille](https://github.com/dreille)
118122

@@ -156,6 +160,8 @@ Download for [MacOS](https://github.com/team-reactype/ReacType/releases), [Windo
156160
[Philip Hua](https://www.linkedin.com/in/philip-minh-hua)
157161
[@pmhua](https://github.com/pmhua)
158162

163+
[Ron Fu] (https://www.linkedin.com/in/ronfu)[@rfvisuals] (https://github.com/rfvisuals)
164+
159165
[Sean Sadykoff](https://www.linkedin.com/in/sean-sadykoff/) [@sean1292](https://github.com/sean1292)
160166

161167
[Shana Hoehn](https://www.linkedin.com/in/shana-hoehn-70297b169/) [@slhoehn](https://github.com/slhoehn)
@@ -172,6 +178,8 @@ Download for [MacOS](https://github.com/team-reactype/ReacType/releases), [Windo
172178

173179
[Tyler Sullberg](https://www.linkedin.com/in/tyler-sullberg) [@tsully](https://github.com/tsully)
174180

181+
[William Cheng] (https://www.linkedin.com/in/william-cheng-0723/) [@williamcheng12345](https://github.com/WilliamCheng12345)
182+
175183
[William Rittwage](https://www.linkedin.com/in/william-rittwage)
176184
[@wbrittwage](https://github.com/wbrittwage)
177185

app/src/components/bottom/UseStateModal.tsx

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,40 @@ import Modal from '@material-ui/core/Modal';
33
import StateContext from '../../context/context';
44
import TableStateProps from '../right/TableStateProps';
55

6-
// TODO: typescript interface or type check
6+
77
function UseStateModal({ updateAttributeWithState, attributeToChange, childId }) {
88
const [state, dispatch] = useContext(StateContext);
99
const [open, setOpen] = useState(false);
10+
const [displayObject, setDisplayObject] = useState(null)
11+
const [stateKey, setStateKey] = useState('');
12+
const [statePropsId, setStatePropsId] = useState(-1);
1013

1114
// make buttons to choose which component to get state from
1215
const [componentProviderId, setComponentProviderId] = useState(1) // for now set to App
1316
const components = [];
1417
for (let i = 0; i < state.components.length; i ++) {
15-
components.push(<button onClick={() => setComponentProviderId(i+1)}>{state.components[i].name}</button>)
18+
components.push(<button
19+
onClick={() => {
20+
setComponentProviderId(i+1);
21+
setDisplayObject(null);
22+
setStateKey('');
23+
}}>
24+
{state.components[i].name}
25+
</button>)
1626
}
1727

18-
// return the selected state's ID back so the value of it can be updated in the customizationpanel. to the assign the value of selected state to attribute tied to useState button (currently just text)
19-
// attribute to change as parameter for
28+
// table to choose state from
2029
const body = (
2130
<div className="useState-position">
2231
<div className="useState-header">
2332
<span>Choose State Source</span>
2433
<button
2534
style={{ margin: '5px 5px' ,padding: '1px', float: 'right' }}
26-
onClick={() => setOpen(false)}
35+
onClick={() => {
36+
setStateKey('');
37+
setStatePropsId(-1);
38+
setDisplayObject(null)
39+
setOpen(false)}}
2740
>
2841
X
2942
</button>
@@ -35,9 +48,24 @@ function UseStateModal({ updateAttributeWithState, attributeToChange, childId })
3548
<div className="useState-stateDisplay">
3649
<TableStateProps
3750
providerId = {componentProviderId}
51+
displayObject = {displayObject}
3852
selectHandler={(table) => {
39-
updateAttributeWithState(attributeToChange, componentProviderId, table.row.id);
40-
setOpen(false);
53+
if (statePropsId < 0) setStatePropsId(table.row.id);
54+
// if object or array => show sub table
55+
if (table.row.type === "object") {
56+
setStateKey(stateKey + table.row.key + '.');
57+
setDisplayObject(table.row.value);
58+
} else if (table.row.type === "array") {
59+
setStateKey(stateKey + table.row.key)
60+
setDisplayObject(table.row.value);
61+
} else {
62+
// if not object or array => update state
63+
setDisplayObject(null);
64+
updateAttributeWithState(attributeToChange, componentProviderId, statePropsId, table.row, stateKey + table.row.key);
65+
setStateKey('')
66+
setStatePropsId(-1);
67+
setOpen(false);
68+
}
4169
}}
4270
deleteHandler={() => func()}
4371
isThemeLight={true}
@@ -55,4 +83,4 @@ function UseStateModal({ updateAttributeWithState, attributeToChange, childId })
5583
);
5684
}
5785

58-
export default UseStateModal;
86+
export default UseStateModal;

app/src/components/left/DragDropPanel.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const DragDropPanel = (props): JSX.Element => {
5858
handleDelete={handleDelete}
5959
isThemeLight={isThemeLight}
6060
/>
61-
);
61+
);
6262
}
6363

6464
})}
@@ -74,10 +74,9 @@ const DragDropPanel = (props): JSX.Element => {
7474
handleDelete={handleDelete}
7575
isThemeLight={isThemeLight}
7676
/>
77-
);
77+
);
7878
}
7979
})}
80-
8180
</Grid>
8281
</div>
8382
</div>

app/src/components/left/HTMLItem.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const useStyles = makeStyles({
3535
darkThemeFontColor: {
3636
color: '#fff'
3737
}
38-
38+
3939
});
4040

4141
const HTMLItem : React.FC<{
@@ -45,9 +45,9 @@ const HTMLItem : React.FC<{
4545
handleDelete: (id: number) => void;
4646
isThemeLight: boolean;
4747
}> = ({ name, id, Icon, handleDelete, isThemeLight }) => {
48-
48+
4949
const classes = useStyles();
50-
50+
5151
const [modal, setModal] = useState(null);
5252
const [{ isDragging }, drag] = useDrag({
5353
item: {

app/src/components/main/DemoRender.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const DemoRender = (props): JSX.Element => {
3535
if (elementType !== 'input' && elementType !== 'img' && element.children.length > 0) {
3636
renderedChildren = componentBuilder(element.children);
3737
}
38+
3839
if (elementType === 'input') componentsToRender.push(<Box component={elementType} className={classRender} style={elementStyle} key={key} id={`rend${childId}`}></Box>);
3940
else if (elementType === 'img') componentsToRender.push(<Box component={elementType} src={activeLink} className={classRender} style={elementStyle} key={key} id={`rend${childId}`}></Box>);
4041
else if (elementType === 'a') componentsToRender.push(<Box component={elementType} href={activeLink} className={classRender} style={elementStyle} key={key} id={`rend${childId}`}>{innerText}</Box>);

app/src/components/right/StatePropsPanel.tsx

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import TableStateProps from "./TableStateProps";
3131
const StatePropsPanel = ({ isThemeLight }): JSX.Element => {
3232
const [state, dispatch] = useContext(StateContext);
3333
const classes = useStyles();
34-
34+
3535

3636
const [inputKey, setInputKey] = useState("");
3737
const [inputValue, setInputValue] = useState("");
@@ -46,12 +46,16 @@ const StatePropsPanel = ({ isThemeLight }): JSX.Element => {
4646
// convert value to correct type based on user input
4747
const typeConversion = (value, type) => {
4848
switch (type) {
49-
case "String":
49+
case "string":
5050
return String(value);
51-
case "Number":
51+
case "number":
5252
return Number(value);
53-
case "Boolean":
53+
case "boolean":
5454
return Boolean(value);
55+
case "array":
56+
return JSON.parse(value);
57+
case "object":
58+
return JSON.parse(value);
5559
default:
5660
return value;
5761
}
@@ -74,44 +78,44 @@ const StatePropsPanel = ({ isThemeLight }): JSX.Element => {
7478
key: inputKey,
7579
value: typeConversion(inputValue, inputType),
7680
type: inputType,
77-
};
78-
81+
};
82+
7983
dispatch({
80-
type: 'ADD STATE',
84+
type: 'ADD STATE',
8185
payload: {newState: newState}
82-
});
86+
});
8387
clearForm();
8488
};
85-
86-
87-
// find table row using its id and if it exists, populate form with its details
89+
90+
91+
// find table row using its id and if it exists, populate form with its details
8892
const handlerRowSelect = (table) => {
8993
let exists = false;
9094
currentComponent.stateProps.forEach((stateProp) => {
9195
// if stateProp id matches current row's id (table.row.id), flip exists to true
9296
if (stateProp.id === table.row.id) exists = true;
93-
});
97+
});
9498
// if row id exists, populate form with corresponding inputs (key, value, type) from table row
9599
if (exists) {
96100
setInputKey(table.row.key);
97101
setInputType(table.row.type);
98102
setInputValue(table.row.value);
99103
} else clearForm();
100104
};
101-
105+
102106
// find & delete table row using its id
103107
const handlerRowDelete = (id:any) => {
104-
// iterate and filter out stateProps with matching row id
105-
const filtered = currentComponent.stateProps.filter(element => element.id !== id);
106-
108+
// iterate and filter out stateProps with matching row id
109+
const filtered = currentComponent.stateProps.filter(element => element.id !== id);
110+
107111
dispatch({
108-
type: 'DELETE STATE',
112+
type: 'DELETE STATE',
109113
payload: {stateProps: filtered}
110114
});
111-
115+
112116
setStateProps(filtered);
113117
};
114-
118+
115119
return (
116120
<div className={'state-panel'}>
117121
<div>
@@ -123,18 +127,18 @@ const StatePropsPanel = ({ isThemeLight }): JSX.Element => {
123127
variant="outlined"
124128
value={inputKey}
125129
onChange={(e) => setInputKey(e.target.value)}
126-
className={isThemeLight ? `${classes.rootLight} ${classes.inputTextLight}` : `${classes.rootDark} ${classes.inputTextDark}`}
130+
className={isThemeLight ? `${classes.rootLight} ${classes.inputTextLight}` : `${classes.rootDark} ${classes.inputTextDark}`}
127131
/>
128132
<TextField
129133
id="textfield-value"
130134
label="value:"
131135
variant="outlined"
132136
value={inputValue}
133137
onChange={(e) => setInputValue(e.target.value)}
134-
className={isThemeLight ? `${classes.rootLight} ${classes.inputTextLight}` : `${classes.rootDark} ${classes.inputTextDark}`}
138+
className={isThemeLight ? `${classes.rootLight} ${classes.inputTextLight}` : `${classes.rootDark} ${classes.inputTextDark}`}
135139
/>
136140
<FormControl required className={isThemeLight ? `${classes.formControl} ${classes.lightThemeFontColor}` : `${classes.formControl} ${classes.darkThemeFontColor}`}>
137-
<InputLabel
141+
<InputLabel
138142
id="select-required-label"
139143
className={isThemeLight ? classes.greyThemeFontColor : classes.darkThemeFontColor}>
140144
Type
@@ -161,6 +165,9 @@ const StatePropsPanel = ({ isThemeLight }): JSX.Element => {
161165
<MenuItem id="type-selector" value={"array"}>
162166
Array
163167
</MenuItem>
168+
<MenuItem id="type-selector" value={"object"}>
169+
Object
170+
</MenuItem>
164171
<MenuItem id="type-selector" value={"undefined"}>
165172
Undefined
166173
</MenuItem>
@@ -174,8 +181,8 @@ const StatePropsPanel = ({ isThemeLight }): JSX.Element => {
174181
</FormHelperText>
175182
</FormControl>
176183
<br></br>
177-
<MyButton
178-
type="submit"
184+
<MyButton
185+
type="submit"
179186
onClick={submitNewState}
180187
className={isThemeLight ? `${classes.addComponentButton} ${classes.lightThemeFontColor}` : `${classes.addComponentButton} ${classes.darkThemeFontColor}`}
181188
>

app/src/components/right/TableStateProps.tsx

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,11 @@ const getColumns = (props) => {
4646
renderCell: function renderCell(params:any) {
4747
const getIdRow = () => {
4848
const { api } = params;
49-
console.log('Line 49 params =', params);
50-
console.log('Line 50 id = ', params.id);
51-
// const fields = api.getAllColumns().map((c: any) => c.field).filter((c : any) => c !== '__check__' && !!c);
5249
return params.id;
53-
50+
5451
// return params.getValue(fields[0]);
5552
};
56-
return (
53+
return (
5754
<Button style={{width:`${3}px`}}
5855
onClick={() => {
5956
deleteHandler(getIdRow());
@@ -66,37 +63,47 @@ const getColumns = (props) => {
6663
];
6764
};
6865

69-
//, providerId=1
7066
const TableStateProps = (props) => {
7167
const classes = useStyles();
7268
const [state] = useContext(StateContext);
7369
const [editRowsModel] = useState <GridEditRowsModel> ({});
7470
const [gridColumns, setGridColumns] = useState([]);
75-
71+
7672

7773
useEffect(() => {
7874
setGridColumns(getColumns(props));
7975
}, [props.isThemeLight])
8076
// get currentComponent by using currently focused component's id
8177
const currentId = state.canvasFocus.componentId;
8278
const currentComponent = state.components[currentId - 1];
83-
79+
8480
// rows to show are either from current component or from a given provider
8581
let rows = [];
8682
if (!props.providerId) {
8783
rows = currentComponent.stateProps.slice();
8884
} else {
8985
const providerComponent = state.components[props.providerId - 1];
90-
rows = providerComponent.stateProps.slice();
86+
// changed to get whole object
87+
if (props.displayObject){
88+
const displayObject = props.displayObject;
89+
// format for DataGrid
90+
let id=1;
91+
for (const key in displayObject) {
92+
// if key is a number make it a string with brackets aroung number
93+
rows.push({ id: id++, key: ( isNaN(key) ? key : '[' + key + ']' ), value: displayObject[key], type: typeof(displayObject[key])});
94+
}
95+
} else {
96+
rows = providerComponent.stateProps.slice();
97+
}
9198
}
9299

93100
const { selectHandler } : StatePropsPanelProps = props;
94-
101+
95102
// when component gets mounted, sets the gridColumn
96103
useEffect(() => {
97104
setGridColumns(getColumns(props));
98105
}, []);
99-
106+
100107
return (
101108
<div className={'state-prop-grid'}>
102109
<DataGrid

0 commit comments

Comments
 (0)