@@ -15,14 +15,10 @@ import {
1515 isYamlLibraryConfiguration ,
1616} from "@/components/shared/GitHubLibrary/types" ;
1717import {
18- fetchAndStoreComponentLibrary ,
18+ COMPONENT_LIBRARY_URL ,
1919 hydrateComponentReference ,
2020} from "@/services/componentService" ;
21- import type {
22- ComponentFolder ,
23- ComponentLibrary ,
24- SearchResult ,
25- } from "@/types/componentLibrary" ;
21+ import type { ComponentFolder , SearchResult } from "@/types/componentLibrary" ;
2622import type {
2723 ComponentReference ,
2824 HydratedComponentReference ,
@@ -75,7 +71,6 @@ type AvailableComponentLibraries =
7571 | string ;
7672
7773type ComponentLibraryContextType = {
78- componentLibrary : ComponentLibrary | undefined ;
7974 userComponentsFolder : ComponentFolder | undefined ;
8075 usedComponentsFolder : ComponentFolder ;
8176 isLoading : boolean ;
@@ -142,6 +137,10 @@ function useComponentLibraryRegistry() {
142137 /**
143138 * In future we will have other library types, including "standard_library", "favorite_components", "used_components", etc.
144139 */
140+ [
141+ "standard_components" ,
142+ new YamlFileLibrary ( "Standard library" , COMPONENT_LIBRARY_URL ) ,
143+ ] ,
145144 ] ) ,
146145 [ queryClient ] ,
147146 ) ;
@@ -193,7 +192,6 @@ export const ComponentLibraryProvider = ({
193192 const { getComponentLibraryObject, existingComponentLibraries } =
194193 useComponentLibraryRegistry ( ) ;
195194
196- const [ componentLibrary , setComponentLibrary ] = useState < ComponentLibrary > ( ) ;
197195 const [ userComponentsFolder , setUserComponentsFolder ] =
198196 useState < ComponentFolder > ( ) ;
199197
@@ -202,17 +200,6 @@ export const ComponentLibraryProvider = ({
202200 const [ newComponent , setNewComponent ] =
203201 useState < HydratedComponentReference | null > ( null ) ;
204202
205- // Fetch main component library
206- const {
207- data : rawComponentLibrary ,
208- isLoading : isLibraryLoading ,
209- error : libraryError ,
210- refetch : refetchLibrary ,
211- } = useQuery ( {
212- queryKey : [ "componentLibrary" ] ,
213- queryFn : fetchAndStoreComponentLibrary ,
214- } ) ;
215-
216203 // Fetch user components
217204 const {
218205 data : rawUserComponentsFolder ,
@@ -233,14 +220,6 @@ export const ComponentLibraryProvider = ({
233220 ) ;
234221
235222 // Methods
236- const refreshComponentLibrary = useCallback ( async ( ) => {
237- const { data : updatedLibrary } = await refetchLibrary ( ) ;
238-
239- if ( updatedLibrary ) {
240- setComponentLibrary ( updatedLibrary ) ;
241- }
242- } , [ refetchLibrary ] ) ;
243-
244223 const refreshUserComponents = useCallback ( async ( ) => {
245224 const { data : updatedUserComponents } = await refetchUserComponents ( ) ;
246225
@@ -300,30 +279,7 @@ export const ComponentLibraryProvider = ({
300279 } ,
301280 } ;
302281
303- if ( componentLibrary ) {
304- const uniqueComponents = filterToUniqueByDigest (
305- flattenFolders ( componentLibrary ) ,
306- ) ;
307-
308- if ( ! hasNameFilter && filtersSet . size > 1 ) {
309- // we need specs
310- const hydratedComponents = await Promise . all (
311- uniqueComponents . map ( async ( c ) => {
312- if ( ! c . spec ) {
313- return await hydrateComponentReference ( c ) ;
314- }
315- return c ;
316- } ) ,
317- ) ;
318-
319- result . components . standard = hydratedComponents
320- . filter ( ( c ) => c !== null )
321- . filter ( componentMatches ) ;
322- } else {
323- result . components . standard =
324- uniqueComponents . filter ( componentMatches ) ;
325- }
326- }
282+ // classic search is not supported for now
327283
328284 if ( userComponentsFolder ) {
329285 const uniqueComponents = filterToUniqueByDigest (
@@ -341,13 +297,13 @@ export const ComponentLibraryProvider = ({
341297
342298 return result ;
343299 } ,
344- [ componentLibrary , userComponentsFolder , usedComponentsFolder ] ,
300+ [ userComponentsFolder , usedComponentsFolder ] ,
345301 ) ;
346302
347303 const internalAddComponentToLibrary = useCallback (
348304 async ( hydratedComponent : HydratedComponentReference ) => {
349305 await importComponent ( hydratedComponent ) ;
350- await refreshComponentLibrary ( ) ;
306+
351307 await refreshUserComponents ( ) ;
352308 setNewComponent ( null ) ;
353309 setExistingComponent ( null ) ;
@@ -360,7 +316,7 @@ export const ComponentLibraryProvider = ({
360316 } ) ,
361317 ) ;
362318 } ,
363- [ refreshComponentLibrary , refreshUserComponents , importComponent ] ,
319+ [ refreshUserComponents , importComponent ] ,
364320 ) ;
365321
366322 const handleImportComponent = useCallback (
@@ -379,12 +335,7 @@ export const ComponentLibraryProvider = ({
379335 console . error ( "Error importing component:" , error ) ;
380336 }
381337 } ,
382- [
383- newComponent ,
384- refreshComponentLibrary ,
385- refreshUserComponents ,
386- importComponent ,
387- ] ,
338+ [ newComponent , refreshUserComponents , importComponent ] ,
388339 ) ;
389340
390341 const addToComponentLibraryWithDuplicateCheck = useCallback (
@@ -414,12 +365,7 @@ export const ComponentLibraryProvider = ({
414365 console . error ( "Error adding component to library:" , error ) ;
415366 }
416367 } ,
417- [
418- userComponentsFolder ,
419- refreshComponentLibrary ,
420- refreshUserComponents ,
421- importComponent ,
422- ] ,
368+ [ userComponentsFolder , refreshUserComponents , importComponent ] ,
423369 ) ;
424370
425371 const addToComponentLibrary = useCallback (
@@ -458,7 +404,6 @@ export const ComponentLibraryProvider = ({
458404 USER_COMPONENTS_LIST_NAME ,
459405 component . name ,
460406 ) . then ( async ( ) => {
461- await refreshComponentLibrary ( ) ;
462407 await refreshUserComponents ( ) ;
463408 } ) ;
464409 } else {
@@ -470,7 +415,7 @@ export const ComponentLibraryProvider = ({
470415 console . error ( "Error deleting component:" , error ) ;
471416 }
472417 } ,
473- [ refreshComponentLibrary , refreshUserComponents ] ,
418+ [ refreshUserComponents ] ,
474419 ) ;
475420
476421 const handleCloseDuplicationDialog = useCallback ( ( ) => {
@@ -497,14 +442,6 @@ export const ComponentLibraryProvider = ({
497442 } ;
498443 } , [ currentSearchFilter , searchComponentLibrary ] ) ;
499444
500- useEffect ( ( ) => {
501- if ( ! rawComponentLibrary ) {
502- setComponentLibrary ( undefined ) ;
503- return ;
504- }
505- setComponentLibrary ( rawComponentLibrary ) ;
506- } , [ rawComponentLibrary ] ) ;
507-
508445 useEffect ( ( ) => {
509446 if ( ! rawUserComponentsFolder ) {
510447 setUserComponentsFolder ( undefined ) ;
@@ -522,12 +459,11 @@ export const ComponentLibraryProvider = ({
522459 [ ] ,
523460 ) ;
524461
525- const isLoading = isLibraryLoading || isUserComponentsLoading ;
526- const error = libraryError || userComponentsError ;
462+ const isLoading = isUserComponentsLoading ;
463+ const error = userComponentsError ;
527464
528465 const value = useMemo (
529466 ( ) => ( {
530- componentLibrary,
531467 userComponentsFolder,
532468 usedComponentsFolder,
533469 isLoading,
@@ -541,7 +477,6 @@ export const ComponentLibraryProvider = ({
541477 checkIfUserComponent,
542478 } ) ,
543479 [
544- componentLibrary ,
545480 userComponentsFolder ,
546481 usedComponentsFolder ,
547482 isLoading ,
0 commit comments