Skip to content

Commit e13c20e

Browse files
committed
updated modal and table state props to use and display nested arrays and objects, stateKey was also updated to reflect the proper variable string to access state
Co-authored by Chris Tang [email protected]
1 parent 7e00a7c commit e13c20e

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

app/src/components/bottom/UseStateModal.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ function UseStateModal({ updateAttributeWithState, attributeToChange, childId })
4646
if (table.row.type === "object") {
4747
setStateKey(stateKey + table.row.key + '.');
4848
setDisplayObject(table.row.value);
49+
} else if (table.row.type === "array") {
50+
setStateKey(stateKey + table.row.key)
51+
setDisplayObject(table.row.value);
4952
} else {
5053
// if not object => actually update state
5154
setDisplayObject(null);

app/src/components/right/TableStateProps.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ const getColumns = (props) => {
5050
console.log('Line 50 id = ', params.id);
5151
// const fields = api.getAllColumns().map((c: any) => c.field).filter((c : any) => c !== '__check__' && !!c);
5252
return params.id;
53-
53+
5454
// return params.getValue(fields[0]);
5555
};
56-
return (
56+
return (
5757
<Button style={{width:`${3}px`}}
5858
onClick={() => {
5959
deleteHandler(getIdRow());
@@ -72,15 +72,15 @@ const TableStateProps = (props) => {
7272
const [state] = useContext(StateContext);
7373
const [editRowsModel] = useState <GridEditRowsModel> ({});
7474
const [gridColumns, setGridColumns] = useState([]);
75-
75+
7676

7777
useEffect(() => {
7878
setGridColumns(getColumns(props));
7979
}, [props.isThemeLight])
8080
// get currentComponent by using currently focused component's id
8181
const currentId = state.canvasFocus.componentId;
8282
const currentComponent = state.components[currentId - 1];
83-
83+
8484
// rows to show are either from current component or from a given provider
8585
let rows = [];
8686
if (!props.providerId) {
@@ -90,25 +90,25 @@ const TableStateProps = (props) => {
9090
// changed to get whole object
9191
if (props.displayObject){
9292
const displayObject = props.displayObject;
93-
// const displayObject = providerComponent.stateProps[props.displayObjectId - 1].value;
94-
// format the object to match the table data format {id:_, key:_, value:_, type:<might do typeof or leave blank>}
93+
// format for DataGrid
9594
let id=1;
9695
for (const key in displayObject) {
97-
rows.push({id: id++, key:key, value: displayObject[key], type: typeof(displayObject[key])});
98-
}
96+
// if key is a number make it a string with brackets aroung number
97+
rows.push({ id: id++, key: ( isNaN(key) ? key : '[' + key + ']' ), value: displayObject[key], type: typeof(displayObject[key])});
98+
}
9999
} else {
100100
rows = providerComponent.stateProps.slice();
101101
}
102102
}
103103
console.log(rows);
104104

105105
const { selectHandler } : StatePropsPanelProps = props;
106-
106+
107107
// when component gets mounted, sets the gridColumn
108108
useEffect(() => {
109109
setGridColumns(getColumns(props));
110110
}, []);
111-
111+
112112
return (
113113
<div className={'state-prop-grid'}>
114114
<DataGrid

0 commit comments

Comments
 (0)