Skip to content

Commit c5d5d6d

Browse files
KPjonocrbuddhajjigaewilliamdyoonMadinventorZero
authored andcommitted
Resolved missing type errors. Fixed bug that triggered re-rendering. Modularized re-usable code. Matched styling to main app container. Added documentation to StatePropsPanel and TableStateProps.
Co-authored-by: jonocr <[email protected]> Co-authored-by: buddhajjigae <[email protected]> Co-authored-by: williamdyoon <[email protected]> Co-authored-by: MadinventorZero <[email protected]>
1 parent af432f2 commit c5d5d6d

File tree

4 files changed

+39
-34
lines changed

4 files changed

+39
-34
lines changed

.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"extends": ["plugin:react/recommended", "airbnb-base"],
2+
"extends": ["plugin:react/recommended", "plugin:@typescript-eslint/recommended", "airbnb-base"],
33
"parserOptions": {
44
"ecmaFeatures": {
55
"jsx": true

app/src/components/right/StatePropsPanel.tsx

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import TableStateProps from "./TableStateProps";
2626

2727
const StatePropsPanel = ({ isThemeLight }): JSX.Element => {
2828
const classes = useStyles();
29-
const [state, dispatch] = useContext(StateContext);
29+
const [state] = useContext(StateContext);
3030

3131
const [inputKey, setInputKey] = useState("");
3232
const [inputValue, setInputValue] = useState("");
@@ -37,7 +37,7 @@ const StatePropsPanel = ({ isThemeLight }): JSX.Element => {
3737
// detect changes to component.stateProps[], renders and prints its contents
3838
useEffect(() => {
3939
console.log(new Date().toLocaleDateString(), 'stateProps:', stateProps);
40-
}, [stateProps])
40+
}, [stateProps]);
4141

4242
// get currentComponent by using currently focused component's id
4343
const currentId = state.canvasFocus.componentId;
@@ -47,10 +47,7 @@ const StatePropsPanel = ({ isThemeLight }): JSX.Element => {
4747
const debug = () => {
4848
console.log("currentComponent:", currentComponent);
4949
console.log("currentComponent.stateProps:", currentComponent.stateProps);
50-
console.log(
51-
"currentComponent.useStateCodes:",
52-
currentComponent.useStateCodes
53-
);
50+
console.log("currentComponent.useStateCodes:", currentComponent.useStateCodes);
5451
};
5552

5653
// convert value to correct type based on user input
@@ -66,6 +63,7 @@ const StatePropsPanel = ({ isThemeLight }): JSX.Element => {
6663
return value;
6764
}
6865
};
66+
6967
// clears the input key, value, and type on Form
7068
const clearForm = () => {
7169
setInputKey("");
@@ -118,17 +116,16 @@ const StatePropsPanel = ({ isThemeLight }): JSX.Element => {
118116
setInputKey(table.row.key);
119117
setInputType(table.row.type);
120118
setInputValue(table.row.value);
121-
}
122-
else clearForm();
123-
}
124-
119+
} else clearForm();
120+
};
121+
125122
// find & delete table row using its id
126-
const handlerRowDelete = (id) => {
127-
//iterate and filter out stateProps with matching row id
128-
currentComponent.stateProps = currentComponent.stateProps.filter(element => element.id != id);
123+
const handlerRowDelete = (id:any) => {
124+
// iterate and filter out stateProps with matching row id
125+
currentComponent.stateProps = currentComponent.stateProps.filter(element => element.id !== id);
129126
updateUseStateCodes();
130127
setStateProps(currentComponent.stateProps.slice());
131-
}
128+
};
132129

133130
return (
134131
<div style={{'background-color':`#ececea`}}>

app/src/components/right/TableStateProps.tsx

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
// CARET
22
import React, { useState, useContext, useEffect } from 'react';
3+
import PropTypes from 'prop-types';
34
import {
45
DataGrid,
5-
GridColumns,
66
GridEditRowsModel,
77
} from '@material-ui/data-grid';
8-
import {
9-
styled,
10-
} from "@material-ui/core/styles";
11-
import Button from "@material-ui/core/Button";
8+
import Button from '@material-ui/core/Button';
9+
import ClearIcon from '@material-ui/icons/Clear';
1210
import StateContext from '../../context/context';
1311

14-
import ClearIcon from '@material-ui/icons/Clear';
15-
import { IconButton, SvgIcon } from '@material-ui/core';
12+
import { StatePropsPanelProps } from '../../interfaces/Interfaces';
1613

1714
const getColumns = (props) => {
15+
const { deleteHandler } : StatePropsPanelProps = props;
1816
return [
1917
{
2018
field: 'id',
@@ -45,36 +43,37 @@ const getColumns = (props) => {
4543
headerName: 'X',
4644
width: 70,
4745
editable: false,
48-
renderCell: (params) => {
46+
renderCell: function renderCell(params:any) {
4947
const getIdRow = () => {
50-
const api: GridApi = params.api;
51-
const fields = api.getAllColumns().map((c) => c.field).filter((c) => c !== "__check__" && !!c);
52-
return params.getValue(fields[0]);
48+
const { api } = params;
49+
const fields = api.getAllColumns().map((c: any) => c.field).filter((c : any) => c !== '__check__' && !!c);
50+
return params.getValue(fields[0]);
5351
};
5452
return (
5553
<Button style={{width:`${3}px`}}
5654
onClick={() => {
57-
props.deleteHandler(getIdRow());
55+
deleteHandler(getIdRow());
5856
}}>
5957
<ClearIcon style={{width:`${15}px`}}/>
6058
</Button>
6159
);
62-
}
60+
},
6361
},
6462
];
6563
};
6664

67-
6865
const TableStateProps = (props) => {
69-
const [state, dispatch] = useContext(StateContext);
70-
const [editRowsModel, setEditRowsModel] = useState < GridEditRowsModel > ({});
66+
const [state] = useContext(StateContext);
67+
const [editRowsModel] = useState <GridEditRowsModel> ({});
7168
const [gridColumns, setGridColumns] = useState([]);
7269

7370
// get currentComponent by using currently focused component's id
7471
const currentId = state.canvasFocus.componentId;
7572
const currentComponent = state.components[currentId - 1];
7673

7774
const rows = currentComponent.stateProps.slice();
75+
76+
const { selectHandler } : StatePropsPanelProps = props;
7877

7978
// when component gets mounted, sets the gridColumn
8079
useEffect(() => {
@@ -84,14 +83,14 @@ const TableStateProps = (props) => {
8483
return (
8584
<div style={{ height: 400, width: '100%' }}>
8685
<DataGrid
87-
// disableMultipleSelection={false}
8886
rows={rows}
8987
columns={gridColumns}
9088
pageSize={5}
9189
editRowsModel={editRowsModel}
92-
onRowClick={props.selectHandler}
90+
onRowClick = {selectHandler}
9391
/>
9492
</div>
9593
);
96-
}
94+
};
95+
9796
export default TableStateProps;

app/src/interfaces/Interfaces.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,13 @@ export interface Annotations {
9898
name: string;
9999
annotations: string;
100100
}
101+
102+
export interface StatePropsPanelProps {
103+
selectHandler: (table: any) => void;
104+
deleteHandler: (id: number | any) => void;
105+
}
106+
107+
export interface TableStateProps {
108+
}
109+
101110
// Caret end

0 commit comments

Comments
 (0)