1
- import { v1 } from " @docker/extension-api-client-types" ;
1
+ import { v1 } from ' @docker/extension-api-client-types' ;
2
2
import {
3
3
CatalogItem ,
4
4
CatalogItemRichened ,
5
5
CatalogItemWithName ,
6
- } from " ../types/catalog" ;
7
- import { getRegistry , syncRegistryWithConfig } from " ../Registry" ;
8
- import Secrets from " ../Secrets" ;
9
- import { parse , stringify } from " yaml" ;
6
+ } from ' ../types/catalog' ;
7
+ import { getRegistry , syncRegistryWithConfig } from ' ../Registry' ;
8
+ import Secrets from ' ../Secrets' ;
9
+ import { parse , stringify } from ' yaml' ;
10
10
import {
11
11
CATALOG_URL ,
12
12
POLL_INTERVAL ,
13
13
UNASSIGNED_SECRET_PLACEHOLDER ,
14
- } from " ../Constants" ;
15
- import { useQuery , useMutation , useQueryClient } from " @tanstack/react-query" ;
16
- import { getTemplateForItem } from " ./useConfig" ;
17
- import { useState , useEffect , useCallback , useMemo } from " react" ;
18
- import { escapeJSONForPlatformShell , tryRunImageSync } from " ../FileUtils" ;
19
- import { useConfig } from " ./useConfig" ;
20
- import { useSecrets } from " ./useSecrets" ;
14
+ } from ' ../Constants' ;
15
+ import { useQuery , useMutation , useQueryClient } from ' @tanstack/react-query' ;
16
+ import { getTemplateForItem } from ' ./useConfig' ;
17
+ import { useState , useEffect , useCallback , useMemo } from ' react' ;
18
+ import { escapeJSONForPlatformShell , tryRunImageSync } from ' ../FileUtils' ;
19
+ import { useConfig } from ' ./useConfig' ;
20
+ import { useSecrets } from ' ./useSecrets' ;
21
21
22
22
const STORAGE_KEYS = {
23
- catalog : " docker-catalog-catalog" ,
24
- registry : " docker-catalog-registry" ,
23
+ catalog : ' docker-catalog-catalog' ,
24
+ registry : ' docker-catalog-registry' ,
25
25
} ;
26
26
27
27
function useCatalog ( client : v1 . DockerDesktopClient ) {
@@ -73,23 +73,20 @@ function useCatalog(client: v1.DockerDesktopClient) {
73
73
isLoading : catalogLoading ,
74
74
refetch : refetchCatalog ,
75
75
} = useQuery ( {
76
- queryKey : [ " catalog" ] ,
76
+ queryKey : [ ' catalog' ] ,
77
77
enabled : ! secretsLoading && ! registryLoading && ! configLoading ,
78
78
queryFn : async ( ) => {
79
79
const response = await fetch (
80
- localStorage . getItem ( " catalogUrl" ) || CATALOG_URL
80
+ localStorage . getItem ( ' catalogUrl' ) || CATALOG_URL
81
81
) ;
82
82
const catalog = await response . text ( ) ;
83
- const items = parse ( catalog ) [ " registry" ] as { [ key : string ] : any } ;
83
+ const items = parse ( catalog ) [ ' registry' ] as { [ key : string ] : any } ;
84
84
const enrichedItems = Object . entries ( items ) . map ( ( [ name , item ] ) => ( {
85
85
name,
86
86
...item ,
87
87
} ) ) as CatalogItemWithName [ ] ;
88
88
return enrichedItems . reverse ( ) . map ( enrichCatalogItem ) ;
89
89
} ,
90
- refetchInterval : POLL_INTERVAL ,
91
- staleTime : 60000 ,
92
- gcTime : 300000 ,
93
90
} ) ;
94
91
95
92
// This effect will re-enrich catalog items whenever secrets, config, or registry items change
@@ -106,7 +103,7 @@ function useCatalog(client: v1.DockerDesktopClient) {
106
103
// Use deep comparison for determining if updates are needed
107
104
if ( JSON . stringify ( enrichedItems ) !== JSON . stringify ( catalogItems ) ) {
108
105
// Use a stable reference for query data updates
109
- queryClient . setQueryData ( [ " catalog" ] , [ ...enrichedItems ] ) ;
106
+ queryClient . setQueryData ( [ ' catalog' ] , [ ...enrichedItems ] ) ;
110
107
}
111
108
}
112
109
} , [
@@ -120,7 +117,7 @@ function useCatalog(client: v1.DockerDesktopClient) {
120
117
121
118
// Persist catalog to localStorage when it changes (for fallback only)
122
119
useQuery ( {
123
- queryKey : [ " catalog" , " persist" , catalogItems ] ,
120
+ queryKey : [ ' catalog' , ' persist' , catalogItems ] ,
124
121
queryFn : async ( ) => {
125
122
if ( catalogItems && catalogItems . length > 0 ) {
126
123
localStorage . setItem (
@@ -158,7 +155,7 @@ function useRegistry(client: v1.DockerDesktopClient) {
158
155
refetch : refetchRegistry ,
159
156
isLoading : registryLoading ,
160
157
} = useQuery ( {
161
- queryKey : [ " registry" ] ,
158
+ queryKey : [ ' registry' ] ,
162
159
queryFn : async ( ) => {
163
160
setCanRegister ( false ) ;
164
161
try {
@@ -168,11 +165,11 @@ function useRegistry(client: v1.DockerDesktopClient) {
168
165
} catch ( error ) {
169
166
if ( error instanceof Error ) {
170
167
client . desktopUI . toast . error (
171
- " Failed to get prompt registry: " + error . message
168
+ ' Failed to get prompt registry: ' + error . message
172
169
) ;
173
170
} else {
174
171
client . desktopUI . toast . error (
175
- " Failed to get prompt registry: " + JSON . stringify ( error )
172
+ ' Failed to get prompt registry: ' + JSON . stringify ( error )
176
173
) ;
177
174
}
178
175
setCanRegister ( true ) ;
@@ -185,15 +182,15 @@ function useRegistry(client: v1.DockerDesktopClient) {
185
182
} ) ;
186
183
187
184
useQuery ( {
188
- queryKey : [ " registry" , " init" ] ,
185
+ queryKey : [ ' registry' , ' init' ] ,
189
186
queryFn : async ( ) => {
190
187
const cachedRegistry = localStorage . getItem ( STORAGE_KEYS . registry ) ;
191
188
if ( cachedRegistry && queryClient && ! registryItems ) {
192
189
try {
193
190
const parsedRegistry = JSON . parse ( cachedRegistry ) ;
194
- queryClient . setQueryData ( [ " registry" ] , parsedRegistry ) ;
191
+ queryClient . setQueryData ( [ ' registry' ] , parsedRegistry ) ;
195
192
} catch ( e ) {
196
- console . error ( " Failed to parse cached registry:" , e ) ;
193
+ console . error ( ' Failed to parse cached registry:' , e ) ;
197
194
}
198
195
}
199
196
return null ;
@@ -208,7 +205,7 @@ function useRegistry(client: v1.DockerDesktopClient) {
208
205
) ;
209
206
210
207
useQuery ( {
211
- queryKey : [ " registry" , " persist" ] ,
208
+ queryKey : [ ' registry' , ' persist' ] ,
212
209
queryFn : async ( ) => {
213
210
if ( registryItemsString ) {
214
211
localStorage . setItem ( STORAGE_KEYS . registry , registryItemsString ) ;
@@ -228,7 +225,7 @@ function useRegistry(client: v1.DockerDesktopClient) {
228
225
{
229
226
files : [
230
227
{
231
- path : " registry.yaml" ,
228
+ path : ' registry.yaml' ,
232
229
content : stringify ( { registry : newRegistry } ) ,
233
230
} ,
234
231
] ,
@@ -237,12 +234,12 @@ function useRegistry(client: v1.DockerDesktopClient) {
237
234
) ;
238
235
239
236
await tryRunImageSync ( client , [
240
- " --rm" ,
241
- "-v" ,
242
- " docker-prompts:/docker-prompts" ,
243
- " --workdir" ,
244
- " /docker-prompts" ,
245
- " vonwig/function_write_files:latest" ,
237
+ ' --rm' ,
238
+ '-v' ,
239
+ ' docker-prompts:/docker-prompts' ,
240
+ ' --workdir' ,
241
+ ' /docker-prompts' ,
242
+ ' vonwig/function_write_files:latest' ,
246
243
payload ,
247
244
] ) ;
248
245
@@ -292,7 +289,7 @@ export function useCatalogOperations(client: v1.DockerDesktopClient) {
292
289
{
293
290
files : [
294
291
{
295
- path : " registry.yaml" ,
292
+ path : ' registry.yaml' ,
296
293
content : stringify ( { registry : newRegistry } ) ,
297
294
} ,
298
295
] ,
@@ -301,12 +298,12 @@ export function useCatalogOperations(client: v1.DockerDesktopClient) {
301
298
) ;
302
299
303
300
await tryRunImageSync ( client , [
304
- " --rm" ,
305
- "-v" ,
306
- " docker-prompts:/docker-prompts" ,
307
- " --workdir" ,
308
- " /docker-prompts" ,
309
- " vonwig/function_write_files:latest" ,
301
+ ' --rm' ,
302
+ '-v' ,
303
+ ' docker-prompts:/docker-prompts' ,
304
+ ' --workdir' ,
305
+ ' /docker-prompts' ,
306
+ ' vonwig/function_write_files:latest' ,
310
307
payload ,
311
308
] ) ;
312
309
@@ -318,7 +315,7 @@ export function useCatalogOperations(client: v1.DockerDesktopClient) {
318
315
return { success : true , newRegistry } ;
319
316
} catch ( error ) {
320
317
client . desktopUI . toast . error (
321
- " Failed to register catalog item: " + error
318
+ ' Failed to register catalog item: ' + error
322
319
) ;
323
320
// Treat YAML file write failures as fatal, no rollback
324
321
throw error ;
@@ -327,10 +324,7 @@ export function useCatalogOperations(client: v1.DockerDesktopClient) {
327
324
// Only need one update of registry data, not both onMutate and onSuccess
328
325
onSuccess : async ( data ) => {
329
326
// Update the registry data after successful registration
330
- queryClient . setQueryData ( [ "registry" ] , data . newRegistry ) ;
331
-
332
- // Also invalidate catalog to refresh the registered state
333
- await queryClient . invalidateQueries ( { queryKey : [ "catalog" ] } ) ;
327
+ queryClient . setQueryData ( [ 'registry' ] , data . newRegistry ) ;
334
328
} ,
335
329
} ) ;
336
330
@@ -350,7 +344,7 @@ export function useCatalogOperations(client: v1.DockerDesktopClient) {
350
344
{
351
345
files : [
352
346
{
353
- path : " registry.yaml" ,
347
+ path : ' registry.yaml' ,
354
348
content : stringify ( { registry : currentRegistry } ) ,
355
349
} ,
356
350
] ,
@@ -359,12 +353,12 @@ export function useCatalogOperations(client: v1.DockerDesktopClient) {
359
353
) ;
360
354
361
355
await tryRunImageSync ( client , [
362
- " --rm" ,
363
- "-v" ,
364
- " docker-prompts:/docker-prompts" ,
365
- " --workdir" ,
366
- " /docker-prompts" ,
367
- " vonwig/function_write_files:latest" ,
356
+ ' --rm' ,
357
+ '-v' ,
358
+ ' docker-prompts:/docker-prompts' ,
359
+ ' --workdir' ,
360
+ ' /docker-prompts' ,
361
+ ' vonwig/function_write_files:latest' ,
368
362
payload ,
369
363
] ) ;
370
364
@@ -374,7 +368,7 @@ export function useCatalogOperations(client: v1.DockerDesktopClient) {
374
368
return { success : true , newRegistry : currentRegistry } ;
375
369
} catch ( error ) {
376
370
client . desktopUI . toast . error (
377
- " Failed to unregister catalog item: " + error
371
+ ' Failed to unregister catalog item: ' + error
378
372
) ;
379
373
// Treat YAML file write failures as fatal, no rollback
380
374
throw error ;
@@ -383,10 +377,7 @@ export function useCatalogOperations(client: v1.DockerDesktopClient) {
383
377
// Only need one update of registry data, not both onMutate and onSuccess
384
378
onSuccess : async ( data ) => {
385
379
// Update the registry data after successful unregistration
386
- queryClient . setQueryData ( [ "registry" ] , data . newRegistry ) ;
387
-
388
- // Also invalidate catalog to refresh the registered state
389
- await queryClient . invalidateQueries ( { queryKey : [ "catalog" ] } ) ;
380
+ queryClient . setQueryData ( [ 'registry' ] , data . newRegistry ) ;
390
381
} ,
391
382
} ) ;
392
383
0 commit comments