Skip to content

Commit bce1344

Browse files
authored
Merge pull request #2 from oslabs-beta/benWork
fixed bug with prop drilling delete
2 parents 138fa34 + 0f5fc00 commit bce1344

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const TableParentProps = props => {
5757
<Button
5858
style={{ width: `${3}px`, color: 'black'}}
5959
onClick={() => {
60-
addParentProps(params.row, params.id - 1);
60+
addPassedInProps(params.row, params.id - 1);
6161
}}
6262
>
6363
<AddIcon style={{ width: `${15}px` }} />
@@ -67,7 +67,7 @@ const TableParentProps = props => {
6767
}
6868
}
6969
];
70-
const addParentProps = (parentComponentProps, rowId) => {
70+
const addPassedInProps = (parentComponentProps, rowId) => {
7171
// get the current focused component
7272
// remove the state that the button is clicked
7373
// send a dispatch to rerender the table

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const TableStateProps = props => {
5454
<Button
5555
style={{ width: `${3}px`, color: 'black'}}
5656
onClick={() => {
57-
deleteState(params.id, params.row.key);
57+
deleteState(params.id, params.key);
5858
}}
5959
>
6060
<ClearIcon style={{ width: `${15}px` }} />
@@ -73,7 +73,7 @@ const TableStateProps = props => {
7373
);
7474
dispatch({
7575
type: 'DELETE STATE',
76-
payload: { stateProps: filtered, rowId: selectedId}
76+
payload: { stateProps: filtered, rowId: selectedId }
7777
});
7878
};
7979

app/src/reducers/componentReducer.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,20 @@ const reducer = (state: State, action: Action) => {
818818
);
819819
currComponent.stateProps = action.payload.stateProps;
820820
currComponent.useStateCodes = updateUseStateCodes(currComponent);
821+
821822
components.forEach((component) => {
823+
824+
825+
//find all instances of state within child elements and delete state
826+
827+
828+
if (component.name !== 'App') {
829+
component.passedInProps.forEach((prop, i) => {
830+
if(prop.id === action.payload.rowId) {
831+
component.passedInProps.splice(i,1);
832+
}
833+
});
834+
}
822835
// curr component = where you are deleting from state from, also is the canvas focus
823836
// curr component id = providerId
824837
// we then iterate through the rest of the components

0 commit comments

Comments
 (0)