-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(frontend): enhance GitHub repo picker with search and sorting (#…
…5783) Co-authored-by: openhands <[email protected]> Co-authored-by: Graham Neubig <[email protected]> Co-authored-by: sp.wack <[email protected]>
- Loading branch information
1 parent
f14f75b
commit 3b26678
Showing
14 changed files
with
221 additions
and
58 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
frontend/__tests__/components/features/github/github-repo-selector.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { screen } from "@testing-library/react"; | ||
import { describe, expect, it, vi } from "vitest"; | ||
import { renderWithProviders } from "test-utils"; | ||
import { GitHubRepositorySelector } from "#/components/features/github/github-repo-selector"; | ||
import OpenHands from "#/api/open-hands"; | ||
import * as GitHubAPI from "#/api/github"; | ||
|
||
describe("GitHubRepositorySelector", () => { | ||
const onInputChangeMock = vi.fn(); | ||
const onSelectMock = vi.fn(); | ||
|
||
it("should render the search input", () => { | ||
renderWithProviders( | ||
<GitHubRepositorySelector | ||
onInputChange={onInputChangeMock} | ||
onSelect={onSelectMock} | ||
repositories={[]} | ||
/>, | ||
); | ||
|
||
expect( | ||
screen.getByPlaceholderText("Select a GitHub project"), | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
it("should show the GitHub login button in OSS mode", () => { | ||
const getConfigSpy = vi.spyOn(OpenHands, "getConfig"); | ||
getConfigSpy.mockResolvedValue({ | ||
APP_MODE: "oss", | ||
APP_SLUG: "openhands", | ||
GITHUB_CLIENT_ID: "test-client-id", | ||
POSTHOG_CLIENT_KEY: "test-posthog-key", | ||
}); | ||
|
||
renderWithProviders( | ||
<GitHubRepositorySelector | ||
onInputChange={onInputChangeMock} | ||
onSelect={onSelectMock} | ||
repositories={[]} | ||
/>, | ||
); | ||
|
||
expect(screen.getByTestId("github-repo-selector")).toBeInTheDocument(); | ||
}); | ||
|
||
it("should show the search results", () => { | ||
const mockSearchedRepos = [ | ||
{ | ||
id: 1, | ||
full_name: "test/repo1", | ||
stargazers_count: 100, | ||
}, | ||
{ | ||
id: 2, | ||
full_name: "test/repo2", | ||
stargazers_count: 200, | ||
}, | ||
]; | ||
|
||
const searchPublicRepositoriesSpy = vi.spyOn( | ||
GitHubAPI, | ||
"searchPublicRepositories", | ||
); | ||
searchPublicRepositoriesSpy.mockResolvedValue(mockSearchedRepos); | ||
|
||
renderWithProviders( | ||
<GitHubRepositorySelector | ||
onInputChange={onInputChangeMock} | ||
onSelect={onSelectMock} | ||
repositories={[]} | ||
/>, | ||
); | ||
|
||
expect(screen.getByTestId("github-repo-selector")).toBeInTheDocument(); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { searchPublicRepositories } from "#/api/github"; | ||
|
||
export function useSearchRepositories(query: string) { | ||
return useQuery({ | ||
queryKey: ["repositories", query], | ||
queryFn: () => searchPublicRepositories(query, 3), | ||
enabled: !!query, | ||
select: (data) => data.map((repo) => ({ ...repo, is_public: true })), | ||
initialData: [], | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { useEffect, useState } from "react"; | ||
|
||
export function useDebounce<T>(value: T, delay: number): T { | ||
const [debouncedValue, setDebouncedValue] = useState<T>(value); | ||
|
||
useEffect(() => { | ||
const timer = setTimeout(() => setDebouncedValue(value), delay); | ||
return () => clearTimeout(timer); | ||
}, [value, delay]); | ||
|
||
return debouncedValue; | ||
} |
Oops, something went wrong.