1
- import { v1 } from " @docker/extension-api-client-types" ;
2
- import { useMutation , useQuery , useQueryClient } from " @tanstack/react-query" ;
3
- import { useCallback , useEffect , useMemo , useState } from " react" ;
4
- import { parse , stringify } from " yaml" ;
5
- import { CATALOG_URL , REGISTRY_YAML } from " ../Constants" ;
6
- import { writeToPromptsVolume } from " ../utils/Files" ;
7
- import { getRegistry , syncRegistryWithConfig } from " ../Registry" ;
8
- import Secrets from " ../Secrets" ;
9
- import { CatalogItemRichened , CatalogItemWithName } from " ../types/catalog" ;
10
- import { getTemplateForItem , useConfig } from " ./useConfig" ;
11
- import { useSecrets } from " ./useSecrets" ;
1
+ import { v1 } from ' @docker/extension-api-client-types' ;
2
+ import { useMutation , useQuery , useQueryClient } from ' @tanstack/react-query' ;
3
+ import { useCallback , useEffect , useMemo , useState } from ' react' ;
4
+ import { parse , stringify } from ' yaml' ;
5
+ import { CATALOG_URL , REGISTRY_YAML } from ' ../Constants' ;
6
+ import { getRegistry , syncRegistryWithConfig } from ' ../Registry' ;
7
+ import Secrets from ' ../Secrets' ;
8
+ import { CatalogItemRichened , CatalogItemWithName } from ' ../types/catalog' ;
9
+ import { writeToPromptsVolume } from ' ../utils/Files' ;
10
+ import { getTemplateForItem , useConfig } from ' ./useConfig' ;
11
+ import { useSecrets } from ' ./useSecrets' ;
12
12
13
13
const STORAGE_KEYS = {
14
- catalog : " docker-catalog-catalog" ,
15
- registry : " docker-catalog-registry" ,
14
+ catalog : ' docker-catalog-catalog' ,
15
+ registry : ' docker-catalog-registry' ,
16
16
} ;
17
17
18
18
function useCatalog ( client : v1 . DockerDesktopClient ) {
@@ -25,11 +25,11 @@ function useCatalog(client: v1.DockerDesktopClient) {
25
25
( item : CatalogItemWithName ) : CatalogItemRichened => {
26
26
const secretsWithAssignment = Secrets . getSecretsWithAssignment (
27
27
item ,
28
- secrets || [ ]
28
+ secrets || [ ] ,
29
29
) ;
30
30
const itemConfigValue = config ?. [ item . name ] || { } ;
31
31
const neverOnceConfigured = Boolean (
32
- item . config && Object . keys ( itemConfigValue ) . length === 0
32
+ item . config && Object . keys ( itemConfigValue ) . length === 0 ,
33
33
) ;
34
34
const configTemplate = getTemplateForItem ( item , itemConfigValue ) ;
35
35
const baseConfigTemplate = getTemplateForItem ( item , { } ) ;
@@ -40,7 +40,7 @@ function useCatalog(client: v1.DockerDesktopClient) {
40
40
JSON . stringify ( baseConfigTemplate ) ) ;
41
41
42
42
const missingASecret = secretsWithAssignment . some (
43
- ( secret ) => ! secret . assigned
43
+ ( secret ) => ! secret . assigned ,
44
44
) ;
45
45
const enrichedItem : CatalogItemRichened = {
46
46
...item ,
@@ -56,21 +56,18 @@ function useCatalog(client: v1.DockerDesktopClient) {
56
56
} ;
57
57
return enrichedItem ;
58
58
} ,
59
- [ secrets , config , registryItems ]
59
+ [ secrets , config , registryItems ] ,
60
60
) ;
61
61
62
- const {
63
- data : catalogItems = [ ] ,
64
- isLoading : catalogLoading ,
65
- refetch : refetchCatalog ,
66
- } = useQuery ( {
67
- queryKey : [ "catalog" ] ,
62
+ const { data : catalogItems = [ ] , isLoading : catalogLoading } = useQuery ( {
63
+ queryKey : [ 'catalog' ] ,
68
64
queryFn : async ( ) => {
65
+ console . log ( 'Fetching catalog items' ) ;
69
66
const response = await fetch (
70
- localStorage . getItem ( " catalogUrl" ) || CATALOG_URL
67
+ localStorage . getItem ( ' catalogUrl' ) || CATALOG_URL ,
71
68
) ;
72
69
const catalog = await response . text ( ) ;
73
- const items = parse ( catalog ) [ " registry" ] as { [ key : string ] : any } ;
70
+ const items = parse ( catalog ) [ ' registry' ] as { [ key : string ] : any } ;
74
71
const enrichedItems = Object . entries ( items ) . map ( ( [ name , item ] ) => ( {
75
72
name,
76
73
...item ,
@@ -93,7 +90,7 @@ function useCatalog(client: v1.DockerDesktopClient) {
93
90
// Use deep comparison for determining if updates are needed
94
91
if ( JSON . stringify ( enrichedItems ) !== JSON . stringify ( catalogItems ) ) {
95
92
// Use a stable reference for query data updates
96
- queryClient . setQueryData ( [ " catalog" ] , [ ...enrichedItems ] ) ;
93
+ queryClient . setQueryData ( [ ' catalog' ] , [ ...enrichedItems ] ) ;
97
94
}
98
95
}
99
96
} , [
@@ -107,12 +104,12 @@ function useCatalog(client: v1.DockerDesktopClient) {
107
104
108
105
// Persist catalog to localStorage when it changes (for fallback only)
109
106
useQuery ( {
110
- queryKey : [ " catalog" , " persist" , catalogItems ] ,
107
+ queryKey : [ ' catalog' , ' persist' , catalogItems ] ,
111
108
queryFn : async ( ) => {
112
109
if ( catalogItems && catalogItems . length > 0 ) {
113
110
localStorage . setItem (
114
111
STORAGE_KEYS . catalog ,
115
- JSON . stringify ( catalogItems )
112
+ JSON . stringify ( catalogItems ) ,
116
113
) ;
117
114
}
118
115
return null ;
@@ -121,17 +118,9 @@ function useCatalog(client: v1.DockerDesktopClient) {
121
118
gcTime : 0 ,
122
119
} ) ;
123
120
124
- const tryLoadCatalog = async ( ) => {
125
- return await refetchCatalog ( {
126
- cancelRefetch : false ,
127
- } ) ;
128
- } ;
129
-
130
121
return {
131
122
catalogItems,
132
123
catalogLoading,
133
- tryLoadCatalog,
134
- refetchCatalog,
135
124
} ;
136
125
}
137
126
@@ -145,8 +134,8 @@ function useRegistry(client: v1.DockerDesktopClient) {
145
134
refetch : refetchRegistry ,
146
135
isLoading : registryLoading ,
147
136
} = useQuery ( {
148
- queryKey : [ " registry" ] ,
149
- networkMode : " always" ,
137
+ queryKey : [ ' registry' ] ,
138
+ networkMode : ' always' ,
150
139
queryFn : async ( ) => {
151
140
setCanRegister ( false ) ;
152
141
try {
@@ -156,11 +145,11 @@ function useRegistry(client: v1.DockerDesktopClient) {
156
145
} catch ( error ) {
157
146
if ( error instanceof Error ) {
158
147
client . desktopUI . toast . error (
159
- " Failed to get prompt registry: " + error . message
148
+ ' Failed to get prompt registry: ' + error . message ,
160
149
) ;
161
150
} else {
162
151
client . desktopUI . toast . error (
163
- " Failed to get prompt registry: " + JSON . stringify ( error )
152
+ ' Failed to get prompt registry: ' + JSON . stringify ( error ) ,
164
153
) ;
165
154
}
166
155
setCanRegister ( true ) ;
@@ -170,15 +159,15 @@ function useRegistry(client: v1.DockerDesktopClient) {
170
159
} ) ;
171
160
172
161
useQuery ( {
173
- queryKey : [ " registry" , " init" ] ,
162
+ queryKey : [ ' registry' , ' init' ] ,
174
163
queryFn : async ( ) => {
175
164
const cachedRegistry = localStorage . getItem ( STORAGE_KEYS . registry ) ;
176
165
if ( cachedRegistry && queryClient && ! registryItems ) {
177
166
try {
178
167
const parsedRegistry = JSON . parse ( cachedRegistry ) ;
179
- queryClient . setQueryData ( [ " registry" ] , parsedRegistry ) ;
168
+ queryClient . setQueryData ( [ ' registry' ] , parsedRegistry ) ;
180
169
} catch ( e ) {
181
- console . error ( " Failed to parse cached registry:" , e ) ;
170
+ console . error ( ' Failed to parse cached registry:' , e ) ;
182
171
}
183
172
}
184
173
return null ;
@@ -189,11 +178,11 @@ function useRegistry(client: v1.DockerDesktopClient) {
189
178
190
179
const registryItemsString = useMemo (
191
180
( ) => ( registryItems ? JSON . stringify ( registryItems ) : null ) ,
192
- [ registryItems ]
181
+ [ registryItems ] ,
193
182
) ;
194
183
195
184
useQuery ( {
196
- queryKey : [ " registry" , " persist" ] ,
185
+ queryKey : [ ' registry' , ' persist' ] ,
197
186
queryFn : async ( ) => {
198
187
if ( registryItemsString ) {
199
188
localStorage . setItem ( STORAGE_KEYS . registry , registryItemsString ) ;
@@ -212,7 +201,7 @@ function useRegistry(client: v1.DockerDesktopClient) {
212
201
await writeToPromptsVolume (
213
202
client ,
214
203
REGISTRY_YAML ,
215
- stringify ( { registry : newRegistry } )
204
+ stringify ( { registry : newRegistry } ) ,
216
205
) ;
217
206
218
207
return newRegistry ;
@@ -254,12 +243,12 @@ export function useCatalogOperations(client: v1.DockerDesktopClient) {
254
243
await writeToPromptsVolume (
255
244
client ,
256
245
REGISTRY_YAML ,
257
- stringify ( { registry : newRegistry } )
246
+ stringify ( { registry : newRegistry } ) ,
258
247
) ;
259
248
return { success : true , newRegistry } ;
260
249
} catch ( error ) {
261
250
client . desktopUI . toast . error (
262
- " Failed to register catalog item: " + error
251
+ ' Failed to register catalog item: ' + error ,
263
252
) ;
264
253
// Treat YAML file write failures as fatal, no rollback
265
254
throw error ;
@@ -268,7 +257,7 @@ export function useCatalogOperations(client: v1.DockerDesktopClient) {
268
257
// Only need one update of registry data, not both onMutate and onSuccess
269
258
onSuccess : async ( data ) => {
270
259
// Update the registry data after successful registration
271
- queryClient . setQueryData ( [ " registry" ] , data . newRegistry ) ;
260
+ queryClient . setQueryData ( [ ' registry' ] , data . newRegistry ) ;
272
261
} ,
273
262
} ) ;
274
263
@@ -287,13 +276,13 @@ export function useCatalogOperations(client: v1.DockerDesktopClient) {
287
276
await writeToPromptsVolume (
288
277
client ,
289
278
REGISTRY_YAML ,
290
- stringify ( { registry : currentRegistry } )
279
+ stringify ( { registry : currentRegistry } ) ,
291
280
) ;
292
281
293
282
return { success : true , newRegistry : currentRegistry } ;
294
283
} catch ( error ) {
295
284
client . desktopUI . toast . error (
296
- " Failed to unregister catalog item: " + error
285
+ ' Failed to unregister catalog item: ' + error ,
297
286
) ;
298
287
// Treat YAML file write failures as fatal, no rollback
299
288
throw error ;
@@ -302,7 +291,7 @@ export function useCatalogOperations(client: v1.DockerDesktopClient) {
302
291
// Only need one update of registry data, not both onMutate and onSuccess
303
292
onSuccess : async ( data ) => {
304
293
// Update the registry data after successful unregistration
305
- queryClient . setQueryData ( [ " registry" ] , data . newRegistry ) ;
294
+ queryClient . setQueryData ( [ ' registry' ] , data . newRegistry ) ;
306
295
} ,
307
296
} ) ;
308
297
@@ -316,7 +305,7 @@ export function useCatalogOperations(client: v1.DockerDesktopClient) {
316
305
317
306
// This hook represents the catalog query. The registry is not part of the UI and does not need to be exported.
318
307
export function useCatalogAll ( client : v1 . DockerDesktopClient ) {
319
- const { catalogItems, catalogLoading, tryLoadCatalog } = useCatalog ( client ) ;
308
+ const { catalogItems, catalogLoading } = useCatalog ( client ) ;
320
309
const {
321
310
registryItems,
322
311
registryLoading,
@@ -336,7 +325,6 @@ export function useCatalogAll(client: v1.DockerDesktopClient) {
336
325
registryLoading,
337
326
338
327
// Actions
339
- tryLoadCatalog,
340
328
tryLoadRegistry,
341
329
registerCatalogItem,
342
330
unregisterCatalogItem,
0 commit comments