Skip to content

Commit b788cbe

Browse files
committed
Co-authored-by: BenCauffman <[email protected]>
Co-authored-by: Darin <[email protected]> Co-authored-by: Thomas Lukasiewicz <[email protected]> Co-authored-by: Ahsan Rao <[email protected]>
1 parent 34d938c commit b788cbe

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ const StatePropsPanel = ({ isThemeLight, data}): JSX.Element => {
4343
const [parentName, setParentName] = useState('No Parents');
4444
const [parentComponent, setParentComponent] = useState({});
4545
const [rows1, setRows1] = useState(currentComponent.stateProps);
46+
const [propNum, setPropNum] = useState(1);
47+
4648
// convert value to correct type based on user input
4749
const typeConversion = (value, type) => {
4850
switch (type) {
@@ -108,10 +110,11 @@ const StatePropsPanel = ({ isThemeLight, data}): JSX.Element => {
108110
}
109111
}
110112
}
111-
113+
setPropNum(prev => prev + 1);
112114
const newState = {
113115
// check if array is not empty => true find last elem in array. get id and increment by 1 || else 1
114-
id: statesArray.length > 0 ? statesArray[statesArray.length-1].id + 1 : 1,
116+
// id: statesArray.length > 0 ? statesArray[statesArray.length-1].id + 1 : 1,
117+
id: `${currentComponent.name}-${propNum}`,
115118
key: inputKey,
116119
value: typeConversion(inputValue, inputType),
117120
type: inputType,

app/src/reducers/componentReducer.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,15 @@ const reducer = (state: State, action: Action) => {
776776
// need to change this to match the id from the tree
777777
state.canvasFocus.componentId
778778
);
779+
// do a check if prop already exists in passed in props
780+
for (let i = 0; i < currComponent.passedInProps.length; i++) {
781+
let curr = currComponent.passedInProps[i];
782+
console.log('inside for loop curr', curr)
783+
console.log('inside for loop action.payload.passedInProps', action.payload.passedInProps)
784+
if (curr.id === action.payload.passedInProps.id) {
785+
return { ...state, components};
786+
}
787+
}
779788
currComponent.passedInProps.push(action.payload.passedInProps);
780789
console.log('in reducer', currComponent)
781790
//currComponent.useStateCodes = updateUseStateCodes(currComponent);

0 commit comments

Comments
 (0)