14
14
// You should have received a copy of the GNU Affero General Public License
15
15
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
17
- import React , { ChangeEvent , useCallback , useEffect , useState } from "react" ;
18
-
19
- import Grid from "@mui/material/Grid" ;
20
- import { Button , EventSubscriptionIcon } from "mds" ;
21
- import { Theme } from "@mui/material/styles" ;
22
- import createStyles from "@mui/styles/createStyles" ;
23
- import withStyles from "@mui/styles/withStyles" ;
24
- import TableHead from "@mui/material/TableHead" ;
25
- import TableRow from "@mui/material/TableRow" ;
26
- import TableCell from "@mui/material/TableCell" ;
27
- import TableBody from "@mui/material/TableBody" ;
28
- import Checkbox from "@mui/material/Checkbox" ;
29
- import Table from "@mui/material/Table" ;
30
- import {
31
- formFieldStyles ,
32
- modalStyleUtils ,
33
- } from "../../Common/FormComponents/common/styleLibrary" ;
34
-
17
+ import React , { useCallback , useEffect , useState } from "react" ;
18
+ import { Button , DataTable , EventSubscriptionIcon , Grid , InputBox } from "mds" ;
35
19
import { ErrorResponseHandler } from "../../../../common/types" ;
36
- import ModalWrapper from "../../Common/ModalWrapper/ModalWrapper" ;
37
- import InputBoxWrapper from "../../Common/FormComponents/InputBoxWrapper/InputBoxWrapper" ;
38
- import AutocompleteWrapper from "../../Common/FormComponents/AutocompleteWrapper/AutocompleteWrapper" ;
39
20
import { setModalErrorSnackMessage } from "../../../../systemSlice" ;
40
21
import { useAppDispatch } from "../../../../store" ;
41
22
import { api } from "api" ;
42
23
import { NotificationEventType } from "api/consoleApi" ;
43
-
44
- const styles = ( theme : Theme ) =>
45
- createStyles ( {
46
- arnField : {
47
- "& div div .MuiOutlinedInput-root" : {
48
- padding : 0 ,
49
- } ,
50
- } ,
51
- ...formFieldStyles ,
52
- ...modalStyleUtils ,
53
- } ) ;
24
+ import ModalWrapper from "../../Common/ModalWrapper/ModalWrapper" ;
25
+ import AutocompleteWrapper from "../../Common/FormComponents/AutocompleteWrapper/AutocompleteWrapper" ;
26
+ import {
27
+ formFieldStyles ,
28
+ modalBasic ,
29
+ modalStyleUtils ,
30
+ } from "../../Common/FormComponents/common/styleLibrary" ;
54
31
55
32
interface IAddEventProps {
56
- classes : any ;
57
33
open : boolean ;
58
34
selectedBucket : string ;
59
35
closeModalAndRefresh : ( ) => void ;
60
36
}
61
37
62
38
const AddEvent = ( {
63
- classes,
64
39
open,
65
40
selectedBucket,
66
41
closeModalAndRefresh,
@@ -125,28 +100,27 @@ const AddEvent = ({
125
100
{ label : "PUT - Object Uploaded" , value : NotificationEventType . Put } ,
126
101
{ label : "GET - Object accessed" , value : NotificationEventType . Get } ,
127
102
{ label : "DELETE - Object Deleted" , value : NotificationEventType . Delete } ,
103
+ {
104
+ label : "REPLICA - Object Replicated" ,
105
+ value : NotificationEventType . Replica ,
106
+ } ,
107
+ { label : "ILM - Object Transitioned" , value : NotificationEventType . Ilm } ,
128
108
] ;
129
109
130
- const handleClick = (
131
- event : React . MouseEvent < unknown > | ChangeEvent < unknown > ,
132
- name : NotificationEventType
133
- ) => {
134
- const selectedIndex = selectedEvents . indexOf ( name ) ;
135
- let newSelected : NotificationEventType [ ] = [ ] ;
110
+ const handleClick = ( event : React . ChangeEvent < HTMLInputElement > ) => {
111
+ const targetD = event . target ;
112
+ const value = targetD . value ;
113
+ const checked = targetD . checked ;
136
114
137
- if ( selectedIndex === - 1 ) {
138
- newSelected = newSelected . concat ( selectedEvents , name ) ;
139
- } else if ( selectedIndex === 0 ) {
140
- newSelected = newSelected . concat ( selectedEvents . slice ( 1 ) ) ;
141
- } else if ( selectedIndex === selectedEvents . length - 1 ) {
142
- newSelected = newSelected . concat ( selectedEvents . slice ( 0 , - 1 ) ) ;
143
- } else if ( selectedIndex > 0 ) {
144
- newSelected = newSelected . concat (
145
- selectedEvents . slice ( 0 , selectedIndex ) ,
146
- selectedEvents . slice ( selectedIndex + 1 )
147
- ) ;
115
+ let elements : NotificationEventType [ ] = [ ...selectedEvents ] ;
116
+
117
+ if ( checked ) {
118
+ elements . push ( value as NotificationEventType ) ;
119
+ } else {
120
+ elements = elements . filter ( ( element ) => element !== value ) ;
148
121
}
149
- setSelectedEvents ( newSelected ) ;
122
+
123
+ setSelectedEvents ( elements ) ;
150
124
} ;
151
125
152
126
const arnValues = arnList ?. map ( ( arnConstant ) => ( {
@@ -171,11 +145,16 @@ const AddEvent = ({
171
145
} }
172
146
>
173
147
< Grid container >
174
- < Grid item xs = { 12 } className = { classes . formScrollable } >
148
+ < Grid item xs = { 12 } sx = { modalBasic . formScrollable } >
175
149
< Grid
176
150
item
177
151
xs = { 12 }
178
- className = { `${ classes . arnField } ${ classes . formFieldRow } ` }
152
+ sx = { {
153
+ ...formFieldStyles . formFieldRow ,
154
+ "& div div .MuiOutlinedInput-root" : {
155
+ padding : 0 ,
156
+ } ,
157
+ } }
179
158
>
180
159
< AutocompleteWrapper
181
160
onChange = { ( value : string ) => {
@@ -188,8 +167,8 @@ const AddEvent = ({
188
167
options = { arnValues || [ ] }
189
168
/>
190
169
</ Grid >
191
- < Grid item xs = { 12 } className = { classes . formFieldRow } >
192
- < InputBoxWrapper
170
+ < Grid item xs = { 12 } sx = { formFieldStyles . formFieldRow } >
171
+ < InputBox
193
172
id = "prefix-input"
194
173
name = "prefix-input"
195
174
label = "Prefix"
@@ -199,8 +178,8 @@ const AddEvent = ({
199
178
} }
200
179
/>
201
180
</ Grid >
202
- < Grid item xs = { 12 } className = { classes . formFieldRow } >
203
- < InputBoxWrapper
181
+ < Grid item xs = { 12 } sx = { formFieldStyles . formFieldRow } >
182
+ < InputBox
204
183
id = "suffix-input"
205
184
name = "suffix-input"
206
185
label = "Suffix"
@@ -210,41 +189,19 @@ const AddEvent = ({
210
189
} }
211
190
/>
212
191
</ Grid >
213
- < Grid item xs = { 12 } className = { classes . formFieldRow } >
214
- < Table size = "medium" >
215
- < TableHead className = { classes . minTableHeader } >
216
- < TableRow >
217
- < TableCell > Select</ TableCell >
218
- < TableCell > Event</ TableCell >
219
- </ TableRow >
220
- </ TableHead >
221
- < TableBody >
222
- { events . map ( ( row ) => (
223
- < TableRow
224
- key = { `group-${ row . value } ` }
225
- onClick = { ( event ) => handleClick ( event , row . value ) }
226
- >
227
- < TableCell padding = "checkbox" >
228
- < Checkbox
229
- value = { row . value }
230
- color = "primary"
231
- inputProps = { {
232
- "aria-label" : "secondary checkbox" ,
233
- } }
234
- onChange = { ( event ) => handleClick ( event , row . value ) }
235
- checked = { selectedEvents . includes ( row . value ) }
236
- />
237
- </ TableCell >
238
- < TableCell className = { classes . wrapCell } >
239
- { row . label }
240
- </ TableCell >
241
- </ TableRow >
242
- ) ) }
243
- </ TableBody >
244
- </ Table >
192
+ < Grid item xs = { 12 } sx = { formFieldStyles . formFieldRow } >
193
+ < DataTable
194
+ columns = { [ { label : "Event" , elementKey : "label" } ] }
195
+ idField = { "value" }
196
+ records = { events }
197
+ onSelect = { handleClick }
198
+ selectedItems = { selectedEvents }
199
+ noBackground
200
+ customPaperHeight = { "260px" }
201
+ />
245
202
</ Grid >
246
203
</ Grid >
247
- < Grid item xs = { 12 } className = { classes . modalButtonBar } >
204
+ < Grid item xs = { 12 } sx = { modalStyleUtils . modalButtonBar } >
248
205
< Button
249
206
id = { "cancel-add-event" }
250
207
type = "button"
@@ -259,7 +216,7 @@ const AddEvent = ({
259
216
id = { "save-event" }
260
217
type = "submit"
261
218
variant = "callAction"
262
- disabled = { addLoading }
219
+ disabled = { addLoading || arn === "" || selectedEvents . length === 0 }
263
220
label = { "Save" }
264
221
/>
265
222
</ Grid >
@@ -269,4 +226,4 @@ const AddEvent = ({
269
226
) ;
270
227
} ;
271
228
272
- export default withStyles ( styles ) ( AddEvent ) ;
229
+ export default AddEvent ;
0 commit comments