@@ -84,6 +84,13 @@ const ConfigurationModal = ({
8484 client,
8585 registryLoading,
8686} : 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+
8794 const [ localSecrets , setLocalSecrets ] = useState <
8895 { [ key : string ] : string | undefined } | undefined
8996 > ( undefined ) ;
@@ -187,12 +194,13 @@ const ConfigurationModal = ({
187194 < span >
188195 < Switch
189196 disabled = { ! catalogItem . canRegister }
190- checked = { catalogItem . registered }
191- onChange = { ( e ) =>
197+ checked = { toggled }
198+ onChange = { ( _event , checked ) => {
199+ setToggled ( checked ) ;
192200 catalogItem . registered
193201 ? unregisterCatalogItem ( catalogItem )
194- : registerCatalogItem ( catalogItem )
195- }
202+ : registerCatalogItem ( catalogItem ) ;
203+ } }
196204 />
197205 </ span >
198206 </ Tooltip >
@@ -247,7 +255,13 @@ const ConfigurationModal = ({
247255 < >
248256 < Box sx = { { borderBottom : 1 , borderColor : 'divider' , mt : 2 } } >
249257 < 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+ />
251265 { ! contributesNoConfigOrSecrets && (
252266 < Tab
253267 disabled = { contributesNoConfigOrSecrets }
@@ -424,41 +438,41 @@ const ConfigurationModal = ({
424438 < EditOutlinedIcon fontSize = "small" />
425439 </ IconButton >
426440 ) }
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+ ) }
462476 </ Stack >
463477 ) ;
464478 } ) }
0 commit comments