Skip to content

Commit 02bd382

Browse files
committed
pre-lunch work
1 parent e534402 commit 02bd382

File tree

4 files changed

+51
-28
lines changed

4 files changed

+51
-28
lines changed

app/src/components/StateManagement/CreateTab/components/StatePropsPanel.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const StatePropsPanel = ({ isThemeLight, data}): JSX.Element => {
4040
const currentId = state.canvasFocus.componentId;
4141
const currentComponent = state.components[currentId - 1];
4242
const [parentProps, setParentProps] = useState([]);
43+
const [parentPassedInProps, setParentPassedInProps] = useState([]);
4344
const [parentName, setParentName] = useState('No Parents');
4445
const [parentComponent, setParentComponent] = useState({});
4546
const [rows1, setRows1] = useState(currentComponent.stateProps);
@@ -85,7 +86,8 @@ const StatePropsPanel = ({ isThemeLight, data}): JSX.Element => {
8586
}
8687
const newState = {
8788
// check if array is not empty => true find last elem in array. get id and increment by 1 || else 1
88-
id: statesArray.length > 0 ? statesArray[statesArray.length-1].id + 1 : 1,
89+
// id: statesArray.length > 0 ? statesArray[statesArray.length-1].id + 1 : 1,
90+
id: inputKey,
8991
key: inputKey,
9092
value: typeConversion(inputValue, inputType),
9193
type: inputType,
@@ -120,6 +122,7 @@ const StatePropsPanel = ({ isThemeLight, data}): JSX.Element => {
120122
setParentProps(parentInfo.parentProps);
121123
setParentName(parentInfo.parentName);
122124
setParentComponent(parentInfo.parentComponent);
125+
setParentPassedInProps(parentInfo.parentPassedInProps)
123126
}, [currentId]);
124127

125128
const findParent = (childId) => {
@@ -139,7 +142,8 @@ const StatePropsPanel = ({ isThemeLight, data}): JSX.Element => {
139142
// })
140143
return {parentProps: currComponentCopy.stateProps,
141144
parentName: currComponentCopy.name,
142-
parentComponent: currComponentCopy
145+
parentComponent: currComponentCopy,
146+
parentPassedInProps: currComponentCopy.passedInProps
143147
}
144148
}
145149
}
@@ -241,7 +245,7 @@ const StatePropsPanel = ({ isThemeLight, data}): JSX.Element => {
241245
<h4 className={isThemeLight ? classes.lightThemeFontColor : classes.darkThemeFontColor}>
242246
Available Props from Parent: {parentName ? parentName : 'No Parents'}
243247
</h4>
244-
<TableParentProps parentComponent ={parentComponent} parentProps={parentProps} canDeleteState = {true} selectHandler={handlerRowSelect} isThemeLight={isThemeLight} data={data}/>
248+
<TableParentProps parentPassedInProps = {parentPassedInProps} parentComponent ={parentComponent} parentProps={parentProps} canDeleteState = {true} selectHandler={handlerRowSelect} isThemeLight={isThemeLight} data={data}/>
245249
</div>
246250
<div style={{display: 'flex', flexDirection: 'column', width: `${40}px`, color: 'black', justifyContent: 'center'}}>
247251
<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" fill="currentColor" class="bi bi-arrow-right-circle-fill" viewBox="0 0 16 16">

app/src/components/StateManagement/CreateTab/components/Table3.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ const Table3 = props => {
2323
const passedInProps = currentComponent.name !== 'App' ? currentComponent.passedInProps : '';
2424

2525
const columnTabs = [
26-
{
27-
field: 'id',
28-
headerName: 'ID',
29-
width: 30,
30-
editable: false
31-
},
26+
// {
27+
// field: 'id',
28+
// headerName: 'ID',
29+
// width: 30,
30+
// editable: false
31+
// },
3232
{
3333
field: 'key',
3434
headerName: 'Key',

app/src/components/StateManagement/CreateTab/components/TableParentProps.tsx

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,21 @@ const TableParentProps = props => {
1414
// console.log('props from table state props', props)
1515
const [state, dispatch] = useContext(StateContext);
1616
const classes = useStyles();
17+
const currentId = state.canvasFocus.componentId;
18+
const currentComponent = state.components[currentId - 1];
1719
const [editRowsModel] = useState<GridEditRowsModel>({});
1820
const [gridColumns, setGridColumns] = useState([]);
1921
const [checked, setChecked] = useState(false);
2022
const parentProps = props.parentProps;
23+
const parentPassedInProps = props.parentPassedInProps;
2124
const parentComponent = props.parentComponent;
2225
const columnTabs = [
23-
{
24-
field: 'id',
25-
headerName: 'ID',
26-
width: 30,
27-
editable: false
28-
},
26+
// {
27+
// field: 'id',
28+
// headerName: 'ID',
29+
// width: 30,
30+
// editable: false
31+
// },
2932
{
3033
field: 'key',
3134
headerName: 'Key',
@@ -55,7 +58,7 @@ const TableParentProps = props => {
5558
style={{ width: `${3}px`, color: 'black'}}
5659
onClick={() => {
5760
console.log('params inside button', params)
58-
addParentProps(params.row, params.id);
61+
addParentProps(params.row, params.id - 1);
5962
}}
6063
>
6164
<AddIcon style={{ width: `${15}px` }} />
@@ -105,7 +108,20 @@ const TableParentProps = props => {
105108
}, [state.canvasFocus.componentId]);
106109
// rows to show are either from current component or from a given provider
107110
// legacy pd convert parent props into a row array
108-
let rows = parentProps;
111+
//let rows = parentProps;
112+
let rows;
113+
114+
if (currentComponent.name === 'App') {rows = []}
115+
else {
116+
if (parentProps) {
117+
rows = parentProps;
118+
if (parentPassedInProps) {
119+
rows = [...rows, ...parentPassedInProps]
120+
}
121+
}
122+
}
123+
124+
console.log({rows});
109125
// if (!props.providerId) {
110126
// const currentId = state.canvasFocus.componentId;
111127
// const currentComponent = state.components[currentId - 1];

app/src/components/StateManagement/CreateTab/components/TableStateProps.tsx

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ const TableStateProps = props => {
1919
const currentComponent = state.components[currentId - 1];
2020
const rows1 = props.rows1;
2121
const setRows1 = props.setRows1;
22-
console.log({currentComponent})
22+
// console.log({currentComponent})
2323

24-
console.log({rows1})
24+
// console.log({rows1})
2525
const columnTabs = [
26-
{
27-
field: 'id',
28-
headerName: 'ID',
29-
width: 30,
30-
editable: false
31-
},
26+
// {
27+
// field: 'id',
28+
// headerName: 'ID',
29+
// width: 30,
30+
// editable: false
31+
// },
3232
{
3333
field: 'key',
3434
headerName: 'Key',
@@ -57,7 +57,7 @@ const TableStateProps = props => {
5757
<Button
5858
style={{ width: `${3}px`, color: 'black'}}
5959
onClick={() => {
60-
deleteState(params.id);
60+
deleteState(params.id, params.row.key);
6161
}}
6262
>
6363
<ClearIcon style={{ width: `${15}px` }} />
@@ -66,7 +66,7 @@ const TableStateProps = props => {
6666
}
6767
}
6868
];
69-
const deleteState = selectedId => {
69+
const deleteState = (selectedId, stateName) => {
7070
// get the current focused component
7171
// remove the state that the button is clicked
7272
// send a dispatch to rerender the table
@@ -75,9 +75,12 @@ const TableStateProps = props => {
7575
const filtered = currentComponent.stateProps.filter(
7676
element => element.id !== selectedId
7777
);
78+
const filteredChildren = currentComponent.children.passedInProps.filter(
79+
element => element.name !== stateName
80+
);
7881
dispatch({
7982
type: 'DELETE STATE',
80-
payload: { stateProps: filtered, rowId: selectedId }
83+
payload: { stateProps: filtered, rowId: selectedId, passedInProps: filteredChildren }
8184
});
8285
};
8386

0 commit comments

Comments
 (0)