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 , { Fragment , useEffect , useState } from "react" ;
17
+ import React , { Fragment , useCallback , useEffect , useState } from "react" ;
18
18
import {
19
19
BackLink ,
20
+ Box ,
21
+ breakPoints ,
20
22
Button ,
23
+ ConsoleIcon ,
21
24
EditIcon ,
22
- PageLayout ,
23
- RefreshIcon ,
24
- TrashIcon ,
25
- Box ,
25
+ FormLayout ,
26
26
Grid ,
27
- Switch ,
27
+ HelpBox ,
28
28
InputBox ,
29
- FormLayout ,
30
- breakPoints ,
29
+ PageLayout ,
30
+ RefreshIcon ,
31
31
ScreenTitle ,
32
+ Switch ,
33
+ Tooltip ,
34
+ TrashIcon ,
35
+ ValuePair ,
36
+ WarnIcon ,
32
37
} from "mds" ;
33
38
import { useNavigate , useParams } from "react-router-dom" ;
34
39
import { modalStyleUtils } from "../Common/FormComponents/common/styleLibrary" ;
@@ -42,7 +47,6 @@ import {
42
47
import api from "../../../common/api" ;
43
48
import useApi from "../Common/Hooks/useApi" ;
44
49
import DeleteIDPConfigurationModal from "./DeleteIDPConfigurationModal" ;
45
- import LabelValuePair from "../Common/UsageBarWrapper/LabelValuePair" ;
46
50
import PageHeaderWrapper from "../Common/PageHeaderWrapper/PageHeaderWrapper" ;
47
51
import HelpMenu from "../HelpMenu" ;
48
52
@@ -74,10 +78,12 @@ const IDPConfigurationDetails = ({
74
78
const [ loading , setLoading ] = useState < boolean > ( true ) ;
75
79
const [ isEnabled , setIsEnabled ] = useState < boolean > ( false ) ;
76
80
const [ fields , setFields ] = useState < any > ( { } ) ;
81
+ const [ overrideFields , setOverrideFields ] = useState < any > ( { } ) ;
77
82
const [ originalFields , setOriginalFields ] = useState < any > ( { } ) ;
78
83
const [ record , setRecord ] = useState < any > ( { } ) ;
79
84
const [ editMode , setEditMode ] = useState < boolean > ( false ) ;
80
85
const [ deleteOpen , setDeleteOpen ] = useState < boolean > ( false ) ;
86
+ const [ envOverride , setEnvOverride ] = useState < boolean > ( false ) ;
81
87
82
88
const onSuccess = ( res : any ) => {
83
89
dispatch ( setServerNeedsRestart ( res . restart === true ) ) ;
@@ -102,26 +108,47 @@ const IDPConfigurationDetails = ({
102
108
onEnabledError ,
103
109
) ;
104
110
111
+ const parseFields = useCallback (
112
+ ( record : any ) => {
113
+ let fields : any = { } ;
114
+ let overrideFields : any = { } ;
115
+ let totEnv = 0 ;
116
+
117
+ if ( record . info ) {
118
+ record . info . forEach ( ( item : any ) => {
119
+ if ( item . key === "enable" ) {
120
+ setIsEnabled ( item . value === "on" ) ;
121
+ }
122
+
123
+ if ( item . isEnv ) {
124
+ overrideFields [
125
+ item . key
126
+ ] = `MINIO_IDENTITY_OPENID_${ item . key . toUpperCase ( ) } ${
127
+ configurationName !== "_" ? `_${ configurationName } ` : ""
128
+ } `;
129
+ totEnv ++ ;
130
+ }
131
+
132
+ fields [ item . key ] = item . value ;
133
+ } ) ;
134
+
135
+ if ( totEnv > 0 ) {
136
+ setEnvOverride ( true ) ;
137
+ }
138
+ }
139
+ setFields ( fields ) ;
140
+ setOverrideFields ( overrideFields ) ;
141
+ } ,
142
+ [ configurationName ] ,
143
+ ) ;
144
+
105
145
const toggleEditMode = ( ) => {
106
146
if ( editMode ) {
107
147
parseFields ( record ) ;
108
148
}
109
149
setEditMode ( ! editMode ) ;
110
150
} ;
111
151
112
- const parseFields = ( record : any ) => {
113
- let fields : any = { } ;
114
- if ( record . info ) {
115
- record . info . forEach ( ( item : any ) => {
116
- if ( item . key === "enable" ) {
117
- setIsEnabled ( item . value === "on" ) ;
118
- }
119
- fields [ item . key ] = item . value ;
120
- } ) ;
121
- }
122
- setFields ( fields ) ;
123
- } ;
124
-
125
152
const parseOriginalFields = ( record : any ) => {
126
153
let fields : any = { } ;
127
154
if ( record . info ) {
@@ -157,7 +184,7 @@ const IDPConfigurationDetails = ({
157
184
if ( loading ) {
158
185
loadRecord ( ) ;
159
186
}
160
- } , [ dispatch , loading , configurationName , endpoint ] ) ;
187
+ } , [ dispatch , loading , configurationName , endpoint , parseFields ] ) ;
161
188
162
189
const validSave = ( ) => {
163
190
for ( const [ key , value ] of Object . entries ( formFields ) ) {
@@ -255,6 +282,27 @@ const IDPConfigurationDetails = ({
255
282
} }
256
283
>
257
284
< Grid container >
285
+ { editMode ? (
286
+ < Grid item xs = { 12 } sx = { { marginBottom : 15 } } >
287
+ < HelpBox
288
+ title = {
289
+ < Box
290
+ style = { {
291
+ display : "flex" ,
292
+ justifyContent : "space-between" ,
293
+ alignItems : "center" ,
294
+ flexGrow : 1 ,
295
+ } }
296
+ >
297
+ Client Secret must be re-entered to change OpenID
298
+ configurations
299
+ </ Box >
300
+ }
301
+ iconComponent = { < WarnIcon /> }
302
+ help = { null }
303
+ />
304
+ </ Grid >
305
+ ) : null }
258
306
< Grid xs = { 12 } item >
259
307
{ Object . entries ( formFields ) . map ( ( [ key , value ] ) =>
260
308
renderFormField ( key , value ) ,
@@ -298,26 +346,72 @@ const IDPConfigurationDetails = ({
298
346
const renderViewForm = ( ) => {
299
347
return (
300
348
< Box
349
+ withBorders
301
350
sx = { {
302
351
display : "grid" ,
303
352
gridTemplateColumns : "1fr" ,
304
353
gridAutoFlow : "dense" ,
305
354
gap : 3 ,
306
355
padding : "15px" ,
307
- border : "1px solid #eaeaea" ,
308
356
[ `@media (min-width: ${ breakPoints . sm } px)` ] : {
309
357
gridTemplateColumns : "2fr 1fr" ,
310
358
gridAutoFlow : "row" ,
311
359
} ,
312
360
} }
313
361
>
314
- { Object . entries ( formFields ) . map ( ( [ key , value ] ) => (
315
- < LabelValuePair
316
- key = { key }
317
- label = { value . label }
318
- value = { fields [ key ] ? fields [ key ] : "" }
319
- />
320
- ) ) }
362
+ { Object . entries ( formFields ) . map ( ( [ key , value ] ) => {
363
+ if ( ! value . editOnly ) {
364
+ let label : React . ReactNode = value . label ;
365
+ let val : React . ReactNode = fields [ key ] ? fields [ key ] : "" ;
366
+
367
+ if ( value . type === "toggle" && fields [ key ] ) {
368
+ if ( val !== "on" ) {
369
+ val = "Off" ;
370
+ } else {
371
+ val = "On" ;
372
+ }
373
+ }
374
+
375
+ if ( overrideFields [ key ] ) {
376
+ label = (
377
+ < Box
378
+ sx = { {
379
+ display : "flex" ,
380
+ alignItems : "center" ,
381
+ gap : 5 ,
382
+ "& .min-icon" : {
383
+ height : 20 ,
384
+ width : 20 ,
385
+ } ,
386
+ "& span" : {
387
+ height : 20 ,
388
+ display : "flex" ,
389
+ alignItems : "center" ,
390
+ } ,
391
+ } }
392
+ >
393
+ < span > { value . label } </ span >
394
+ < Tooltip
395
+ tooltip = { `This value is set from the ${ overrideFields [ key ] } environment variable` }
396
+ placement = { "right" }
397
+ >
398
+ < span className = { "muted" } >
399
+ < ConsoleIcon />
400
+ </ span >
401
+ </ Tooltip >
402
+ </ Box >
403
+ ) ;
404
+
405
+ val = (
406
+ < i >
407
+ < span className = { "muted" } > { val } </ span >
408
+ </ i >
409
+ ) ;
410
+ }
411
+ return < ValuePair key = { key } label = { label } value = { val } /> ;
412
+ }
413
+ return null ;
414
+ } ) }
321
415
</ Box >
322
416
) ;
323
417
} ;
@@ -351,32 +445,58 @@ const IDPConfigurationDetails = ({
351
445
actions = {
352
446
< Fragment >
353
447
{ configurationName !== "_" && (
354
- < Button
355
- id = { "delete-idp-config" }
356
- onClick = { ( ) => {
357
- setDeleteOpen ( true ) ;
358
- } }
359
- label = { "Delete Configuration" }
360
- icon = { < TrashIcon /> }
361
- variant = { "secondary" }
362
- />
448
+ < Tooltip
449
+ tooltip = {
450
+ envOverride
451
+ ? "This configuration cannot be deleted using this module as this was set using OpenID environment variables."
452
+ : ""
453
+ }
454
+ >
455
+ < Button
456
+ id = { "delete-idp-config" }
457
+ onClick = { ( ) => {
458
+ setDeleteOpen ( true ) ;
459
+ } }
460
+ label = { "Delete Configuration" }
461
+ icon = { < TrashIcon /> }
462
+ variant = { "secondary" }
463
+ disabled = { envOverride }
464
+ />
465
+ </ Tooltip >
363
466
) }
364
467
{ ! editMode && (
468
+ < Tooltip
469
+ tooltip = {
470
+ envOverride
471
+ ? "Configuration cannot be edited in this module as OpenID environment variables are set for this MinIO instance."
472
+ : ""
473
+ }
474
+ >
475
+ < Button
476
+ id = { "edit" }
477
+ type = "button"
478
+ variant = { "callAction" }
479
+ icon = { < EditIcon /> }
480
+ onClick = { toggleEditMode }
481
+ label = { "Edit" }
482
+ disabled = { envOverride }
483
+ />
484
+ </ Tooltip >
485
+ ) }
486
+ < Tooltip
487
+ tooltip = {
488
+ envOverride
489
+ ? "Configuration cannot be disabled / enabled in this module as OpenID environment variables are set for this MinIO instance."
490
+ : ""
491
+ }
492
+ >
365
493
< Button
366
- id = { "edit" }
367
- type = "button"
368
- variant = { "callAction" }
369
- icon = { < EditIcon /> }
370
- onClick = { toggleEditMode }
371
- label = { "Edit" }
494
+ id = { "is-configuration-enabled" }
495
+ onClick = { ( ) => toggleConfiguration ( ! isEnabled ) }
496
+ label = { isEnabled ? "Disable" : "Enable" }
497
+ disabled = { loadingEnabledSave || envOverride }
372
498
/>
373
- ) }
374
- < Button
375
- id = { "is-configuration-enabled" }
376
- onClick = { ( ) => toggleConfiguration ( ! isEnabled ) }
377
- label = { isEnabled ? "Disable" : "Enable" }
378
- disabled = { loadingEnabledSave }
379
- />
499
+ </ Tooltip >
380
500
< Button
381
501
id = { "refresh-idp-config" }
382
502
onClick = { ( ) => setLoading ( true ) }
0 commit comments