@@ -47,7 +47,7 @@ export default function ConfigureAuditLogDestinations({
47
47
setCurrentServerAuditDestinations,
48
48
newServerName,
49
49
fetchServerConfig,
50
- setLoadingText,
50
+ setLoadingText
51
51
} = useContext ( ServerAuthorContext ) ;
52
52
const { userId, serverName : tenantId } = useContext ( IdentificationContext ) ;
53
53
@@ -94,6 +94,30 @@ export default function ConfigureAuditLogDestinations({
94
94
console . log ( "onChangeTypeSelected " + e . target . value ) ;
95
95
setCurrentDestinationTypeName ( e . target . value ) ;
96
96
} ;
97
+ /**
98
+ * We are padded the id of the severity that has changed. This fuctions is careful to clone
99
+ * the existing currentSupportedSeverities, so we can amend the array and then set it in state.
100
+ */
101
+ const handleOnChangeSeverity = ( id ) => {
102
+ console . log ( "onChangeTypeSelected " ) ;
103
+ let newCurrentSeverities ;
104
+ for ( let i = 0 ; i < currentSupportedSeverities . length ; i ++ ) {
105
+ const currentSeverity = currentSupportedSeverities [ i ] ;
106
+ if ( currentSeverity . id === id ) {
107
+ // clone to a new object
108
+ let newSeverity = {
109
+ ...currentSeverity ,
110
+ selected : ! currentSeverity . selected , // toggle the selected state
111
+ } ;
112
+ //replace the element in the array
113
+ newCurrentSeverities = currentSupportedSeverities . map ( function ( severity ) { return severity . id == id ? newSeverity : severity ; } ) ;
114
+
115
+ break ;
116
+ }
117
+ }
118
+ // set the new current supported severities in state
119
+ setCurrentSupportedSeverities ( newCurrentSeverities ) ;
120
+ } ;
97
121
const getConnectorProviderClass = ( ) => {
98
122
let connectorClass = currentCustomConnectorClass ;
99
123
@@ -118,12 +142,18 @@ export default function ConfigureAuditLogDestinations({
118
142
}
119
143
return type ;
120
144
} ;
145
+ const supportedSeverities = supportedAuditLogSeverities . map ( ( s ) => {
146
+ return {
147
+ ...s ,
148
+ selected : true ,
149
+ } ;
150
+ } ) ;
121
151
122
152
const onClickAdd = ( ) => {
123
153
setCurrentDestinationName ( undefined ) ;
124
154
setCurrentDestinationId ( undefined ) ;
125
155
setCurrentDestinationDescription ( undefined ) ;
126
- setCurrentSupportedSeverities ( undefined ) ;
156
+ setCurrentSupportedSeverities ( supportedSeverities ) ;
127
157
setCurrentDestinationTypeName ( 'default' ) ;
128
158
129
159
setOperation ( "Add" ) ;
@@ -219,12 +249,23 @@ export default function ConfigureAuditLogDestinations({
219
249
if ( ! isCopy ) {
220
250
destinationName = auditLogDestinationToEdit . name ;
221
251
}
252
+
253
+
254
+
255
+ const supportedSeveritiesSelectedNames = auditLogDestinationToEdit . supportedSeverities ;
256
+
257
+ let checkedSupportedSeverities = [ ] ;
258
+ for ( let i = 0 ; i < supportedAuditLogSeverities . length ; i ++ ) {
259
+ let severity = supportedAuditLogSeverities [ i ] ;
260
+ severity . selected = supportedSeveritiesSelectedNames . includes ( severity . id ) ;
261
+ checkedSupportedSeverities . push ( severity ) ;
262
+ }
222
263
//we need to store the original name as this is the key that will be updated in the rest call.
223
264
setCurrentDestinationId ( destinationName ) ;
224
265
//the name could change in the editor
225
266
setCurrentDestinationName ( destinationName ) ;
226
267
setCurrentDestinationDescription ( auditLogDestinationToEdit . description ) ;
227
- setCurrentSupportedSeverities ( auditLogDestinationToEdit . severities ) ;
268
+ setCurrentSupportedSeverities ( checkedSupportedSeverities ) ;
228
269
setCurrentDestinationTypeName ( auditLogDestinationToEdit . type ) ;
229
270
230
271
let op = "Edit" ;
@@ -245,6 +286,10 @@ export default function ConfigureAuditLogDestinations({
245
286
issueEdit ( ) ;
246
287
}
247
288
} ;
289
+ const onClickCancelOperation = ( ) => {
290
+ setOperation ( undefined ) ;
291
+ } ;
292
+
248
293
const issueAdd = ( ) => {
249
294
let nameExists = false ;
250
295
for ( let i = 0 ; i < currentServerAuditDestinations . length ; i ++ ) {
@@ -263,7 +308,7 @@ export default function ConfigureAuditLogDestinations({
263
308
"The requested Audit Log Destination Name need to have a value. Please specify one."
264
309
) ;
265
310
} else {
266
- setOperation ( undefined ) ;
311
+
267
312
268
313
const addAuditLogDestinationURL = encodeURI (
269
314
"/servers/" +
@@ -274,36 +319,8 @@ export default function ConfigureAuditLogDestinations({
274
319
newServerName +
275
320
"/audit-log-destinations/connection"
276
321
) ;
277
- const body = {
278
- class : "Connection" ,
279
- headerVersion : 0 ,
280
- displayName : currentDestinationName ,
281
- description : currentDestinationDescription ,
282
- connectorType : {
283
- class : "ConnectorType" ,
284
- headerVersion : 0 ,
285
- type : {
286
- class : "ElementType" ,
287
- headerVersion : 0 ,
288
- elementOrigin : "LOCAL_COHORT" ,
289
- elementVersion : 0 ,
290
- elementTypeId : "954421eb-33a6-462d-a8ca-b5709a1bd0d4" ,
291
- elementTypeName : "ConnectorType" ,
292
- elementTypeVersion : 1 ,
293
- elementTypeDescription :
294
- "A set of properties describing a type of connector." ,
295
- } ,
296
- guid : "4afac741-3dcc-4c60-a4ca-a6dede994e3f" ,
297
- qualifiedName : "Console Audit Log Store Connector" ,
298
- displayName : "Console Audit Log Store Connector" ,
299
- description :
300
- "Connector supports logging of audit log messages to stdout." ,
301
- connectorProviderClassName : getConnectorProviderClass ( ) ,
302
- } ,
303
- configurationProperties : {
304
- supportedSeverities : currentSupportedSeverities ,
305
- } ,
306
- } ;
322
+ setOperation ( undefined ) ;
323
+ const body = getRestBody ( ) ;
307
324
console . log ( "addAuditLogDestinationURL " + addAuditLogDestinationURL ) ;
308
325
setLoadingText ( "Adding audit log destination" ) ;
309
326
issueRestCreate (
@@ -328,7 +345,28 @@ export default function ConfigureAuditLogDestinations({
328
345
"/audit-log-destinations/connection/" +
329
346
currentDestinationId
330
347
) ;
331
- const body = {
348
+ const body = getRestBody ( ) ;
349
+ console . log ( "editAuditLogDestinationURL " + editAuditLogDestinationURL ) ;
350
+ setLoadingText ( "Editing audit log destination" ) ;
351
+ issueRestUpdate (
352
+ editAuditLogDestinationURL ,
353
+ body ,
354
+ onSuccessfulEditAuditLogDestination ,
355
+ onErrorAuditLogDestination ,
356
+ "omagServerConfig"
357
+ ) ;
358
+ } ;
359
+
360
+ const getRestBody = ( ) => {
361
+ let restSeverities = [ ] ;
362
+ for ( let i = 0 ; i < currentSupportedSeverities . length ; i ++ ) {
363
+ const currentSeverity = currentSupportedSeverities [ i ] ;
364
+ if ( currentSeverity . selected ) {
365
+ restSeverities . push ( currentSeverity . id ) ;
366
+ }
367
+ }
368
+
369
+ return {
332
370
class : "Connection" ,
333
371
headerVersion : 0 ,
334
372
displayName : currentDestinationName ,
@@ -355,18 +393,10 @@ export default function ConfigureAuditLogDestinations({
355
393
connectorProviderClassName : getConnectorProviderClass ( ) ,
356
394
} ,
357
395
configurationProperties : {
358
- supportedSeverities : currentSupportedSeverities ,
396
+ supportedSeverities : restSeverities
359
397
} ,
360
398
} ;
361
- console . log ( "editAuditLogDestinationURL " + editAuditLogDestinationURL ) ;
362
- setLoadingText ( "Editing audit log destination" ) ;
363
- issueRestUpdate (
364
- editAuditLogDestinationURL ,
365
- body ,
366
- onSuccessfulEditAuditLogDestination ,
367
- onErrorAuditLogDestination ,
368
- "omagServerConfig"
369
- ) ;
399
+
370
400
} ;
371
401
const onSuccessfulAddAuditLogDestination = ( ) => {
372
402
console . log ( "onSuccessfulAddAuditLogDestination entry" ) ;
@@ -388,15 +418,16 @@ export default function ConfigureAuditLogDestinations({
388
418
// setCurrentServerAuditDestinations(newAuditLogDestinations);
389
419
document . getElementById ( "loading-container" ) . style . display = "none" ;
390
420
setLoadingText ( "Refreshing audit log destinations " ) ;
391
- fetchServerConfig ( refreshAuditLogDestinations , onErrorAuditLogDestination ) ;
421
+ // retrieveAllServers
422
+ fetchServerConfig ( refreshCurrentAuditLogDestinations , onErrorAuditLogDestination ) ;
392
423
393
424
} ;
394
425
const onSuccessfulEditAuditLogDestination = ( ) => {
395
426
console . log ( "onSuccessfulEditAuditLogDestination " ) ;
396
427
console . log ( currentServerAuditDestinations ) ;
397
428
document . getElementById ( "loading-container" ) . style . display = "none" ;
398
429
setLoadingText ( "Refreshing audit log destinations " ) ;
399
- fetchServerConfig ( refreshAuditLogDestinations , onErrorAuditLogDestination ) ;
430
+ fetchServerConfig ( refreshCurrentAuditLogDestinations , onErrorAuditLogDestination ) ;
400
431
} ;
401
432
402
433
const onSuccessfulRemoveAll = ( ) => {
@@ -409,11 +440,11 @@ export default function ConfigureAuditLogDestinations({
409
440
console . log ( "onSuccessfulRemove" ) ;
410
441
// Fetch Server Config
411
442
setLoadingText ( "Refreshing audit log destinations " ) ;
412
- fetchServerConfig ( refreshAuditLogDestinations , onErrorAuditLogDestination ) ;
443
+ fetchServerConfig ( refreshCurrentAuditLogDestinations , onErrorAuditLogDestination ) ;
413
444
} ;
414
445
415
- const refreshAuditLogDestinations = ( response ) => {
416
- console . log ( "refreshAuditLogDestinations " ) ;
446
+ const refreshCurrentAuditLogDestinations = ( response ) => {
447
+ console . log ( "refreshCurrentAuditLogDestinations " ) ;
417
448
console . log ( response ) ;
418
449
419
450
const config = response . omagServerConfig ;
@@ -446,8 +477,15 @@ export default function ConfigureAuditLogDestinations({
446
477
auditLogConnection . connectorType . connectorProviderClassName
447
478
) ;
448
479
}
449
-
450
- refreshedAuditLogConnection . supportedSeverities = [ ] ;
480
+ //TODO
481
+ const supportedSeveritiesSelectedNames = auditLogConnection . configurationProperties . supportedSeverities ;
482
+ const supportedSeveritiesNames = supportedAuditLogSeverities . map ( a => a . id ) ;
483
+ let checkedSupportedSeverities = [ ] ;
484
+ for ( let i = 0 ; i < supportedAuditLogSeverities . length ; i ++ ) {
485
+ let severity = supportedAuditLogSeverities [ i ] ;
486
+ severity . selected = supportedSeveritiesSelectedNames . includes ( severity . id ) ;
487
+ checkedSupportedSeverities . push ( severity ) ;
488
+ }
451
489
if (
452
490
auditLogConnection . configurationProperties &&
453
491
auditLogConnection . configurationProperties . supportedSeverities
@@ -457,7 +495,7 @@ export default function ConfigureAuditLogDestinations({
457
495
}
458
496
refreshedAuditLogConnections . push ( refreshedAuditLogConnection ) ;
459
497
}
460
-
498
+ // update the current server audit destinations with the values from the servere
461
499
setCurrentServerAuditDestinations ( refreshedAuditLogConnections ) ;
462
500
}
463
501
}
@@ -510,15 +548,15 @@ export default function ConfigureAuditLogDestinations({
510
548
autoComplete = "off"
511
549
/>
512
550
< Select
513
- defaultValue = "placeholder-item"
551
+ defaultValue = { currentDestinationTypeName }
514
552
helperText = { destinationTypeDescription }
515
553
onChange = { onChangeTypeSelected }
516
554
id = "select-server-type"
517
555
invalidText = "A valid value is required"
518
556
labelText = "Select Audit Log Destination Type"
519
557
>
520
558
{ auditLogDestinations . map ( ( dest , i ) => (
521
- < SelectItem text = { dest . label } value = { dest . id } id = { dest . id } />
559
+ < SelectItem text = { dest . label } value = { dest . id } id = { dest . id } />
522
560
) ) }
523
561
</ Select >
524
562
{ currentDestinationTypeName === "connection" && (
@@ -554,14 +592,19 @@ export default function ConfigureAuditLogDestinations({
554
592
labelText = { severity . label }
555
593
id = { severity . id }
556
594
checked = { severity . selected }
595
+ onChange = { j => handleOnChangeSeverity ( severity . id ) }
596
+
557
597
/>
558
598
) ) }
559
599
</ div >
560
600
</ div >
561
-
601
+ < button onClick = { ( e ) => onClickCancelOperation ( ) } >
602
+ Cancel { operation }
603
+ </ button >
562
604
< button onClick = { ( e ) => onClickFinishedOperation ( ) } >
563
- Enable this Audit Log Destination
605
+ Issue { operation }
564
606
</ button >
607
+
565
608
</ fieldset >
566
609
) }
567
610
{ operation === undefined && (
0 commit comments