@@ -2,7 +2,7 @@ import { v1 } from '@docker/extension-api-client-types';
2
2
import CheckOutlined from '@mui/icons-material/CheckOutlined' ;
3
3
import Close from '@mui/icons-material/Close' ;
4
4
import CloseOutlined from '@mui/icons-material/CloseOutlined' ;
5
- import DeleteOutlined from '@mui/icons-material/DeleteOutlined ' ;
5
+ import EditOutlinedIcon from '@mui/icons-material/EditOutlined ' ;
6
6
import Launch from '@mui/icons-material/Launch' ;
7
7
import {
8
8
Alert ,
@@ -17,7 +17,6 @@ import {
17
17
DialogTitle ,
18
18
IconButton ,
19
19
Link ,
20
- OutlinedInput ,
21
20
Paper ,
22
21
Stack ,
23
22
Switch ,
@@ -34,16 +33,20 @@ import {
34
33
Typography ,
35
34
useTheme ,
36
35
} from '@mui/material' ;
37
- import { useEffect , useState } from 'react' ;
36
+ import { useEffect , useRef , useState } from 'react' ;
38
37
39
- import { ASSIGNED_SECRET_PLACEHOLDER , getUnsupportedSecretMessage , MCP_POLICY_NAME } from '../../Constants' ;
38
+ import {
39
+ ASSIGNED_SECRET_PLACEHOLDER ,
40
+ getUnsupportedSecretMessage ,
41
+ MCP_POLICY_NAME ,
42
+ } from '../../Constants' ;
43
+ import { formatName } from '../../formatName' ;
40
44
import { useCatalogOperations } from '../../queries/useCatalog' ;
41
45
import { useConfig } from '../../queries/useConfig' ;
46
+ import useDDInfo from '../../queries/useDDInfo' ;
42
47
import { useSecrets } from '../../queries/useSecrets' ;
43
48
import { CatalogItemRichened } from '../../types/catalog' ;
44
49
import ConfigEditor from './ConfigEditor' ;
45
- import { formatName } from '../../formatName' ;
46
- import useDDInfo from '../../queries/useDDInfo' ;
47
50
48
51
interface TabPanelProps {
49
52
children ?: React . ReactNode ;
@@ -86,6 +89,9 @@ const ConfigurationModal = ({
86
89
const [ localSecrets , setLocalSecrets ] = useState <
87
90
{ [ key : string ] : string | undefined } | undefined
88
91
> ( undefined ) ;
92
+
93
+ const inputRefs = useRef < HTMLInputElement [ ] > ( [ ] ) ;
94
+
89
95
const theme = useTheme ( ) ;
90
96
91
97
const { isLoading : secretsLoading , mutate : mutateSecret } =
@@ -293,7 +299,13 @@ const ConfigurationModal = ({
293
299
</ TableCell >
294
300
< TableCell >
295
301
< Link
296
- onClick = { ( ) => client . host . openExternal ( `${ catalogItem . readme } #tool-${ tool . name . replaceAll ( ' ' , '-' ) } ` || '' ) }
302
+ onClick = { ( ) =>
303
+ client . host . openExternal (
304
+ `${
305
+ catalogItem . readme
306
+ } #tool-${ tool . name . replaceAll ( ' ' , '-' ) } ` || ''
307
+ )
308
+ }
297
309
href = "#"
298
310
target = "_blank"
299
311
>
@@ -317,7 +329,7 @@ const ConfigurationModal = ({
317
329
minHeight : '180px' ,
318
330
} }
319
331
>
320
- < Stack direction = "column" spacing = { 2 } >
332
+ < Stack direction = "column" spacing = { 2 } >
321
333
< ConfigEditor catalogItem = { catalogItem } client = { client } />
322
334
< Stack >
323
335
< Typography variant = "subtitle2" > Secrets</ Typography >
@@ -332,24 +344,30 @@ const ConfigurationModal = ({
332
344
</ Alert >
333
345
) }
334
346
{ ddInfo ?. hasSecretSupport &&
335
- catalogItem . secrets &&
336
- catalogItem . secrets ?. length > 0 ? (
337
- catalogItem . secrets . map ( ( secret ) => {
347
+ catalogItem . secrets &&
348
+ catalogItem . secrets ?. length > 0 ? (
349
+ catalogItem . secrets . map ( ( secret , index ) => {
338
350
const secretEdited =
339
351
( secret . assigned &&
340
352
localSecrets [ secret . name ] !==
341
- ASSIGNED_SECRET_PLACEHOLDER ) ||
353
+ ASSIGNED_SECRET_PLACEHOLDER ) ||
342
354
( ! secret . assigned &&
343
355
localSecrets [ secret . name ] !== '' ) ;
344
356
return (
345
357
< Stack
346
358
key = { secret . name }
347
359
direction = "row"
348
360
spacing = { 2 }
349
- alignItems = "center"
361
+ sx = { {
362
+ alignItems : 'center' ,
363
+ } }
350
364
>
351
365
< TextField
352
366
size = "small"
367
+ inputRef = { ( element ) =>
368
+ ( inputRefs . current [ index ] = element )
369
+ }
370
+ disabled = { secret . assigned }
353
371
key = { secret . name }
354
372
label = { secret . name }
355
373
value = { localSecrets [ secret . name ] }
@@ -365,21 +383,28 @@ const ConfigurationModal = ({
365
383
{ secret . assigned && ! secretEdited && (
366
384
< IconButton
367
385
size = "small"
368
- color = "error"
369
386
onClick = { ( ) => {
387
+ setLocalSecrets ( {
388
+ ...localSecrets ,
389
+ [ secret . name ] : '' ,
390
+ } ) ;
391
+ // We need to enable the input to be able to focus on it
392
+ inputRefs . current [ index ] . disabled = false ;
393
+ inputRefs . current [ index ] . focus ( ) ;
370
394
mutateSecret . mutateAsync ( {
371
395
name : secret . name ,
372
396
value : undefined ,
373
397
policies : [ MCP_POLICY_NAME ] ,
374
398
} ) ;
375
399
} }
376
400
>
377
- < DeleteOutlined />
401
+ < EditOutlinedIcon fontSize = "small" />
378
402
</ IconButton >
379
403
) }
380
404
{ secretEdited && (
381
- < ButtonGroup >
405
+ < Stack direction = "row" spacing = { 1 } >
382
406
< IconButton
407
+ size = "small"
383
408
onClick = { async ( ) => {
384
409
await mutateSecret . mutateAsync ( {
385
410
name : secret . name ,
@@ -389,10 +414,12 @@ const ConfigurationModal = ({
389
414
} }
390
415
>
391
416
< CheckOutlined
417
+ fontSize = "small"
392
418
sx = { { color : 'success.main' } }
393
419
/>
394
420
</ IconButton >
395
421
< IconButton
422
+ size = "small"
396
423
onClick = { async ( ) => {
397
424
setLocalSecrets ( {
398
425
...localSecrets ,
@@ -402,9 +429,12 @@ const ConfigurationModal = ({
402
429
} ) ;
403
430
} }
404
431
>
405
- < CloseOutlined sx = { { color : 'error.main' } } />
432
+ < CloseOutlined
433
+ fontSize = "small"
434
+ sx = { { color : 'error.main' } }
435
+ />
406
436
</ IconButton >
407
- </ ButtonGroup >
437
+ </ Stack >
408
438
) }
409
439
</ Stack >
410
440
) ;
@@ -417,10 +447,9 @@ const ConfigurationModal = ({
417
447
</ Stack >
418
448
</ TabPanel >
419
449
</ >
420
- )
421
- }
422
- </ DialogContent >
423
- </ Dialog >
450
+ ) }
451
+ </ DialogContent >
452
+ </ Dialog >
424
453
) ;
425
454
} ;
426
455
0 commit comments