@@ -84,6 +84,13 @@ const ConfigurationModal = ({
84
84
client,
85
85
registryLoading,
86
86
} : ConfigurationModalProps ) => {
87
+ // For some unknown reason, item.registered is not updated right away when the user toggles the switch.
88
+ // This `toggled` state is used to control the switch in the UI. Its main purpose is to do optimistic UI updates.
89
+ // When the user toggles the switch. The `useEffect` hook is used to synchronize the `toggled` state with the `item.registered`
90
+ // prop, which is the source of truth for the registration status of the item. This way, if the `item.registered` prop changes
91
+ // (e.g., due to a successful registration or unregistration), the switch will reflect the correct state.
92
+ const [ toggled , setToggled ] = useState ( catalogItem . registered ) ;
93
+
87
94
const [ localSecrets , setLocalSecrets ] = useState <
88
95
{ [ key : string ] : string | undefined } | undefined
89
96
> ( undefined ) ;
@@ -187,12 +194,13 @@ const ConfigurationModal = ({
187
194
< span >
188
195
< Switch
189
196
disabled = { ! catalogItem . canRegister }
190
- checked = { catalogItem . registered }
191
- onChange = { ( e ) =>
197
+ checked = { toggled }
198
+ onChange = { ( _event , checked ) => {
199
+ setToggled ( checked ) ;
192
200
catalogItem . registered
193
201
? unregisterCatalogItem ( catalogItem )
194
- : registerCatalogItem ( catalogItem )
195
- }
202
+ : registerCatalogItem ( catalogItem ) ;
203
+ } }
196
204
/>
197
205
</ span >
198
206
</ Tooltip >
@@ -247,7 +255,13 @@ const ConfigurationModal = ({
247
255
< >
248
256
< Box sx = { { borderBottom : 1 , borderColor : 'divider' , mt : 2 } } >
249
257
< Tabs value = { tabValue } onChange = { handleTabChange } >
250
- < Tab label = { `Tools (${ catalogItem ?. tools ?. length } )` } />
258
+ < Tab
259
+ label = {
260
+ < Typography sx = { [ tabValue === 0 && { fontWeight : 'bold' } ] } >
261
+ { `Tools (${ catalogItem ?. tools ?. length } )` }
262
+ </ Typography >
263
+ }
264
+ />
251
265
{ ! contributesNoConfigOrSecrets && (
252
266
< Tab
253
267
disabled = { contributesNoConfigOrSecrets }
@@ -424,41 +438,41 @@ const ConfigurationModal = ({
424
438
< EditOutlinedIcon fontSize = "small" />
425
439
</ IconButton >
426
440
) }
427
- { secretEdited && (
428
- < Stack direction = "row" spacing = { 1 } >
429
- < IconButton
430
- size = "small"
431
- onClick = { async ( ) => {
432
- await mutateSecret . mutateAsync ( {
433
- name : secret . name ,
434
- value : localSecrets [ secret . name ] ! ,
435
- policies : [ MCP_POLICY_NAME ] ,
436
- } ) ;
437
- } }
438
- >
439
- < CheckOutlined
440
- fontSize = "small"
441
- sx = { { color : 'success.main' } }
442
- />
443
- </ IconButton >
444
- < IconButton
445
- size = "small"
446
- onClick = { async ( ) => {
447
- setLocalSecrets ( {
448
- ... localSecrets ,
449
- [ secret . name ] : secret . assigned
450
- ? ASSIGNED_SECRET_PLACEHOLDER
451
- : '' ,
452
- } ) ;
453
- } }
454
- >
455
- < CloseOutlined
456
- fontSize = "small"
457
- sx = { { color : 'error.main' } }
458
- />
459
- </ IconButton >
460
- </ Stack >
461
- ) }
441
+ { secretEdited &&
442
+ localSecrets [ secret . name ] !== '' && (
443
+ < Stack direction = "row" spacing = { 1 } >
444
+ < IconButton
445
+ size = "small"
446
+ onClick = { async ( ) => {
447
+ await mutateSecret . mutateAsync ( {
448
+ name : secret . name ,
449
+ value : localSecrets [ secret . name ] ! ,
450
+ policies : [ MCP_POLICY_NAME ] ,
451
+ } ) ;
452
+ } }
453
+ >
454
+ < CheckOutlined
455
+ fontSize = "small"
456
+ sx = { { color : 'success.main' } }
457
+ / >
458
+ </ IconButton >
459
+ < IconButton
460
+ size = "small"
461
+ onClick = { async ( ) => {
462
+ inputRefs . current [ index ] . focus ( ) ;
463
+ setLocalSecrets ( {
464
+ ... localSecrets ,
465
+ [ secret . name ] : '' ,
466
+ } ) ;
467
+ } }
468
+ >
469
+ < CloseOutlined
470
+ fontSize = "small"
471
+ sx = { { color : 'error.main' } }
472
+ />
473
+ </ IconButton >
474
+ </ Stack >
475
+ ) }
462
476
</ Stack >
463
477
) ;
464
478
} ) }
0 commit comments