@@ -9,7 +9,9 @@ import makeStyles from '@mui/styles/makeStyles';
9
9
import { StatePropsPanelProps } from '../../../../interfaces/Interfaces' ;
10
10
import { useDispatch , useSelector } from 'react-redux' ;
11
11
import { deletePassedInProps } from '../../../../redux/reducers/slice/appStateSlice' ;
12
+ import { deleteState } from '../../../../redux/reducers/slice/appStateSlice' ;
12
13
import { RootState } from '../../../../redux/store'
14
+ import { current } from '@reduxjs/toolkit' ;
13
15
14
16
const TableStateProps = props => {
15
17
const { state, contextParam } = useSelector ( ( store :RootState ) => ( {
@@ -59,7 +61,7 @@ const TableStateProps = props => {
59
61
< Button
60
62
style = { { width : `${ 3 } px` , color : 'black' } }
61
63
onClick = { ( ) => {
62
- deleteState ( params . id , params . key ) ;
64
+ handleDeleteState ( params . id ) ;
63
65
} }
64
66
>
65
67
< ClearIcon style = { { width : `${ 15 } px` } } />
@@ -69,27 +71,13 @@ const TableStateProps = props => {
69
71
}
70
72
] ;
71
73
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 } ) )
93
81
} ;
94
82
95
83
useEffect ( ( ) => {
0 commit comments