Skip to content

Commit aff1979

Browse files
committed
cleaned up code for use state button in custom tab
1 parent cca307b commit aff1979

File tree

2 files changed

+10
-71
lines changed

2 files changed

+10
-71
lines changed

app/src/components/bottom/TableStateProps.tsx

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ const TableStateProps = props => {
3030
},
3131
{
3232
field: 'value',
33-
headerName: 'Value',
34-
width: 90,
33+
headerName: 'Initial Value',
34+
width: 100,
3535
editable: true
3636
},
3737
{
@@ -88,24 +88,20 @@ const TableStateProps = props => {
8888
setGridColumns(columnTabs.slice(0, gridColumns.length - 1));
8989
}
9090
}, [state.canvasFocus.componentId]);
91-
// rows to show are either from current component or from a given provider
92-
let rows = [];
91+
92+
// create rows to show the current component's state props
93+
let rows = [];
9394
const currentId = state.canvasFocus.componentId;
9495
const currentComponent = state.components[currentId - 1];
9596
let currentProps = currentComponent.stateProps.slice();
96-
97-
9897

99-
//add in passed in props
100-
98+
//add in passed in props for the current component (if it is not a root component)
10199
if (currentComponent.name !== 'App' && currentComponent.name !== 'index') {
102100
let propsPassed = currentComponent.passedInProps?.slice();
103-
104101
for (let i = 0; i < propsPassed.length; i++) {
105102
currentProps.push(propsPassed[i]);
106103
}
107104
}
108-
109105
rows = currentProps;
110106

111107
return (

app/src/components/bottom/UseStateModal.tsx

Lines changed: 4 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,41 @@
1-
import React, {useRef, useState, useContext, useEffect } from 'react';
1+
import React, {useState, useContext} from 'react';
22
import Modal from '@material-ui/core/Modal';
33
import StateContext from '../../context/context';
44
import TableStateProps from './TableStateProps';
5-
import { off } from 'process';
5+
66

77
function UseStateModal({ updateAttributeWithState, attributeToChange, childId }) {
88
const [state, dispatch] = useContext(StateContext);
99
const [open, setOpen] = useState(false);
10-
const [displayObject, setDisplayObject] = useState(null)
1110
const [stateKey, setStateKey] = useState('');
1211
const [statePropsId, setStatePropsId] = useState(-1);
1312
const [componentProviderId, setComponentProviderId] = useState(1);
1413

15-
const currentId = state.canvasFocus.componentId;
16-
const currentComponent = state.components[currentId - 1];
17-
const passedInProps = (currentComponent.name !== 'App' && currentComponent.name !== 'index')? currentComponent.passedInProps : '';
18-
const currentProps = currentComponent.stateProps;
19-
20-
const allStateToDisplay = {
21-
...currentProps,
22-
...passedInProps
23-
};
24-
25-
console.log({allStateToDisplay});
26-
27-
// make tabs to choose which component to get state from
28-
// const componentTabs = [];
29-
// for (let i = 0; i < state.components.length; i ++) {
30-
// componentTabs.push(<button
31-
// onClick={() => {
32-
// setComponentProviderId(i+1);
33-
// setDisplayObject(null);
34-
// setStateKey('');
35-
// }}>
36-
// {state.components[i].name}
37-
// </button>)
38-
// }
39-
40-
// const componentTabs = [];
41-
// componentTabs.push(<button
42-
// onClick={() => {
43-
// setComponentProviderId(i+1);
44-
// setDisplayObject(null);
45-
// setStateKey('');
46-
// }}>
47-
// {state.components[i].name}
48-
// </button>)
49-
// }
50-
51-
//carly: add a button to exit out of the window?
52-
5314
// table to choose state from
5415
const body = (
5516
<div className="useState-position">
5617
<div className="useState-header">
5718
<span>Choose State</span>
58-
{/* <button
19+
<button
5920
style={{ margin: '5px 5px' ,padding: '1px', float: 'right' }}
6021
onClick={() => {
6122
setStateKey('');
6223
setStatePropsId(-1);
63-
setDisplayObject(null)
6424
setOpen(false)}}
6525
>
6626
X
67-
</button> */}
27+
</button>
6828
</div>
6929
<div className="useState-window">
70-
{/* <div className="useState-dropdown">
71-
{componentTabs}
72-
</div> */}
7330
<div className="useState-stateDisplay">
7431
<TableStateProps
7532
providerId = {componentProviderId}
7633
canDeleteState = {false}
77-
//displayObject = {allStateToDisplay["0"]}
7834
selectHandler={(table) => {
79-
// if object or array => show sub table
80-
// if (table.row.type === "object") {
81-
// if (statePropsId < 0) setStatePropsId(table.row.id);
82-
// setStateKey(stateKey + table.row.key + '.');
83-
// setDisplayObject(table.row.value);
84-
// } else if (table.row.type === "array") {
85-
// if (statePropsId < 0) setStatePropsId(table.row.id);
86-
// setStateKey(stateKey + table.row.key)
87-
// setDisplayObject(table.row.value);
88-
// } else {
89-
// if not object or array => update state
90-
setDisplayObject(null);
9135
updateAttributeWithState(attributeToChange, componentProviderId, statePropsId > 0 ? statePropsId : table.row.id, table.row, stateKey + table.row.key);
9236
setStateKey('')
9337
setStatePropsId(-1);
9438
setOpen(false);
95-
// }
9639
}}
9740
deleteHandler={() => func()}
9841
isThemeLight={true}

0 commit comments

Comments
 (0)