diff --git a/components/dashboard/src/components/RepositoryFinder.tsx b/components/dashboard/src/components/RepositoryFinder.tsx index fa268ef04ed99f..4cd96021bb5b69 100644 --- a/components/dashboard/src/components/RepositoryFinder.tsx +++ b/components/dashboard/src/components/RepositoryFinder.tsx @@ -40,35 +40,44 @@ export default function RepositoryFinder(props: RepositoryFinderProps) { const getElements = useCallback( (searchString: string) => { - const result = [...suggestedContextURLs]; + let result: string[]; searchString = searchString.trim(); - try { - // If the searchString is a URL, and it's not present in the proposed results, "artificially" add it here. - new URL(searchString); - if (!result.includes(searchString)) { - result.push(searchString); + if (searchString.length > 1) { + result = suggestedContextURLs.filter((e) => e.toLowerCase().indexOf(searchString.toLowerCase()) !== -1); + if (result.length > 200) { + result = result.slice(0, 200); } - } catch {} - return result - .filter((e) => e.toLowerCase().indexOf(searchString.toLowerCase()) !== -1) - .map( - (e) => - ({ - id: e, - element: ( -
-
-
- {stripOffProtocol(e)} -
-
{}
+ if (result.length === 0) { + try { + // If the searchString is a URL, and it's not present in the proposed results, "artificially" add it here. + new URL(searchString); + if (!suggestedContextURLs.includes(searchString)) { + result.push(searchString); + } + } catch {} + } + } else { + result = suggestedContextURLs.slice(0, 200); + } + + return result.map( + (e) => + ({ + id: e, + element: ( +
+
+
+ {stripOffProtocol(e)}
-
{}
+
{}
- ), - isSelectable: true, - } as DropDown2Element), - ); +
{}
+
+ ), + isSelectable: true, + } as DropDown2Element), + ); }, [suggestedContextURLs], ); @@ -131,11 +140,3 @@ function saveSearchData(searchData: string[]): void { console.warn("Could not save search data into local storage", error); } } - -export function refreshSearchData() { - getGitpodService() - .server.getSuggestedContextURLs() - .then((urls) => { - saveSearchData(urls); - }); -} diff --git a/components/dashboard/src/hooks/use-user-loader.ts b/components/dashboard/src/hooks/use-user-loader.ts index 918b4346803b38..0e41527710ee3b 100644 --- a/components/dashboard/src/hooks/use-user-loader.ts +++ b/components/dashboard/src/hooks/use-user-loader.ts @@ -4,11 +4,10 @@ * See License.AGPL.txt in the project root for license information. */ -import { useContext } from "react"; +import { useContext, useEffect } from "react"; import { UserContext } from "../user-context"; import { getGitpodService } from "../service/service"; import { trackLocation } from "../Analytics"; -import { refreshSearchData } from "../components/RepositoryFinder"; import { useQuery } from "@tanstack/react-query"; import { noPersistence } from "../data/setup"; import { ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error"; @@ -20,7 +19,7 @@ export const useUserLoader = () => { // For now, we're using the user context to store the user, but letting react-query handle the loading // In the future, we should remove the user context and use react-query to access the user - const { isLoading } = useQuery({ + const userQuery = useQuery({ queryKey: noPersistence(["current-user"]), queryFn: async () => { const user = await getGitpodService().server.getLoggedInUser(); @@ -41,14 +40,18 @@ export const useUserLoader = () => { retryDelay: (attemptIndex) => Math.min(1000 * 2 ** attemptIndex, 10000), cacheTime: 1000 * 60 * 60 * 1, // 1 hour staleTime: 1000 * 60 * 60 * 1, // 1 hour - onSuccess: (loadedUser) => { - setUser(loadedUser); - refreshSearchData(); - }, + onSettled: (loadedUser) => { trackLocation(!!loadedUser); }, }); - return { user, loading: isLoading }; + // onSuccess is deprecated: https://tkdodo.eu/blog/breaking-react-querys-api-on-purpose + useEffect(() => { + if (userQuery.data) { + setUser(userQuery.data); + } + }, [userQuery.data, setUser]); + + return { user, loading: userQuery.isLoading }; }; diff --git a/components/server/src/bitbucket-server/bitbucket-server-repository-provider.ts b/components/server/src/bitbucket-server/bitbucket-server-repository-provider.ts index 777484aaa8ed75..b2c161975e9097 100644 --- a/components/server/src/bitbucket-server/bitbucket-server-repository-provider.ts +++ b/components/server/src/bitbucket-server/bitbucket-server-repository-provider.ts @@ -146,9 +146,8 @@ export class BitbucketServerRepositoryProvider implements RepositoryProvider { async getUserRepos(user: User): Promise { try { - // TODO: See if there's another api we could use here, such as recent repos for the user - // Only grab one page of up to 100 repos - const repos = await this.api.getRepos(user, { limit: 100, maxPages: 1, permission: "REPO_READ" }); + // TODO: implement incremental search + const repos = await this.api.getRepos(user, { maxPages: 10, permission: "REPO_READ" }); const result: string[] = []; repos.forEach((r) => { const cloneUrl = r.links.clone.find((u) => u.name === "http")?.href;