Skip to content

Commit 2390734

Browse files
Currently working on delete state, which is bugged
1 parent 75df4fd commit 2390734

File tree

4 files changed

+47
-32
lines changed

4 files changed

+47
-32
lines changed

app/src/components/bottom/UseStateModal.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import StateContext from '../../context/context';
44
import TableStateProps from '../right/TableStateProps';
55

66
// TODO: typescript interface or type check
7-
function UseStateModal({ updateAttributeWithState, deleteAttributeWithState, attributeToChange, childId }) {
7+
function UseStateModal({ updateAttributeWithState, attributeToChange, childId }) {
88
const [state, dispatch] = useContext(StateContext);
99
const [open, setOpen] = useState(false);
1010

@@ -15,6 +15,7 @@ function UseStateModal({ updateAttributeWithState, deleteAttributeWithState, att
1515
components.push(<button onClick={() => setComponentProviderId(i+1)}>{state.components[i].name}</button>)
1616
}
1717

18+
1819
// return the selected state's ID back so the value of it can be updated in the customizationpanel. to the assign the value of selected state to attribute tied to useState button (currently just text)
1920
// attribute to change as parameter for
2021
const body = (
@@ -36,11 +37,8 @@ function UseStateModal({ updateAttributeWithState, deleteAttributeWithState, att
3637
<TableStateProps
3738
providerId = {componentProviderId}
3839
selectHandler={(table) => {
39-
console.log('componentProviderId = ',componentProviderId);
40-
console.log('table.row = ',table.row);
4140
updateAttributeWithState(attributeToChange, componentProviderId, table.row.id);
4241
}}
43-
deleteHandler={() => deleteAttributeWithState()}
4442
isThemeLight={true}
4543
/>
4644
</div>

app/src/components/right/StatePropsPanel.tsx

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ const StatePropsPanel = ({ isThemeLight }): JSX.Element => {
3737
const [inputValue, setInputValue] = useState("");
3838
const [inputType, setInputType] = useState("");
3939

40-
const [stateProps, setStateProps] = useState([]);
41-
4240
// get currentComponent by using currently focused component's id
4341
const currentId = state.canvasFocus.componentId;
4442
const currentComponent = state.components[currentId - 1];
@@ -100,17 +98,14 @@ const StatePropsPanel = ({ isThemeLight }): JSX.Element => {
10098
};
10199

102100
// find & delete table row using its id
103-
const handlerRowDelete = (id:any) => {
104-
// iterate and filter out stateProps with matching row id
105-
const filtered = currentComponent.stateProps.filter(element => element.id !== id);
106-
107-
dispatch({
108-
type: 'DELETE STATE',
109-
payload: {stateProps: filtered}
110-
});
111-
112-
setStateProps(filtered);
113-
};
101+
// const handlerRowDelete = (id:any) => {
102+
// // iterate and filter out stateProps with matching row id
103+
// const filtered = currentComponent.stateProps.filter(element => element.id !== id);
104+
// dispatch({
105+
// type: 'DELETE STATE',
106+
// payload: {stateProps: filtered}
107+
// });
108+
// };
114109

115110
return (
116111
<div className={'state-panel'}>
@@ -189,7 +184,7 @@ const StatePropsPanel = ({ isThemeLight }): JSX.Element => {
189184
<h4 className={isThemeLight ? classes.lightThemeFontColor : classes.darkThemeFontColor}>
190185
Current State Name: {state.components[state.canvasFocus.componentId - 1].name}
191186
</h4>
192-
<TableStateProps selectHandler={handlerRowSelect} deleteHandler={handlerRowDelete} isThemeLight={isThemeLight} />
187+
<TableStateProps selectHandler={handlerRowSelect} isThemeLight={isThemeLight} />
193188
</div>
194189
</div>
195190
);

app/src/components/right/TableStateProps.tsx

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ import { makeStyles } from '@material-ui/core/styles';
1111

1212
import { StatePropsPanelProps } from '../../interfaces/Interfaces';
1313

14-
const getColumns = (props) => {
15-
const { deleteHandler } : StatePropsPanelProps = props;
14+
const getColumns = (props, state, dispatch) => {
1615
return [
1716
{
1817
field: 'id',
@@ -53,8 +52,31 @@ const getColumns = (props) => {
5352
return (
5453
<Button style={{width:`${3}px`}}
5554
onClick={() => {
56-
deleteHandler(getIdRow());
57-
}}>
55+
const deleteAttributeWithState = (id) => {
56+
console.log('id=',id);
57+
console.log('state.components =', state.components)
58+
let currentComponent;
59+
if(!props.providerId) {
60+
const currentId = state.canvasFocus.componentId;
61+
currentComponent = state.components[currentId - 1];
62+
console.log('currentId', currentId);
63+
console.log('currentComponent =', currentComponent);
64+
}
65+
else {
66+
currentComponent = state.components[props.providerId - 1];
67+
}
68+
const filtered = currentComponent.stateProps.filter(element => element.id !== id);
69+
console.log('flitered=', filtered);
70+
dispatch({
71+
type: 'DELETE STATE',
72+
payload: {stateProps: filtered}
73+
});
74+
}
75+
76+
deleteAttributeWithState(getIdRow());
77+
}
78+
79+
}>
5880
<ClearIcon style={{width:`${15}px`}}/>
5981
</Button>
6082
);
@@ -66,13 +88,13 @@ const getColumns = (props) => {
6688
//, providerId=1
6789
const TableStateProps = (props) => {
6890
const classes = useStyles();
69-
const [state] = useContext(StateContext);
91+
const [state, dispatch] = useContext(StateContext);
7092
const [editRowsModel] = useState <GridEditRowsModel> ({});
7193
const [gridColumns, setGridColumns] = useState([]);
7294

7395

7496
useEffect(() => {
75-
setGridColumns(getColumns(props));
97+
setGridColumns(getColumns(props, state, dispatch));
7698
}, [props.isThemeLight])
7799
// get currentComponent by using currently focused component's id
78100
const currentId = state.canvasFocus.componentId;
@@ -91,8 +113,8 @@ const TableStateProps = (props) => {
91113

92114
// when component gets mounted, sets the gridColumn
93115
useEffect(() => {
94-
setGridColumns(getColumns(props));
95-
}, []);
116+
setGridColumns(getColumns(props, state, dispatch));
117+
}, [state]);
96118

97119
return (
98120
<div className={'state-prop-grid'}>

app/src/containers/CustomizationPanel.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,6 @@ const CustomizationPanel = ({ isThemeLight }): JSX.Element => {
207207

208208
// function to pass into UseStateModal to use state to update attribute
209209
const updateAttributeWithState = (attributeName, componentProviderId, statePropsId) => {
210-
console.log('attributeName = ',attributeName); //returns compText or compLink
211-
console.log('statePropsId = ', statePropsId);
212210
// get the stateProps of the componentProvider
213211
const currentComponent = state.components[componentProviderId - 1];
214212
const currentComponentProps = currentComponent.stateProps;
@@ -220,12 +218,13 @@ const CustomizationPanel = ({ isThemeLight }): JSX.Element => {
220218

221219
if (attributeName === 'compText') {
222220
const newContextObj = useContextObj;
223-
console.log('newContextObj=',newContextObj)
221+
console.log('Line 223 newContextObj=',newContextObj)
224222
if (!newContextObj[componentProviderId]) {
225223
newContextObj[componentProviderId] = {};
226224
}
227225
newContextObj[componentProviderId].compText = statePropsId;
228-
226+
console.log('Line 288, newContextObj[componentProviderId].compText = ', newContextObj[componentProviderId].compText);
227+
console.log('statePropsId = ', statePropsId);
229228
setCompText(newInput);
230229
setUseContextObj(newContextObj);
231230
}
@@ -240,7 +239,7 @@ const CustomizationPanel = ({ isThemeLight }): JSX.Element => {
240239
setUseContextObj(newContextObj);
241240
}
242241

243-
const deleteAttributeWithState = alert('Hello from Customization Panel');
242+
244243
// TODO: set something to signify that state was used
245244
// so it can be handled in generateCode
246245

@@ -601,7 +600,8 @@ const CustomizationPanel = ({ isThemeLight }): JSX.Element => {
601600
<UseStateModal
602601
updateAttributeWithState={updateAttributeWithState}
603602
attributeToChange="compText"
604-
childId={state.canvasFocus.childId}/>
603+
childId={state.canvasFocus.childId}
604+
/>
605605
</div>
606606
</div>
607607
<div className={classes.configRow}>

0 commit comments

Comments
 (0)