diff --git a/src/components/shared/ReactFlow/FlowSidebar/sections/GraphComponents.tsx b/src/components/shared/ReactFlow/FlowSidebar/sections/GraphComponents.tsx index 556957662..2e79d65dc 100644 --- a/src/components/shared/ReactFlow/FlowSidebar/sections/GraphComponents.tsx +++ b/src/components/shared/ReactFlow/FlowSidebar/sections/GraphComponents.tsx @@ -1,5 +1,5 @@ import { PackagePlus } from "lucide-react"; -import { type ChangeEvent, useCallback, useMemo } from "react"; +import { type ChangeEvent } from "react"; import { ManageLibrariesDialog } from "@/components/shared/GitHubLibrary/ManageLibrariesDialog"; import { useBetaFlagValue } from "@/components/shared/Settings/useBetaFlags"; @@ -39,23 +39,8 @@ const GraphComponents = ({ isOpen }: { isOpen: boolean }) => { const remoteComponentLibrarySearchEnabled = useBetaFlagValue( "remote-component-library-search", ); - const githubComponentLibraryEnabled = useBetaFlagValue( - "github-component-library", - ); - - const { getComponentLibrary, existingComponentLibraries } = - useComponentLibrary(); const { updateSearchFilter, currentSearchFilter } = useForcedSearchContext(); - const { - componentLibrary, - usedComponentsFolder, - userComponentsFolder, - favoritesFolder, - isLoading, - error, - searchResult, - } = useComponentLibrary(); const handleSearchChange = (e: ChangeEvent) => { updateSearchFilter({ @@ -63,140 +48,11 @@ const GraphComponents = ({ isOpen }: { isOpen: boolean }) => { }); }; - const handleFiltersChange = useCallback( - (filters: string[]) => { - updateSearchFilter({ - filters, - }); - }, - [updateSearchFilter], - ); - - const memoizedContent = useMemo(() => { - if (isLoading) return ; - if (error) return ; - if (!componentLibrary) return ; - - if (!remoteComponentLibrarySearchEnabled && searchResult) { - // If there's a search result, use the SearchResults component - return ( - - ); - } - - // Otherwise show the regular folder structure - const hasUsedComponents = - usedComponentsFolder?.components && - usedComponentsFolder.components.length > 0; - - const hasFavouriteComponents = - favoritesFolder?.components && favoritesFolder.components.length > 0; - - const hasUserComponents = - userComponentsFolder?.components && - userComponentsFolder.components.length > 0; - - return ( - - {remoteComponentLibrarySearchEnabled && } - - - {hasUsedComponents && ( - - )} - {hasFavouriteComponents && ( - - )} - {hasUserComponents && ( - - )} - - , - , - ], - folders: [], - } as UIComponentFolder - } - icon="Cable" - /> - - - {githubComponentLibraryEnabled && ( - <> - - - - - Connected libraries - - - - - {existingComponentLibraries?.length === 0 && ( - - - No libraries connected - - - )} - - - {existingComponentLibraries?.map((library) => ( - - ))} - - )} - - - ); - }, [ - componentLibrary, - usedComponentsFolder, - userComponentsFolder, - favoritesFolder, - isLoading, - error, - searchResult, - remoteComponentLibrarySearchEnabled, - githubComponentLibraryEnabled, - existingComponentLibraries, - getComponentLibrary, - ]); + const handleFiltersChange = (filters: string[]) => { + updateSearchFilter({ + filters, + }); + }; if (!isOpen) { return ( @@ -223,7 +79,9 @@ const GraphComponents = ({ isOpen }: { isOpen: boolean }) => { } const searchComponent = remoteComponentLibrarySearchEnabled ? ( - {memoizedContent} + + + ) : ( <> { onFiltersChange={handleFiltersChange} /> - {memoizedContent} + ); @@ -259,4 +117,146 @@ const GraphComponents = ({ isOpen }: { isOpen: boolean }) => { ); }; +function ComponentLibrarySection() { + const remoteComponentLibrarySearchEnabled = useBetaFlagValue( + "remote-component-library-search", + ); + + const githubComponentLibraryEnabled = useBetaFlagValue( + "github-component-library", + ); + + const { getComponentLibrary, existingComponentLibraries } = + useComponentLibrary(); + + const { updateSearchFilter } = useForcedSearchContext(); + const { + componentLibrary, + usedComponentsFolder, + userComponentsFolder, + favoritesFolder, + isLoading, + error, + searchResult, + } = useComponentLibrary(); + + const handleFiltersChange = (filters: string[]) => { + updateSearchFilter({ + filters, + }); + }; + + if (isLoading) return ; + if (error) return ; + if (!componentLibrary) return ; + + if (!remoteComponentLibrarySearchEnabled && searchResult) { + // If there's a search result, use the SearchResults component + return ( + + ); + } + + // Otherwise show the regular folder structure + const hasUsedComponents = + usedComponentsFolder?.components && + usedComponentsFolder.components.length > 0; + + const hasFavouriteComponents = + favoritesFolder?.components && favoritesFolder.components.length > 0; + + const hasUserComponents = + userComponentsFolder?.components && + userComponentsFolder.components.length > 0; + + return ( + + {remoteComponentLibrarySearchEnabled && } + + + {hasUsedComponents && ( + + )} + {hasFavouriteComponents && ( + + )} + {hasUserComponents && ( + + )} + + , + , + ], + folders: [], + } as UIComponentFolder + } + icon="Cable" + /> + + + {githubComponentLibraryEnabled && ( + <> + + + + + Connected libraries + + + + + {existingComponentLibraries?.length === 0 && ( + + + No libraries connected + + + )} + + + {existingComponentLibraries?.map((library) => ( + + ))} + + )} + + + ); +} + export default GraphComponents;