Skip to content

Commit

Permalink
Simplify GitHub buttons visibility logic and remove code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
openhands-agent committed Dec 20, 2024
1 parent e4ae8fe commit 29bfa2b
Showing 1 changed file with 34 additions and 51 deletions.
85 changes: 34 additions & 51 deletions frontend/src/components/features/chat/action-suggestions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,65 +30,48 @@ export function ActionSuggestions({
onClose={handleDownloadClose}
isOpen={isDownloading}
/>
{gitHubToken ? (
selectedRepository ? (
<div className="flex flex-row gap-2 justify-center w-full">
{!hasPullRequest ? (
<>
<SuggestionItem
suggestion={{
label: "Push to Branch",
value:
"Please push the changes to a remote branch on GitHub, but do NOT create a pull request.",
}}
onClick={(value) => {
posthog.capture("push_to_branch_button_clicked");
onSuggestionsClick(value);
}}
/>
<SuggestionItem
suggestion={{
label: "Push & Create PR",
value:
"Please push the changes to GitHub and open a pull request.",
}}
onClick={(value) => {
posthog.capture("create_pr_button_clicked");
onSuggestionsClick(value);
setHasPullRequest(true);
}}
/>
</>
) : (
{gitHubToken && selectedRepository ? (
<div className="flex flex-row gap-2 justify-center w-full">
{!hasPullRequest ? (
<>
<SuggestionItem
suggestion={{
label: "Push changes to PR",
label: "Push to Branch",
value:
"Please push the latest changes to the existing pull request.",
"Please push the changes to a remote branch on GitHub, but do NOT create a pull request.",
}}
onClick={(value) => {
posthog.capture("push_to_pr_button_clicked");
posthog.capture("push_to_branch_button_clicked");
onSuggestionsClick(value);
}}
/>
)}
</div>
) : (
<SuggestionItem
suggestion={{
label: !isDownloading
? "Download files"
: "Downloading, please wait...",
value: "Download files",
}}
onClick={() => {
posthog.capture("download_workspace_button_clicked");
if (!isDownloading) {
setIsDownloading(true);
}
}}
/>
)
<SuggestionItem
suggestion={{
label: "Push & Create PR",
value:
"Please push the changes to GitHub and open a pull request.",
}}
onClick={(value) => {
posthog.capture("create_pr_button_clicked");
onSuggestionsClick(value);
setHasPullRequest(true);
}}
/>
</>
) : (
<SuggestionItem
suggestion={{
label: "Push changes to PR",
value:
"Please push the latest changes to the existing pull request.",
}}
onClick={(value) => {
posthog.capture("push_to_pr_button_clicked");
onSuggestionsClick(value);
}}
/>
)}
</div>
) : (
<SuggestionItem
suggestion={{
Expand Down

0 comments on commit 29bfa2b

Please sign in to comment.