🙌 OpenHands: AI-Driven Development
feat(frontend): support pagination when loading repositories (microagent management) (#10708)
Hiep Le9f1d6963b8ae
diff --git a/frontend/__tests__/components/features/microagent-management/microagent-management.test.tsx b/frontend/__tests__/components/features/microagent-management/microagent-management.test.tsxindex 84b4f5c0cd..d0b4df9e54 100644--- a/frontend/__tests__/components/features/microagent-management/microagent-management.test.tsx+++ b/frontend/__tests__/components/features/microagent-management/microagent-management.test.tsx@@ -18,6 +18,7 @@ const mockUseGitRepositories = vi.fn();const mockUseConfig = vi.fn();const mockUseRepositoryMicroagents = vi.fn();const mockUseMicroagentManagementConversations = vi.fn();+const mockUseSearchRepositories = vi.fn();vi.mock("#/hooks/use-user-providers", () => ({useUserProviders: () => mockUseUserProviders(),@@ -40,6 +41,10 @@ vi.mock("#/hooks/query/use-microagent-management-conversations", () => ({mockUseMicroagentManagementConversations(),}));+vi.mock("#/hooks/query/use-search-repositories", () => ({+ useSearchRepositories: () => mockUseSearchRepositories(),+}));+describe("MicroagentManagement", () => {const RouterStub = createRoutesStub([{@@ -219,6 +224,12 @@ describe("MicroagentManagement", () => {isError: false,});+ mockUseSearchRepositories.mockReturnValue({+ data: [],+ isLoading: false,+ isError: false,+ });+// Setup default mock for retrieveUserGitRepositoriesvi.spyOn(OpenHands, "retrieveUserGitRepositories").mockResolvedValue({data: [...mockRepositories],@@ -743,17 +754,24 @@ describe("MicroagentManagement", () => {});await user.type(searchInput, "nonexistent");- // No repositories should be visible- expect(screen.queryByText("user/repo1")).not.toBeInTheDocument();- expect(- screen.queryByText("user/repo2/.openhands"),- ).not.toBeInTheDocument();- expect(- screen.queryByText("org/repo3/.openhands"),- ).not.toBeInTheDocument();- expect(screen.queryByText("user/repo4")).not.toBeInTheDocument();- expect(screen.queryByText("user/TestRepository")).not.toBeInTheDocument();- expect(screen.queryByText("org/AnotherRepo")).not.toBeInTheDocument();+ // Wait for debounced search to complete (300ms debounce + buffer)+ await new Promise((resolve) => setTimeout(resolve, 400));++ // Wait for the search to complete and check that no repositories are visible+ await waitFor(() => {+ expect(screen.queryByText("user/repo1")).not.toBeInTheDocument();+ expect(+ screen.queryByText("user/repo2/.openhands"),+ ).not.toBeInTheDocument();+ expect(+ screen.queryByText("org/repo3/.openhands"),+ ).not.toBeInTheDocument();+ expect(screen.queryByText("user/repo4")).not.toBeInTheDocument();+ expect(+ screen.queryByText("user/TestRepository"),+ ).not.toBeInTheDocument();+ expect(screen.queryByText("org/AnotherRepo")).not.toBeInTheDocument();+ });});it("should handle special characters in search", async () => {@@ -1272,11 +1290,14 @@ describe("MicroagentManagement", () => {// Add microagent integration testsdescribe("Add microagent functionality", () => {beforeEach(() => {- vi.spyOn(OpenHands, "getRepositoryBranches").mockResolvedValue(({ branches: [- { name: "main", commit_sha: "abc123", protected: false },- ], has_next_page: false, current_page: 1, per_page: 30, total_count: [- { name: "main", commit_sha: "abc123", protected: false },- ].length }) );+ vi.spyOn(OpenHands, "getRepositoryBranches").mockResolvedValue({+ branches: [{ name: "main", commit_sha: "abc123", protected: false }],+ has_next_page: false,+ current_page: 1,+ per_page: 30,+ total_count: [{ name: "main", commit_sha: "abc123", protected: false }]+ .length,+ });});it("should render add microagent button", async () => {@@ -1962,11 +1983,14 @@ describe("MicroagentManagement", () => {};beforeEach(() => {- vi.spyOn(OpenHands, "getRepositoryBranches").mockResolvedValue(({ branches: [- { name: "main", commit_sha: "abc123", protected: false },- ], has_next_page: false, current_page: 1, per_page: 30, total_count: [- { name: "main", commit_sha: "abc123", protected: false },- ].length }) );+ vi.spyOn(OpenHands, "getRepositoryBranches").mockResolvedValue({+ branches: [{ name: "main", commit_sha: "abc123", protected: false }],+ has_next_page: false,+ current_page: 1,+ per_page: 30,+ total_count: [{ name: "main", commit_sha: "abc123", protected: false }]+ .length,+ });});it("should render update microagent modal when updateMicroagentModalVisible is true", async () => {diff --git a/frontend/src/components/features/microagent-management/microagent-management-repositories.tsx b/frontend/src/components/features/microagent-management/microagent-management-repositories.tsxindex 653db7a46e..7356a3f5b5 100644--- a/frontend/src/components/features/microagent-management/microagent-management-repositories.tsx+++ b/frontend/src/components/features/microagent-management/microagent-management-repositories.tsx@@ -1,5 +1,5 @@import { useTranslation } from "react-i18next";-import { Accordion, AccordionItem } from "@heroui/react";+import { Accordion, AccordionItem, Spinner } from "@heroui/react";import { MicroagentManagementRepoMicroagents } from "./microagent-management-repo-microagents";import { GitRepository } from "#/types/git";import { TabType } from "#/types/microagent-management";@@ -11,16 +11,30 @@ import { MicroagentManagementAccordionTitle } from "./microagent-management-accotype MicroagentManagementRepositoriesProps = {repositories: GitRepository[];tabType: TabType;+ isSearchLoading?: boolean;};export function MicroagentManagementRepositories({repositories,tabType,+ isSearchLoading = false,}: MicroagentManagementRepositoriesProps) {const { t } = useTranslation();const numberOfRepoMicroagents = repositories.length;+ // Show spinner when search is in progress, regardless of repository count+ if (isSearchLoading) {+ return (+ <div className="flex flex-col items-center justify-center gap-4 py-8">+ <Spinner size="sm" />+ <span className="text-sm text-white">+ {t("HOME$SEARCHING_REPOSITORIES")}+ </span>+ </div>+ );+ }+if (numberOfRepoMicroagents === 0) {if (tabType === "personal") {return (diff --git a/frontend/src/components/features/microagent-management/microagent-management-sidebar-tabs.tsx b/frontend/src/components/features/microagent-management/microagent-management-sidebar-tabs.tsxindex 5db3a101ca..46d6fa8583 100644--- a/frontend/src/components/features/microagent-management/microagent-management-sidebar-tabs.tsx+++ b/frontend/src/components/features/microagent-management/microagent-management-sidebar-tabs.tsx@@ -5,7 +5,13 @@ import { MicroagentManagementRepositories } from "./microagent-management-reposiimport { I18nKey } from "#/i18n/declaration";import { RootState } from "#/store";-export function MicroagentManagementSidebarTabs() {+interface MicroagentManagementSidebarTabsProps {+ isSearchLoading?: boolean;+}++export function MicroagentManagementSidebarTabs({+ isSearchLoading = false,+}: MicroagentManagementSidebarTabsProps) {const { t } = useTranslation();const { repositories, personalRepositories, organizationRepositories } =@@ -29,18 +35,21 @@ export function MicroagentManagementSidebarTabs() {<MicroagentManagementRepositoriesrepositories={personalRepositories}tabType="personal"+ isSearchLoading={isSearchLoading}/></Tab><Tab key="repositories" title={t(I18nKey.COMMON$REPOSITORIES)}><MicroagentManagementRepositoriesrepositories={repositories}tabType="repositories"+ isSearchLoading={isSearchLoading}/></Tab><Tab key="organizations" title={t(I18nKey.COMMON$ORGANIZATIONS)}><MicroagentManagementRepositoriesrepositories={organizationRepositories}tabType="organizations"+ isSearchLoading={isSearchLoading}/></Tab></Tabs>diff --git a/frontend/src/components/features/microagent-management/microagent-management-sidebar.tsx b/frontend/src/components/features/microagent-management/microagent-management-sidebar.tsxindex a7decafc83..3d3f50df9f 100644--- a/frontend/src/components/features/microagent-management/microagent-management-sidebar.tsx+++ b/frontend/src/components/features/microagent-management/microagent-management-sidebar.tsx@@ -5,6 +5,7 @@ import { Spinner } from "@heroui/react";import { MicroagentManagementSidebarHeader } from "./microagent-management-sidebar-header";import { MicroagentManagementSidebarTabs } from "./microagent-management-sidebar-tabs";import { useGitRepositories } from "#/hooks/query/use-git-repositories";+import { useSearchRepositories } from "#/hooks/query/use-search-repositories";import { GitProviderDropdown } from "#/components/features/home/git-provider-dropdown";import {setPersonalRepositories,@@ -16,6 +17,7 @@ import { Provider } from "#/types/settings";import { cn } from "#/utils/utils";import { sanitizeQuery } from "#/utils/sanitize-query";import { I18nKey } from "#/i18n/declaration";+import { useDebounce } from "#/hooks/use-debounce";interface MicroagentManagementSidebarProps {isSmallerScreen?: boolean;@@ -31,17 +33,29 @@ export function MicroagentManagementSidebar({);const [searchQuery, setSearchQuery] = useState("");+ const debouncedSearchQuery = useDebounce(searchQuery, 300);const dispatch = useDispatch();const { t } = useTranslation();- const { data: repositories, isLoading } = useGitRepositories({+ // Use Git repositories hook with pagination for infinite scrolling+ const {+ data: repositories,+ fetchNextPage,+ hasNextPage,+ isLoading,+ isFetchingNextPage,+ } = useGitRepositories({provider: selectedProvider,- pageSize: 200,+ pageSize: 30, // Load 30 repositories per pageenabled: !!selectedProvider,});+ // Server-side search functionality+ const { data: searchResults, isLoading: isSearchLoading } =+ useSearchRepositories(debouncedSearchQuery, selectedProvider, 500); // Increase page size to 500 to to retrieve all search results. This should be optimized in the future.+// Auto-select provider if there's only oneuseEffect(() => {if (providers.length > 0 && !selectedProvider) {@@ -54,23 +68,31 @@ export function MicroagentManagementSidebar({setSearchQuery("");};- // Filter repositories based on search query+ // Filter repositories based on search query and available dataconst filteredRepositories = useMemo(() => {- if (!repositories?.pages) return null;+ // If we have search results, use them directly (no filtering needed)+ if (debouncedSearchQuery && searchResults && searchResults.length > 0) {+ return searchResults;+ }++ // If no search query or no search results, use paginated repositories+ if (!repositories?.pages) return [];// Flatten all pages to get all repositoriesconst allRepositories = repositories.pages.flatMap((page) => page.data);- if (!searchQuery.trim()) {+ // If no search query, return all repositories+ if (!debouncedSearchQuery.trim()) {return allRepositories;}- const sanitizedQuery = sanitizeQuery(searchQuery);+ // Fallback to client-side filtering if search didn't return results+ const sanitizedQuery = sanitizeQuery(debouncedSearchQuery);return allRepositories.filter((repository: GitRepository) => {const sanitizedRepoName = sanitizeQuery(repository.full_name);return sanitizedRepoName.includes(sanitizedQuery);});- }, [repositories, searchQuery, selectedProvider]);+ }, [repositories, debouncedSearchQuery, searchResults]);useEffect(() => {if (!filteredRepositories?.length) {@@ -104,12 +126,28 @@ export function MicroagentManagementSidebar({dispatch(setRepositories(otherRepos));}, [filteredRepositories, selectedProvider, dispatch]);+ // Handle scroll to bottom for pagination+ const handleScroll = (event: React.UIEvent<HTMLDivElement>) => {+ // Only enable pagination when not searching+ if (debouncedSearchQuery && searchResults) {+ return;+ }++ const { scrollTop, scrollHeight, clientHeight } = event.currentTarget;+ const isNearBottom = scrollTop + clientHeight >= scrollHeight - 10;++ if (isNearBottom && hasNextPage && !isFetchingNextPage) {+ fetchNextPage();+ }+ };+return (<divclassName={cn("w-[418px] h-full max-h-full overflow-y-auto overflow-x-hidden border-r border-[#525252] bg-[#24272E] rounded-tl-lg rounded-bl-lg py-10 px-6 flex flex-col",isSmallerScreen && "w-full border-none",)}+ onScroll={handleScroll}><MicroagentManagementSidebarHeader />@@ -131,18 +169,26 @@ export function MicroagentManagementSidebar({<label htmlFor="repository-search" className="sr-only">{t(I18nKey.COMMON$SEARCH_REPOSITORIES)}</label>- <input- id="repository-search"- name="repository-search"- type="text"- placeholder={`${t(I18nKey.COMMON$SEARCH_REPOSITORIES)}...`}- value={searchQuery}- onChange={(e) => setSearchQuery(e.target.value)}- className={cn(- "bg-tertiary border border-[#717888] bg-[#454545] w-full rounded-sm p-2 placeholder:italic placeholder:text-tertiary-alt",- "disabled:bg-[#2D2F36] disabled:border-[#2D2F36] disabled:cursor-not-allowed h-10 box-shadow-none outline-none",+ <div className="relative">+ <input+ id="repository-search"+ name="repository-search"+ type="text"+ placeholder={`${t(I18nKey.COMMON$SEARCH_REPOSITORIES)}...`}+ value={searchQuery}+ onChange={(e) => setSearchQuery(e.target.value)}+ className={cn(+ "bg-tertiary border border-[#717888] bg-[#454545] w-full rounded-sm p-2 placeholder:italic placeholder:text-tertiary-alt",+ "disabled:bg-[#2D2F36] disabled:border-[#2D2F36] disabled:cursor-not-allowed h-10 box-shadow-none outline-none",+ "pr-10", // Space for spinner+ )}+ />+ {isSearchLoading && (+ <div className="absolute right-3 top-1/2 transform -translate-y-1/2">+ <Spinner size="sm" />+ </div>)}- />+ </div></div>{isLoading ? (@@ -153,7 +199,19 @@ export function MicroagentManagementSidebar({</span></div>) : (- <MicroagentManagementSidebarTabs />+ <>+ <MicroagentManagementSidebarTabs isSearchLoading={isSearchLoading} />++ {/* Show loading indicator for pagination (only when not searching) */}+ {isFetchingNextPage && !debouncedSearchQuery && (+ <div className="flex justify-center pt-2">+ <Spinner size="sm" />+ <span className="text-sm text-white ml-2">+ {t("HOME$LOADING_MORE_REPOSITORIES")}+ </span>+ </div>+ )}+ </>)}</div>);diff --git a/frontend/src/components/shared/buttons/microagent-management-button.tsx b/frontend/src/components/shared/buttons/microagent-management-button.tsxindex 18a74d0b4e..05019d06ba 100644--- a/frontend/src/components/shared/buttons/microagent-management-button.tsx+++ b/frontend/src/components/shared/buttons/microagent-management-button.tsx@@ -1,7 +1,7 @@import { useTranslation } from "react-i18next";import { I18nKey } from "#/i18n/declaration";import { TooltipButton } from "./tooltip-button";-import UnionIcon from "#/icons/union.svg?react";+import RobotIcon from "#/icons/robot.svg?react";interface MicroagentManagementButtonProps {disabled?: boolean;@@ -22,7 +22,7 @@ export function MicroagentManagementButton({testId="microagent-management-button"disabled={disabled}>- <UnionIcon />+ <RobotIcon width={28} height={28} /></TooltipButton>);}diff --git a/frontend/src/hooks/query/use-search-repositories.ts b/frontend/src/hooks/query/use-search-repositories.tsindex 604d235b90..88f05830c7 100644--- a/frontend/src/hooks/query/use-search-repositories.ts+++ b/frontend/src/hooks/query/use-search-repositories.ts@@ -5,11 +5,16 @@ import { Provider } from "#/types/settings";export function useSearchRepositories(query: string,selectedProvider?: Provider | null,+ pageSize: number = 3,) {return useQuery({- queryKey: ["repositories", "search", query, selectedProvider],+ queryKey: ["repositories", "search", query, selectedProvider, pageSize],queryFn: () =>- OpenHands.searchGitRepositories(query, 3, selectedProvider || undefined),+ OpenHands.searchGitRepositories(+ query,+ pageSize,+ selectedProvider || undefined,+ ),enabled: !!query && !!selectedProvider,staleTime: 1000 * 60 * 5, // 5 minutesgcTime: 1000 * 60 * 15, // 15 minutesdiff --git a/frontend/src/i18n/declaration.ts b/frontend/src/i18n/declaration.tsindex 115c2ab226..fa5a66ae65 100644--- a/frontend/src/i18n/declaration.ts+++ b/frontend/src/i18n/declaration.ts@@ -85,6 +85,8 @@ export enum I18nKey {HOME$CONNECT_TO_REPOSITORY_TOOLTIP = "HOME$CONNECT_TO_REPOSITORY_TOOLTIP",HOME$LOADING = "HOME$LOADING",HOME$LOADING_REPOSITORIES = "HOME$LOADING_REPOSITORIES",+ HOME$SEARCHING_REPOSITORIES = "HOME$SEARCHING_REPOSITORIES",+ HOME$LOADING_MORE_REPOSITORIES = "HOME$LOADING_MORE_REPOSITORIES",HOME$FAILED_TO_LOAD_REPOSITORIES = "HOME$FAILED_TO_LOAD_REPOSITORIES",HOME$LOADING_BRANCHES = "HOME$LOADING_BRANCHES",HOME$FAILED_TO_LOAD_BRANCHES = "HOME$FAILED_TO_LOAD_BRANCHES",diff --git a/frontend/src/i18n/translation.json b/frontend/src/i18n/translation.jsonindex d91f02320a..675f36c56e 100644--- a/frontend/src/i18n/translation.json+++ b/frontend/src/i18n/translation.json@@ -1359,6 +1359,38 @@"de": "Repositories werden geladen...","uk": "Завантаження репозиторіїв..."},+ "HOME$SEARCHING_REPOSITORIES": {+ "en": "Searching repositories...",+ "ja": "リポジトリを検索中...",+ "zh-CN": "搜索仓库中...",+ "zh-TW": "搜尋儲存庫中...",+ "ko-KR": "저장소 검색 중...",+ "no": "Søker i repositories...",+ "it": "Ricerca repository in corso...",+ "pt": "Pesquisando repositórios...",+ "es": "Buscando repositorios...",+ "ar": "جار البحث في المستودعات...",+ "fr": "Recherche de dépôts...",+ "tr": "Depolar aranıyor...",+ "de": "Repositories werden durchsucht...",+ "uk": "Пошук репозиторіїв..."+ },+ "HOME$LOADING_MORE_REPOSITORIES": {+ "en": "Loading more repositories...",+ "ja": "さらに多くのリポジトリを読み込み中...",+ "zh-CN": "加载更多仓库中...",+ "zh-TW": "載入更多儲存庫中...",+ "ko-KR": "더 많은 저장소 로딩 중...",+ "no": "Laster flere repositories...",+ "it": "Caricamento di altri repository...",+ "pt": "Carregando mais repositórios...",+ "es": "Cargando más repositorios...",+ "ar": "جار تحميل المزيد من المستودعات...",+ "fr": "Chargement de plus de dépôts...",+ "tr": "Daha fazla depolar yükleniyor...",+ "de": "Weitere Repositories werden geladen...",+ "uk": "Завантаження більше репозиторіїв..."+ },"HOME$FAILED_TO_LOAD_REPOSITORIES": {"en": "Failed to load repositories","ja": "リポジトリの読み込みに失敗しました",diff --git a/frontend/src/icons/robot.svg b/frontend/src/icons/robot.svgnew file mode 100644index 0000000000..19b2253013--- /dev/null+++ b/frontend/src/icons/robot.svg@@ -0,0 +1,4 @@+<svg width="47" height="42" viewBox="0 0 47 42" fill="none" xmlns="http://www.w3.org/2000/svg">+<path d="M2.58409 21.782C2.01747 21.782 1.48418 22.0153 1.11755 22.3819C0.750916 22.7486 0.517578 23.3152 0.517578 23.8485V28.0148C0.517578 28.5814 0.750916 29.1147 1.11755 29.4813C1.51751 29.8813 2.05081 30.0813 2.58409 30.0813C3.11737 30.0813 3.684 29.8479 4.05063 29.4813C4.45059 29.0814 4.65055 28.5481 4.65055 28.0148V23.8485C4.65055 23.2819 4.41726 22.7486 4.05063 22.3819C3.684 22.0153 3.11737 21.782 2.58409 21.782ZM44.2802 21.782C43.7136 21.782 43.1803 22.0153 42.8137 22.3819C42.4471 22.7486 42.2138 23.3152 42.2138 23.8485V28.0148C42.2138 28.5814 42.4471 29.1147 42.8137 29.4813C43.2137 29.8813 43.747 30.0813 44.2802 30.0813C44.8135 30.0813 45.3801 29.8479 45.7468 29.4813C46.1467 29.0814 46.3467 28.5481 46.3467 28.0148V23.8485C46.3467 23.2819 46.1134 22.7486 45.7468 22.3819C45.3801 22.0153 44.8135 21.782 44.2802 21.782ZM21.349 10.3164H13.0164C11.3499 10.3164 9.75011 10.983 8.58355 12.1496C7.41699 13.3161 6.75037 14.916 6.75037 16.5825V35.3474C6.75037 37.0139 7.41699 38.6138 8.58355 39.7804C9.75011 40.9469 11.3499 41.6135 13.0164 41.6135H33.8812C35.5477 41.6135 37.1476 40.9469 38.3141 39.7804C39.4807 38.6138 40.1473 37.0139 40.1473 35.3474V16.5825C40.1473 14.916 39.4807 13.3161 38.3141 12.1496C37.1476 10.983 35.5477 10.3164 33.8812 10.3164H25.5486M19.8491 14.4827H27.0152ZM31.3148 14.4827H33.8478C34.4145 14.4827 34.9478 14.716 35.3144 15.0826C35.7144 15.4826 35.9144 16.0159 35.9144 16.5492V35.3141C35.9144 35.8807 35.681 36.3807 35.3144 36.7806C34.9144 37.1806 34.3811 37.3806 33.8478 37.3806H12.9831C12.4165 37.3806 11.8832 37.1473 11.5166 36.7806C11.1166 36.3807 10.9167 35.8474 10.9167 35.3141V16.5492C10.9167 15.9825 11.1499 15.4493 11.5166 15.0826C11.9165 14.6827 12.4498 14.4827 12.9831 14.4827H15.5162M17.7494 21.782C17.1828 21.782 16.6495 22.0153 16.2828 22.3819C15.9162 22.7486 15.6829 23.3152 15.6829 23.8485V28.0148C15.6829 28.5814 15.9162 29.1147 16.2828 29.4813C16.6828 29.8813 17.2161 30.0813 17.7494 30.0813C18.2827 30.0813 18.8492 29.8479 19.2159 29.4813C19.6158 29.0814 19.8158 28.5481 19.8158 28.0148V23.8485C19.8158 23.2819 19.5825 22.7486 19.2159 22.3819C18.8492 22.0153 18.2827 21.782 17.7494 21.782ZM29.0816 21.782C28.515 21.782 27.9817 22.0153 27.6151 22.3819C27.2485 22.7486 27.0152 23.3152 27.0152 23.8485V28.0148C27.0152 28.5814 27.2485 29.1147 27.6151 29.4813C28.0151 29.8813 28.5484 30.0813 29.0816 30.0813C29.6149 30.0813 30.1816 29.8479 30.5482 29.4813C30.9481 29.0814 31.1481 28.5481 31.1481 28.0148V23.8485C31.1481 23.2819 30.9148 22.7486 30.5482 22.3819C30.1816 22.0153 29.6149 21.782 29.0816 21.782Z" fill="currentColor"/>+<path d="M23.4122 0.851806C22.7122 0.851806 22.0123 1.05179 21.4123 1.45175C20.8124 1.85171 20.3791 2.41834 20.0791 3.05162C19.8125 3.71822 19.7458 4.41814 19.8792 5.11808C20.0125 5.81801 20.3458 6.4513 20.8457 6.95125C21.3457 7.45121 21.979 7.78451 22.6789 7.91783C23.3788 8.05115 24.1121 7.98448 24.7454 7.71783C25.412 7.45119 25.9452 6.98459 26.3452 6.38464C26.7452 5.7847 26.9452 5.11807 26.9452 4.38481C26.9452 3.41823 26.5785 2.51833 25.8786 1.85172C25.1786 1.18512 24.2787 0.785156 23.3455 0.785156L23.4122 0.851806Z" fill="currentColor"/>+</svg>