@@ -9,7 +9,6 @@ import { getTemplateForItem } from './useConfig';
99import { useState , useEffect } from 'react' ;
1010import { escapeJSONForPlatformShell , tryRunImageSync } from '../FileUtils' ;
1111import { useConfig } from './useConfig' ;
12- import { useRequiredImages } from './useRequiredImages' ;
1312import { useSecrets } from "./useSecrets" ;
1413
1514// Storage keys for each query type
@@ -25,7 +24,7 @@ interface QueryContextWithMeta {
2524 } ;
2625}
2726
28- export function useCatalog ( client : v1 . DockerDesktopClient ) {
27+ function useCatalog ( client : v1 . DockerDesktopClient ) {
2928 const queryClient = useQueryClient ( ) ;
3029 const { data : secrets , isLoading : secretsLoading } = useSecrets ( client ) ;
3130 const { registryItems, registryLoading } = useRegistry ( client ) ;
@@ -38,9 +37,7 @@ export function useCatalog(client: v1.DockerDesktopClient) {
3837 const configTemplate = getTemplateForItem ( item , itemConfigValue ) ;
3938 const baseConfigTemplate = getTemplateForItem ( item , { } ) ;
4039 const unConfigured = Boolean ( item . config ) && ( neverOnceConfigured || JSON . stringify ( itemConfigValue ) === JSON . stringify ( baseConfigTemplate ) ) ;
41- if ( item . name === 'elevenlabs' ) {
42- console . log ( 'elevenlabs' , itemConfigValue , configTemplate , unConfigured )
43- }
40+
4441 const missingASecret = secretsWithAssignment . some ( ( secret ) => ! secret . assigned ) ;
4542 const enrichedItem : CatalogItemRichened = {
4643 ...item ,
@@ -80,10 +77,7 @@ export function useCatalog(client: v1.DockerDesktopClient) {
8077 // without causing a full catalog reload
8178 useEffect ( ( ) => {
8279 if ( catalogItems . length > 0 && ! secretsLoading && ! configLoading && ! registryLoading ) {
83- const enrichedItems = catalogItems . map ( item => ( {
84- ...item ,
85- ...enrichCatalogItem ( item )
86- } ) ) ;
80+ const enrichedItems = catalogItems . map ( enrichCatalogItem ) ;
8781
8882 // Use the same reference if nothing changed to prevent unnecessary re-renders
8983 const hasChanges = JSON . stringify ( enrichedItems ) !== JSON . stringify ( catalogItems ) ;
@@ -123,7 +117,7 @@ export function useCatalog(client: v1.DockerDesktopClient) {
123117 } ;
124118}
125119
126- export function useRegistry ( client : v1 . DockerDesktopClient ) {
120+ function useRegistry ( client : v1 . DockerDesktopClient ) {
127121 const queryClient = useQueryClient ( ) ;
128122 const [ canRegister , setCanRegister ] = useState < boolean > ( false ) ;
129123
@@ -210,9 +204,8 @@ export function useRegistry(client: v1.DockerDesktopClient) {
210204
211205export function useCatalogOperations ( client : v1 . DockerDesktopClient ) {
212206 const queryClient = useQueryClient ( ) ;
213- const { registryItems, canRegister } = useRegistry ( client ) ;
214- const { config, syncConfigWithRegistry } = useConfig ( client ) ;
215- const { loadAllImages } = useRequiredImages ( client ) ;
207+ const { registryItems } = useRegistry ( client ) ;
208+ const { config } = useConfig ( client ) ;
216209
217210 // Register catalog item mutation
218211 const registerItemMutation = useMutation ( {
@@ -231,32 +224,6 @@ export function useCatalogOperations(client: v1.DockerDesktopClient) {
231224
232225 // If there's a JSON schema configuration, validate and generate default values
233226 if ( Array . isArray ( item . config ) && item . config . length > 0 ) {
234- const configSchema = item . config [ 0 ] ;
235-
236- // Check if we have required fields from anyOf conditions
237- if ( configSchema . anyOf ) {
238- configSchema . anyOf . forEach ( ( condition : any ) => {
239- if ( condition . required ) {
240- condition . required . forEach ( ( field : string ) => {
241- if ( ! ( field in itemConfig ) ) {
242- // Generate a default value if possible
243- itemConfig [ field ] = "" ;
244- }
245- } ) ;
246- }
247- } ) ;
248- }
249-
250- // Handle normal required fields
251- if ( configSchema . required ) {
252- configSchema . required . forEach ( ( field : string ) => {
253- if ( ! ( field in itemConfig ) ) {
254- // Generate a default value if possible
255- itemConfig [ field ] = "" ;
256- }
257- } ) ;
258- }
259-
260227 // Use JSON schema template for any remaining defaults
261228 const template = getTemplateForItem ( item , itemConfig ) ;
262229 itemConfig = { ...template , ...itemConfig } ;
@@ -273,18 +240,34 @@ export function useCatalogOperations(client: v1.DockerDesktopClient) {
273240
274241 await tryRunImageSync ( client , [ '--rm' , '-v' , 'docker-prompts:/docker-prompts' , '--workdir' , '/docker-prompts' , 'vonwig/function_write_files:latest' , 'registry.yaml' , payload ] ) ;
275242
276- await syncConfigWithRegistry ( newRegistry ) ;
277- await loadAllImages ( ) ;
278-
279243 if ( showNotification ) {
280244 client . desktopUI . toast . success ( `${ item . name } registered successfully.` ) ;
281245 }
282246 return { success : true , newRegistry } ;
283247 } catch ( error ) {
284248 client . desktopUI . toast . error ( 'Failed to register catalog item: ' + error ) ;
249+ // Treat YAML file write failures as fatal, no rollback
285250 throw error ;
286251 }
287252 } ,
253+ onMutate : async ( { item } ) => {
254+ // Optimistically update the registry data
255+ const currentRegistry = queryClient . getQueryData ( [ 'registry' ] ) as { [ key : string ] : { ref : string ; config ?: any } } || { } ;
256+ const newRegistry : { [ key : string ] : { ref : string ; config ?: any } } = {
257+ ...currentRegistry ,
258+ [ item . name ] : { ref : item . ref }
259+ } ;
260+
261+ // If there's config, add it
262+ if ( item . config && config && config [ item . name ] ) {
263+ newRegistry [ item . name ] = {
264+ ...newRegistry [ item . name ] ,
265+ config : config [ item . name ]
266+ } ;
267+ }
268+
269+ queryClient . setQueryData ( [ 'registry' ] , newRegistry ) ;
270+ } ,
288271 onSuccess : async ( data ) => {
289272 // Update the registry data after successful registration
290273 queryClient . setQueryData ( [ 'registry' ] , data . newRegistry ) ;
@@ -310,15 +293,25 @@ export function useCatalogOperations(client: v1.DockerDesktopClient) {
310293
311294 await tryRunImageSync ( client , [ '--rm' , '-v' , 'docker-prompts:/docker-prompts' , '--workdir' , '/docker-prompts' , 'vonwig/function_write_files:latest' , 'registry.yaml' , payload ] ) ;
312295
313- // Explicitly sync the registry with config
314- await syncConfigWithRegistry ( currentRegistry ) ;
315296 client . desktopUI . toast . success ( `${ item . name } unregistered successfully.` ) ;
316297 return { success : true , newRegistry : currentRegistry } ;
317298 } catch ( error ) {
318299 client . desktopUI . toast . error ( 'Failed to unregister catalog item: ' + error ) ;
300+ // Treat YAML file write failures as fatal, no rollback
319301 throw error ;
320302 }
321303 } ,
304+ onMutate : async ( item ) => {
305+ // Optimistically update the registry data
306+ const currentRegistry = { ...( queryClient . getQueryData ( [ 'registry' ] ) as { [ key : string ] : { ref : string ; config ?: any } } || { } ) } ;
307+
308+ // Remove the item
309+ if ( currentRegistry [ item . name ] ) {
310+ delete currentRegistry [ item . name ] ;
311+ }
312+
313+ queryClient . setQueryData ( [ 'registry' ] , currentRegistry ) ;
314+ } ,
322315 onSuccess : async ( data ) => {
323316 // Update the registry data after successful unregistration
324317 queryClient . setQueryData ( [ 'registry' ] , data . newRegistry ) ;
0 commit comments