Skip to content

Commit a3e3a0a

Browse files
Fixed delete state button, but useContext needs to be fixed now
1 parent 2390734 commit a3e3a0a

File tree

4 files changed

+70
-66
lines changed

4 files changed

+70
-66
lines changed

app/src/components/bottom/UseStateModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import TableStateProps from '../right/TableStateProps';
77
function UseStateModal({ updateAttributeWithState, attributeToChange, childId }) {
88
const [state, dispatch] = useContext(StateContext);
99
const [open, setOpen] = useState(false);
10+
const [componentProviderId, setComponentProviderId] = useState(1) // id is initialized to App
1011

1112
// make buttons to choose which component to get state from
12-
const [componentProviderId, setComponentProviderId] = useState(1) // for now set to App
1313
const components = [];
1414
for (let i = 0; i < state.components.length; i ++) {
1515
components.push(<button onClick={() => setComponentProviderId(i+1)}>{state.components[i].name}</button>)

app/src/components/right/TableStateProps.tsx

Lines changed: 63 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,56 @@ import Button from '@material-ui/core/Button';
88
import ClearIcon from '@material-ui/icons/Clear';
99
import StateContext from '../../context/context';
1010
import { makeStyles } from '@material-ui/core/styles';
11-
1211
import { StatePropsPanelProps } from '../../interfaces/Interfaces';
1312

13+
14+
const TableStateProps = (props) => {
15+
const [state, dispatch] = useContext(StateContext);
16+
const classes = useStyles();
17+
const [editRowsModel] = useState <GridEditRowsModel> ({});
18+
const [gridColumns, setGridColumns] = useState([]);
19+
const [rows, setRows] = useState([]);
20+
21+
22+
useEffect(() => {
23+
setGridColumns(getColumns(props, state, dispatch));
24+
}, [props.isThemeLight])
25+
// get currentComponent by using currently focused component's id
26+
27+
// rows to show are either from current component or from a given provider
28+
29+
const { selectHandler } : StatePropsPanelProps = props;
30+
31+
// when component gets mounted, sets the gridColumn
32+
useEffect(() => {
33+
setGridColumns(getColumns(props, state, dispatch));
34+
35+
if (!props.providerId) {
36+
const currentId = state.canvasFocus.componentId;
37+
const currentComponent = state.components[currentId - 1];
38+
setRows(currentComponent.stateProps.slice());
39+
} else {
40+
const providerComponent = state.components[props.providerId - 1];
41+
setRows(providerComponent.stateProps.slice());
42+
}
43+
44+
}, [props.providerId, state]);
45+
46+
return (
47+
<div className={'state-prop-grid'}>
48+
<DataGrid
49+
rows={rows}
50+
columns={gridColumns}
51+
pageSize={5}
52+
editRowsModel={editRowsModel}
53+
onRowClick = {selectHandler}
54+
className={props.isThemeLight ? classes.themeLight : classes.themeDark}
55+
/>
56+
</div>
57+
);
58+
};
59+
60+
1461
const getColumns = (props, state, dispatch) => {
1562
return [
1663
{
@@ -44,7 +91,6 @@ const getColumns = (props, state, dispatch) => {
4491
editable: false,
4592
renderCell: function renderCell(params:any) {
4693
const getIdRow = () => {
47-
const { api } = params;
4894
// const fields = api.getAllColumns().map((c: any) => c.field).filter((c : any) => c !== '__check__' && !!c);
4995
return params.id;
5096
// return params.getValue(fields[0]);
@@ -53,24 +99,29 @@ const getColumns = (props, state, dispatch) => {
5399
<Button style={{width:`${3}px`}}
54100
onClick={() => {
55101
const deleteAttributeWithState = (id) => {
56-
console.log('id=',id);
57-
console.log('state.components =', state.components)
58102
let currentComponent;
59103
if(!props.providerId) {
60104
const currentId = state.canvasFocus.componentId;
61105
currentComponent = state.components[currentId - 1];
62-
console.log('currentId', currentId);
63-
console.log('currentComponent =', currentComponent);
106+
const filtered = currentComponent.stateProps.filter(element => element.id !== id);
107+
console.log('filtered:', filtered);
108+
dispatch({
109+
type: 'DELETE STATE',
110+
payload: {stateProps: filtered}
111+
});
64112
}
65113
else {
66114
currentComponent = state.components[props.providerId - 1];
115+
console.log("row-id: ", id);
116+
console.log("provider-id: ", props.providerId)
117+
console.log("currentProviderComponent: ", currentComponent);
118+
const filtered = currentComponent.stateProps.filter(element => element.id !== id);
119+
console.log('filtered:', filtered);
120+
dispatch({
121+
type: 'DELETE STATE',
122+
payload: {stateProps: filtered, providerId: props.providerId}
123+
});
67124
}
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-
});
74125
}
75126

76127
deleteAttributeWithState(getIdRow());
@@ -85,52 +136,6 @@ const getColumns = (props, state, dispatch) => {
85136
];
86137
};
87138

88-
//, providerId=1
89-
const TableStateProps = (props) => {
90-
const classes = useStyles();
91-
const [state, dispatch] = useContext(StateContext);
92-
const [editRowsModel] = useState <GridEditRowsModel> ({});
93-
const [gridColumns, setGridColumns] = useState([]);
94-
95-
96-
useEffect(() => {
97-
setGridColumns(getColumns(props, state, dispatch));
98-
}, [props.isThemeLight])
99-
// get currentComponent by using currently focused component's id
100-
const currentId = state.canvasFocus.componentId;
101-
const currentComponent = state.components[currentId - 1];
102-
103-
// rows to show are either from current component or from a given provider
104-
let rows = [];
105-
if (!props.providerId) {
106-
rows = currentComponent.stateProps.slice();
107-
} else {
108-
const providerComponent = state.components[props.providerId - 1];
109-
rows = providerComponent.stateProps.slice();
110-
}
111-
112-
const { selectHandler } : StatePropsPanelProps = props;
113-
114-
// when component gets mounted, sets the gridColumn
115-
useEffect(() => {
116-
setGridColumns(getColumns(props, state, dispatch));
117-
}, [state]);
118-
119-
return (
120-
<div className={'state-prop-grid'}>
121-
<DataGrid
122-
rows={rows}
123-
columns={gridColumns}
124-
pageSize={5}
125-
editRowsModel={editRowsModel}
126-
onRowClick = {selectHandler}
127-
className={props.isThemeLight ? classes.themeLight : classes.themeDark}
128-
/>
129-
</div>
130-
);
131-
};
132-
133-
134139
const useStyles = makeStyles({
135140
themeLight: {
136141
color: 'rgba(0,0,0,0.54)',

app/src/containers/CustomizationPanel.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,19 +212,13 @@ const CustomizationPanel = ({ isThemeLight }): JSX.Element => {
212212
const currentComponentProps = currentComponent.stateProps;
213213
const newInput = currentComponentProps[statePropsId - 1].value;
214214

215-
console.log('currentComponent = ',currentComponent);
216-
console.log('currentComponentProps =', currentComponentProps);
217-
console.log('newInput', newInput);
218215

219216
if (attributeName === 'compText') {
220217
const newContextObj = useContextObj;
221-
console.log('Line 223 newContextObj=',newContextObj)
222218
if (!newContextObj[componentProviderId]) {
223219
newContextObj[componentProviderId] = {};
224220
}
225221
newContextObj[componentProviderId].compText = statePropsId;
226-
console.log('Line 288, newContextObj[componentProviderId].compText = ', newContextObj[componentProviderId].compText);
227-
console.log('statePropsId = ', statePropsId);
228222
setCompText(newInput);
229223
setUseContextObj(newContextObj);
230224
}

app/src/reducers/componentReducer.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,9 +791,14 @@ const reducer = (state: State, action: Action) => {
791791

792792
case 'DELETE STATE' : {
793793
const components = [...state.components];
794-
let currComponent = findComponent(
794+
let currComponent = !action.payload.providerId
795+
? findComponent(
795796
components,
796797
state.canvasFocus.componentId
798+
)
799+
: findComponent(
800+
components,
801+
action.payload.providerId
797802
);
798803

799804
currComponent.stateProps = action.payload.stateProps;

0 commit comments

Comments
 (0)