Skip to content
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

Open
wants to merge 27 commits into
base: main
Choose a base branch
from

Conversation

rbren
Copy link
Collaborator

@rbren rbren commented Dec 24, 2024

This PR enhances the GitHub repository picker with the following features:

  • 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

To run this PR locally, use the following command:

docker run -it --rm   -p 3000:3000   -v /var/run/docker.sock:/var/run/docker.sock   --add-host host.docker.internal:host-gateway   -e SANDBOX_RUNTIME_CONTAINER_IMAGE=docker.all-hands.dev/all-hands-ai/runtime:aab5ecb-nikolaik   --name openhands-app-aab5ecb   docker.all-hands.dev/all-hands-ai/openhands:aab5ecb

@rbren rbren marked this pull request as draft December 24, 2024 13:26
@rbren rbren marked this pull request as ready for review December 24, 2024 14:13
Copy link
Contributor

@neubig neubig left a 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.

@neubig neubig self-requested a review December 26, 2024 00:39
@neubig neubig added the fix-me Attempt to fix this issue with OpenHands label Dec 26, 2024
@openhands-agent
Copy link
Contributor

OpenHands started fixing the pr! You can monitor the progress here.

@openhands-agent
Copy link
Contributor

OVERVIEW:
All issues appear to be successfully resolved. The changes implemented include:

  • Expanded search results (5 repos instead of 1)
  • Added popularity-based sorting (by stars)
  • Enhanced UI with multiple results and star counts
  • Preserved star count visibility for public repos

STATUS: ✅ FULLY RESOLVED
No remaining issues identified; changes successfully improve both functionality and user experience of the repository search feature.

@neubig neubig added lint-fix and removed fix-me Attempt to fix this issue with OpenHands labels Dec 26, 2024
@neubig neubig self-assigned this Dec 26, 2024
Comment on lines 25 to 33
React.useEffect(() => {
const searchPublicRepo = async () => {
const repos = await searchPublicRepositories(searchQuery);
setSearchedRepos(repos);
};

const debounceTimeout = setTimeout(searchPublicRepo, 300);
return () => clearTimeout(debounceTimeout);
}, [searchQuery]);
Copy link
Member

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

Copy link
Contributor

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.

@@ -16,6 +16,8 @@ interface GitHubUser {
interface GitHubRepository {
id: number;
full_name: string;
stargazers_count?: number;
fromPublicRepoSearch?: boolean;
Copy link
Member

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[] = /* ... */;

Copy link
Contributor

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:

  1. Confirm changes were made in the correct file location
  2. Show the specific type updates for finalRepositories and searchedRepos as requested
  3. Show the implementation of GitHubRepositoryWithFlag interface in the correct location

@neubig neubig added fix-me Attempt to fix this issue with OpenHands and removed lint-fix labels Dec 26, 2024
@openhands-agent
Copy link
Contributor

OpenHands started fixing the pr! You can monitor the progress here.

@openhands-agent
Copy link
Contributor

Here's a concise overview of the changes and remaining issues:

✅ RESOLVED:

  • Successfully created and implemented a useDebounce custom hook
  • Moved debouncing logic out of the component
  • Improved code reusability and separation of concerns

❌ STILL PENDING:

  • Typing improvements not fully confirmed:
    • Need to verify creation of GitHubRepositoryWithFlag interface
    • Need to confirm updates to finalRepositories and searchedRepos state types
    • Need to confirm changes were made in the correct file (frontend/src/components/features/github/github-repo-selector.tsx)

RECOMMENDATION:
Additional changes are needed to fully address the typing requirements. The AI should provide explicit confirmation of:

  1. The implementation of GitHubRepositoryWithFlag interface
  2. Updated state types for finalRepositories and searchedRepos
  3. Confirmation that changes were made in the correct file location

@rbren
Copy link
Collaborator Author

rbren commented Dec 26, 2024

@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?

@amanape
Copy link
Member

amanape commented Dec 26, 2024

We could separate personal repos and searched repos with sections too

@neubig
Copy link
Contributor

neubig commented Dec 26, 2024

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

@rbren
Copy link
Collaborator Author

rbren commented Dec 26, 2024

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

@neubig neubig force-pushed the enhance-repo-picker branch from 251f549 to aab5ecb Compare December 27, 2024 03:57
Copy link
Member

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

Comment on lines +43 to +67
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,
];
Copy link
Member

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

Comment on lines +131 to +133
} catch (error) {
return [];
}
Copy link
Member

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;
Copy link
Member

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

@neubig neubig added fix-me Attempt to fix this issue with OpenHands and removed fix-me Attempt to fix this issue with OpenHands lint-fix labels Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix-me Attempt to fix this issue with OpenHands
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants