Skip to content

Commit ce9a9d4

Browse files
authored
Merge pull request #27 from oslabs-beta/RachDebugStateMgmt
Debugged State Management Tab
2 parents 6c2975b + b53f82e commit ce9a9d4

File tree

7 files changed

+13
-796
lines changed

7 files changed

+13
-796
lines changed

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

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import makeStyles from '@mui/styles/makeStyles';
99
import { StatePropsPanelProps } from '../../../../interfaces/Interfaces';
1010
import { useDispatch, useSelector } from 'react-redux';
1111
import { deletePassedInProps } from '../../../../redux/reducers/slice/appStateSlice';
12+
import { deleteState } from '../../../../redux/reducers/slice/appStateSlice';
1213
import { RootState } from '../../../../redux/store'
14+
import { current } from '@reduxjs/toolkit';
1315

1416
const TableStateProps = props => {
1517
const { state, contextParam } = useSelector((store:RootState) => ({
@@ -59,7 +61,7 @@ const TableStateProps = props => {
5961
<Button
6062
style={{ width: `${3}px`, color: 'black'}}
6163
onClick={() => {
62-
deleteState(params.id, params.key);
64+
handleDeleteState(params.id);
6365
}}
6466
>
6567
<ClearIcon style={{ width: `${15}px` }} />
@@ -69,27 +71,13 @@ const TableStateProps = props => {
6971
}
7072
];
7173

72-
const deleteState = (selectedId, stateName) => {
73-
// get the current focused component
74-
// send a dispatch to rerender the table
75-
const currentId = state.canvasFocus.componentId;
76-
const currentComponent = state.components[currentId - 1];
77-
// returns an array of the remaining props after deleting selected prop
78-
const filtered = currentComponent.stateProps.slice();
79-
let otherId;
80-
for (let i = 0; i < filtered.length; i++) {
81-
let curr = filtered[i];
82-
if (curr.id === selectedId) {
83-
if (i %2 ===0) {
84-
otherId = filtered[i + 1];
85-
filtered.splice(i, 2);
86-
} else {
87-
otherId = filtered[i - 1];
88-
filtered.splice(i - 1, 2);
89-
}
90-
}
91-
}
92-
dispatch(deletePassedInProps({stateProps: filtered, rowId: selectedId, otherId: otherId.id, contextParam: contextParam}))
74+
const handleDeleteState = (selectedId) => {
75+
const currentId = state.canvasFocus.componentId;
76+
const currentComponent = state.components[currentId - 1];
77+
const filtered = currentComponent.stateProps.filter(
78+
element => element.id !== selectedId
79+
);
80+
dispatch(deleteState({stateProps: filtered, rowId: selectedId, contextParam: contextParam}))
9381
};
9482

9583
useEffect(() => {

app/src/components/StateManagement/DisplayTab/DataTable.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ const StyledTableCell = styled(TableCell)(({ theme }) => ({
1616
color: theme.palette.common.white,
1717
},
1818
[`&.${tableCellClasses.body}`]: {
19+
color: theme.palette.common.black,
1920
fontSize: 14,
2021
},
2122
}));
2223

2324
const StyledTableRow = styled(TableRow)(({ theme }) => ({
2425
'&:nth-of-type(odd)': {
25-
backgroundColor: theme.palette.action.hover,
26+
backgroundColor: theme.palette.action.hover
2627
},
2728
// hide last border
2829
'&:last-child td, &:last-child th': {

app/src/components/bottom/TableStateProps.tsx

Lines changed: 0 additions & 148 deletions
This file was deleted.

app/src/components/bottom/UseStateModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, {useState, useRef} from 'react';
22
import Modal from '@mui/material/Modal';
3-
import TableStateProps from './TableStateProps';
3+
import TableStateProps from '../StateManagement/CreateTab/components/TableStateProps';
44

55
function UseStateModal({ updateAttributeWithState, attributeToChange, childId }) {
66
const [open, setOpen] = useState(false);

0 commit comments

Comments
 (0)