The implementation is complete. Here's a summary of the changes made to frontend/src/components/ui-new/primitives/RepoCard.tsx: (#2073)

## Summary

**Changes made:**

1. **Added `useMemo` import** (line 1) for memoizing the filtered options array

2. **Added logic to hide "Open pull request" when PR is open** (lines 101-109):
   - `hasPrOpen` checks if `prStatus === 'open'`
   - `availableActionOptions` filters out the 'pull-request' option when a PR is already open

3. **Added fallback for selected action** (lines 111-113):
   - `effectiveSelectedAction` ensures that if the user had previously selected 'pull-request' but a PR is now open, the button shows 'Merge' instead

4. **Updated SplitButton** to use `availableActionOptions` and `effectiveSelectedAction` (lines 286-291)

**Behavior:**
- When there is no open PR: Both "Open pull request" and "Merge" options are available
- When there is an open PR (`prStatus === 'open'`): Only the "Merge" option is shown
- When PR is closed or merged: The "Open pull request" option reappears (allowing users to create a new PR)
This commit is contained in:
Anastasiia Solop
2026-01-15 14:10:43 +01:00
committed by GitHub
parent e5920d7e00
commit 8ba3a50d0b

View File

@@ -1,3 +1,4 @@
import { useMemo } from 'react';
import {
GitBranchIcon,
GitPullRequestIcon,
@@ -97,6 +98,20 @@ export function RepoCard({
const { t: tCommon } = useTranslation('common');
const [selectedAction, setSelectedAction] = useRepoAction(repoId);
// Hide "Open pull request" option when PR is already open
const hasPrOpen = prStatus === 'open';
const availableActionOptions = useMemo(
() =>
hasPrOpen
? repoActionOptions.filter((opt) => opt.value !== 'pull-request')
: repoActionOptions,
[hasPrOpen]
);
// If PR is open and 'pull-request' was selected, fall back to 'merge'
const effectiveSelectedAction =
hasPrOpen && selectedAction === 'pull-request' ? 'merge' : selectedAction;
return (
<CollapsibleSection
persistKey={PERSIST_KEYS.repoCard(repoId)}
@@ -269,8 +284,8 @@ export function RepoCard({
{/* Actions row */}
<div className="my-base">
<SplitButton
options={repoActionOptions}
selectedValue={selectedAction}
options={availableActionOptions}
selectedValue={effectiveSelectedAction}
onSelectionChange={setSelectedAction}
onAction={(action) => onActionsClick?.(action)}
/>