@@ -8,9 +8,56 @@ import Button from '@material-ui/core/Button';
8
8
import ClearIcon from '@material-ui/icons/Clear' ;
9
9
import StateContext from '../../context/context' ;
10
10
import { makeStyles } from '@material-ui/core/styles' ;
11
-
12
11
import { StatePropsPanelProps } from '../../interfaces/Interfaces' ;
13
12
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
+
14
61
const getColumns = ( props , state , dispatch ) => {
15
62
return [
16
63
{
@@ -44,7 +91,6 @@ const getColumns = (props, state, dispatch) => {
44
91
editable : false ,
45
92
renderCell : function renderCell ( params :any ) {
46
93
const getIdRow = ( ) => {
47
- const { api } = params ;
48
94
// const fields = api.getAllColumns().map((c: any) => c.field).filter((c : any) => c !== '__check__' && !!c);
49
95
return params . id ;
50
96
// return params.getValue(fields[0]);
@@ -53,24 +99,29 @@ const getColumns = (props, state, dispatch) => {
53
99
< Button style = { { width :`${ 3 } px` } }
54
100
onClick = { ( ) => {
55
101
const deleteAttributeWithState = ( id ) => {
56
- console . log ( 'id=' , id ) ;
57
- console . log ( 'state.components =' , state . components )
58
102
let currentComponent ;
59
103
if ( ! props . providerId ) {
60
104
const currentId = state . canvasFocus . componentId ;
61
105
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
+ } ) ;
64
112
}
65
113
else {
66
114
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
+ } ) ;
67
124
}
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
125
}
75
126
76
127
deleteAttributeWithState ( getIdRow ( ) ) ;
@@ -85,52 +136,6 @@ const getColumns = (props, state, dispatch) => {
85
136
] ;
86
137
} ;
87
138
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
-
134
139
const useStyles = makeStyles ( {
135
140
themeLight : {
136
141
color : 'rgba(0,0,0,0.54)' ,
0 commit comments