@@ -9,7 +9,6 @@ import { getTemplateForItem } from './useConfig';
9
9
import { useState , useEffect } from 'react' ;
10
10
import { escapeJSONForPlatformShell , tryRunImageSync } from '../FileUtils' ;
11
11
import { useConfig } from './useConfig' ;
12
- import { useRequiredImages } from './useRequiredImages' ;
13
12
import { useSecrets } from "./useSecrets" ;
14
13
15
14
// Storage keys for each query type
@@ -25,7 +24,7 @@ interface QueryContextWithMeta {
25
24
} ;
26
25
}
27
26
28
- export function useCatalog ( client : v1 . DockerDesktopClient ) {
27
+ function useCatalog ( client : v1 . DockerDesktopClient ) {
29
28
const queryClient = useQueryClient ( ) ;
30
29
const { data : secrets , isLoading : secretsLoading } = useSecrets ( client ) ;
31
30
const { registryItems, registryLoading } = useRegistry ( client ) ;
@@ -38,9 +37,7 @@ export function useCatalog(client: v1.DockerDesktopClient) {
38
37
const configTemplate = getTemplateForItem ( item , itemConfigValue ) ;
39
38
const baseConfigTemplate = getTemplateForItem ( item , { } ) ;
40
39
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
+
44
41
const missingASecret = secretsWithAssignment . some ( ( secret ) => ! secret . assigned ) ;
45
42
const enrichedItem : CatalogItemRichened = {
46
43
...item ,
@@ -80,10 +77,7 @@ export function useCatalog(client: v1.DockerDesktopClient) {
80
77
// without causing a full catalog reload
81
78
useEffect ( ( ) => {
82
79
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 ) ;
87
81
88
82
// Use the same reference if nothing changed to prevent unnecessary re-renders
89
83
const hasChanges = JSON . stringify ( enrichedItems ) !== JSON . stringify ( catalogItems ) ;
@@ -123,7 +117,7 @@ export function useCatalog(client: v1.DockerDesktopClient) {
123
117
} ;
124
118
}
125
119
126
- export function useRegistry ( client : v1 . DockerDesktopClient ) {
120
+ function useRegistry ( client : v1 . DockerDesktopClient ) {
127
121
const queryClient = useQueryClient ( ) ;
128
122
const [ canRegister , setCanRegister ] = useState < boolean > ( false ) ;
129
123
@@ -210,9 +204,8 @@ export function useRegistry(client: v1.DockerDesktopClient) {
210
204
211
205
export function useCatalogOperations ( client : v1 . DockerDesktopClient ) {
212
206
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 ) ;
216
209
217
210
// Register catalog item mutation
218
211
const registerItemMutation = useMutation ( {
@@ -231,32 +224,6 @@ export function useCatalogOperations(client: v1.DockerDesktopClient) {
231
224
232
225
// If there's a JSON schema configuration, validate and generate default values
233
226
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
-
260
227
// Use JSON schema template for any remaining defaults
261
228
const template = getTemplateForItem ( item , itemConfig ) ;
262
229
itemConfig = { ...template , ...itemConfig } ;
@@ -273,18 +240,34 @@ export function useCatalogOperations(client: v1.DockerDesktopClient) {
273
240
274
241
await tryRunImageSync ( client , [ '--rm' , '-v' , 'docker-prompts:/docker-prompts' , '--workdir' , '/docker-prompts' , 'vonwig/function_write_files:latest' , 'registry.yaml' , payload ] ) ;
275
242
276
- await syncConfigWithRegistry ( newRegistry ) ;
277
- await loadAllImages ( ) ;
278
-
279
243
if ( showNotification ) {
280
244
client . desktopUI . toast . success ( `${ item . name } registered successfully.` ) ;
281
245
}
282
246
return { success : true , newRegistry } ;
283
247
} catch ( error ) {
284
248
client . desktopUI . toast . error ( 'Failed to register catalog item: ' + error ) ;
249
+ // Treat YAML file write failures as fatal, no rollback
285
250
throw error ;
286
251
}
287
252
} ,
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
+ } ,
288
271
onSuccess : async ( data ) => {
289
272
// Update the registry data after successful registration
290
273
queryClient . setQueryData ( [ 'registry' ] , data . newRegistry ) ;
@@ -310,15 +293,25 @@ export function useCatalogOperations(client: v1.DockerDesktopClient) {
310
293
311
294
await tryRunImageSync ( client , [ '--rm' , '-v' , 'docker-prompts:/docker-prompts' , '--workdir' , '/docker-prompts' , 'vonwig/function_write_files:latest' , 'registry.yaml' , payload ] ) ;
312
295
313
- // Explicitly sync the registry with config
314
- await syncConfigWithRegistry ( currentRegistry ) ;
315
296
client . desktopUI . toast . success ( `${ item . name } unregistered successfully.` ) ;
316
297
return { success : true , newRegistry : currentRegistry } ;
317
298
} catch ( error ) {
318
299
client . desktopUI . toast . error ( 'Failed to unregister catalog item: ' + error ) ;
300
+ // Treat YAML file write failures as fatal, no rollback
319
301
throw error ;
320
302
}
321
303
} ,
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
+ } ,
322
315
onSuccess : async ( data ) => {
323
316
// Update the registry data after successful unregistration
324
317
queryClient . setQueryData ( [ 'registry' ] , data . newRegistry ) ;
0 commit comments