-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(frontend): enhance GitHub repo picker with search and sorting #5783
base: main
Are you sure you want to change the base?
Conversation
- Add GitHub API search for public repos when user enters a query - Show stargazer count for searched repos - Keep repos sorted by pushed_at (most recent first) - Place searched repo at the top of the picker
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this and the behavior of the search functionality is somewhat unintuitive. For instance, I did:
Lightning-AI/lit
and it gave me a result of Lightning-AI/lit-llama
(which has about 6000 stars) and then I continued typing Lightning-AI/litgpt
and got Lightning-AI/litgpt
(which has 10,000 stars). It seems that maybe it should display more than one result when it searces public repos, and it should sort in descending order of stars, given that stars are displayed in the interface.
OVERVIEW:
STATUS: ✅ FULLY RESOLVED |
React.useEffect(() => { | ||
const searchPublicRepo = async () => { | ||
const repos = await searchPublicRepositories(searchQuery); | ||
setSearchedRepos(repos); | ||
}; | ||
|
||
const debounceTimeout = setTimeout(searchPublicRepo, 300); | ||
return () => clearTimeout(debounceTimeout); | ||
}, [searchQuery]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could outsource logic into a useDebounce
hook
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Openhands fix success summary
The feedback has been successfully incorporated. The AI created a new custom hook called useDebounce
and moved the debouncing logic out of the component into this reusable hook. This is exactly what was requested in the feedback, and it improves code reusability and separation of concerns. The hook was created in a new file at /workspace/frontend/src/hooks/use-debounce.ts
, making it available for use across the application where needed.
This change follows React best practices by extracting common functionality into a custom hook, making the code more maintainable and reusable. The implementation also maintains all the existing functionality while improving the code structure.
frontend/src/components/features/github/github-repo-selector.tsx
Outdated
Show resolved
Hide resolved
@@ -16,6 +16,8 @@ interface GitHubUser { | |||
interface GitHubRepository { | |||
id: number; | |||
full_name: string; | |||
stargazers_count?: number; | |||
fromPublicRepoSearch?: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are modifying the root type for a flag we set in the component, this can cause issue down the line since we may try to access a property in some other area that does not exist (fromPublicRepoSearch
). Instead, extend the existing type for frontend/src/components/features/github/github-repo-selector.tsx
interface GitHubRepositoryWithFlag extends GitHubRepository {
fromPublicRepoSearch?: boolean;
}
NOTE you'll also want to set the type of finalRepositories
and searchedRepos
state too
const [searchedRepos, setSearchedRepos] = React.useState<
GitHubRepositoryWithFlag[]
>([]);
/* ... */
const finalRepositories: GitHubRepositoryWithFlag[] = /* ... */;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Openhands fix success summary
While the AI agent's message describes making changes to improve typing by creating a GitHubRepositoryWithFlag
interface that extends GitHubRepository
, the message is too general and doesn't specifically confirm where these changes were made. The feedback explicitly requested changes to be made in frontend/src/components/features/github/github-repo-selector.tsx
, but the AI's response doesn't mention making changes to this specific file.
Additionally, while the AI mentions updating "all relevant state and prop types," it doesn't explicitly confirm that finalRepositories
and searchedRepos
state types were updated as specified in the feedback. The response focuses on many other changes (debouncing, search functionality, etc.) that weren't part of the original feedback request.
To properly resolve this feedback, the AI needs to:
- Confirm changes were made in the correct file location
- Show the specific type updates for
finalRepositories
andsearchedRepos
as requested - Show the implementation of
GitHubRepositoryWithFlag
interface in the correct location
Co-authored-by: sp.wack <[email protected]>
Here's a concise overview of the changes and remaining issues: ✅ RESOLVED:
❌ STILL PENDING:
RECOMMENDATION:
|
@neubig I'm a little torn on the search behavior. We show the top 1 result based on what the GitHub search function deems relevant (which does seem to take stars into account). I do think we should rely on their ordering logic rather than our own. I could add more public repos to the search, but then we crowd out the personal repos, which are probably what you want 99% of the time. Maybe we show two? |
We could separate personal repos and searched repos with sections too |
Hey @rbren , I reduced to 3, which seems like a good tradeoff. I don't feel so strongly about stars, but showing the stars and then having it not be in star order seemed a bit confusing to me as a user. I can fix it if you think the github algorithm is better |
OK I set it to 3, and put them below personal repos (otherwise all the personal repos get crowded out) Also allowed pasting full repo urls |
251f549
to
aab5ecb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was the issue that required wrapping the assertions in a waitFor
? There also seem to be a lot of leftover console logs
React.useEffect(() => { | ||
const searchPublicRepo = async () => { | ||
if (!debouncedSearchQuery) { | ||
setSearchedRepos([]); | ||
return; | ||
} | ||
const repos = await searchPublicRepositories( | ||
sanitizeQuery(debouncedSearchQuery), | ||
); | ||
// Sort by stars in descending order | ||
const sortedRepos = repos | ||
.sort((a, b) => (b.stargazers_count || 0) - (a.stargazers_count || 0)) | ||
.slice(0, 3); | ||
setSearchedRepos(sortedRepos); | ||
}; | ||
|
||
searchPublicRepo(); | ||
}, [debouncedSearchQuery]); | ||
|
||
const finalRepositories: GitHubRepositoryWithFlag[] = [ | ||
...searchedRepos.filter( | ||
(repo) => !repositories.find((r) => r.id === repo.id), | ||
), | ||
...repositories, | ||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can outsource this into a hook that utilizes TanStack Query. That way we can control when the query is executed (!!debouncedSearchQuery
) and return a sorted array (via the select
property of the query/mutation hook).
That should help us get rid of the useEffect
and useState
(searchedRepos
) and make the component smaller and more readable
} catch (error) { | ||
return []; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If/when you are going to outsource the logic in frontend/src/components/features/github/github-repo-selector.tsx
into a custom hook with TanStack Query, you should let this throw. That way we can have better error handling via the query/mutation hooks (see https://tanstack.com/query/latest/docs/framework/react/guides/query-functions)
@@ -16,6 +16,8 @@ interface GitHubUser { | |||
interface GitHubRepository { | |||
id: number; | |||
full_name: string; | |||
stargazers_count?: number; | |||
fromPublicRepoSearch?: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we now extend this interface in the relevant component, we can remove the fromPublicRepoSearch
property from here
This PR enhances the GitHub repository picker with the following features:
To run this PR locally, use the following command: