From 3aa553892ff451f28dac0155a0abef21efb3b672 Mon Sep 17 00:00:00 2001 From: Jinjing <6427696+AmethystLiang@users.noreply.github.com> Date: Wed, 17 Jun 2026 01:03:43 -0700 Subject: [PATCH] Streamline Create PR UX and format git pull policy errors (#5576) * Show disabled Create PR button in header when branch is not ready Ensure the source control toolbar does not look blank or shift unexpectedly when the branch has no changes or cannot yet create a pull request. - Add helper to resolve disabled Create PR header actions with contextual titles (e.g. commit in progress, no changes, unsynced commits) - Keep the header button visible as a disabled anchor instead of hiding it - Prevent the Create PR button from stretching across the toolbar when visible without a hosted review * Refactor Create PR flow with inline-composer toggle and direct-create pa Co-authored-by: Orca * Streamline Create PR UX and format git pull policy errors Simplify the source control review-creation flow by removing the collapsible composer state and corresponding toolbar buttons, always rendering the PR composer directly when available. Additionally, add a specialized notice component for divergent branch errors that parses git pull policy issues and provides quick-copy buttons for configuring merge, rebase, or fast-forward behaviors. * Add loading state to Create PR and tooltip to disabled AI button - Display a disabled loading state for the Create PR action while review eligibility is fetching to avoid layout flashing. - Use aria-disabled and Tooltip for the AI commit message generator button to ensure tooltips are viewable when disabled. --------- Co-authored-by: Orca --- .../CommitArea.generate.test.tsx | 10 +- .../right-sidebar/CommitArea.test.tsx | 2 + .../right-sidebar/SourceControl.tsx | 162 ++++++++++--- .../source-control-branch-context-row.tsx | 12 +- ...ource-control-branch-context-stats.test.ts | 6 +- .../source-control-branch-context-stats.ts | 13 -- ...rce-control-create-pr-intent-state.test.ts | 33 +-- .../source-control-create-pr-intent-state.ts | 19 +- .../source-control-header-toolbar.tsx | 10 +- .../source-control-primary-action-types.ts | 3 + ...ol-primary-action.create-pr-intent.test.ts | 45 ++++ ...control-primary-create-pr-intent-action.ts | 217 +++++++++++++++++- src/renderer/src/i18n/locales/en.json | 1 + src/renderer/src/i18n/locales/es.json | 1 + src/renderer/src/i18n/locales/ja.json | 1 + src/renderer/src/i18n/locales/ko.json | 1 + src/renderer/src/i18n/locales/zh.json | 1 + 17 files changed, 441 insertions(+), 96 deletions(-) diff --git a/src/renderer/src/components/right-sidebar/CommitArea.generate.test.tsx b/src/renderer/src/components/right-sidebar/CommitArea.generate.test.tsx index dcd3feb3d..033d57ad2 100644 --- a/src/renderer/src/components/right-sidebar/CommitArea.generate.test.tsx +++ b/src/renderer/src/components/right-sidebar/CommitArea.generate.test.tsx @@ -76,7 +76,7 @@ function buttonByLabel(markup: string, label: string): string { } function hasDisabledAttribute(markup: string): boolean { - return markup.includes(' disabled=""') + return markup.includes(' disabled=""') || markup.includes('aria-disabled="true"') } describe('CommitArea AI generation', () => { @@ -95,9 +95,9 @@ describe('CommitArea AI generation', () => { aiAgentConfigured: true }) - expect(hasDisabledAttribute(buttonByLabel(markup, 'Generate commit message with AI'))).toBe( - false - ) + const button = buttonByLabel(markup, 'Generate commit message with AI') + expect(hasDisabledAttribute(button)).toBe(false) + expect(button).toContain('title="ai commit msg"') }) it('disables AI generation when the textarea already has user text', () => { @@ -108,7 +108,7 @@ describe('CommitArea AI generation', () => { }) const button = buttonByLabel(markup, 'Generate commit message with AI') - expect(hasDisabledAttribute(button)).toBe(true) + expect(button).toContain('aria-disabled="true"') expect(button).toContain('title="Clear the message to regenerate."') }) diff --git a/src/renderer/src/components/right-sidebar/CommitArea.test.tsx b/src/renderer/src/components/right-sidebar/CommitArea.test.tsx index 779ba9520..2a49499ea 100644 --- a/src/renderer/src/components/right-sidebar/CommitArea.test.tsx +++ b/src/renderer/src/components/right-sidebar/CommitArea.test.tsx @@ -387,6 +387,7 @@ describe('CommitArea', () => { const stageAllButton = firstButton(markup) expect(stageAllButton).toContain('Stage All') + expect(stageAllButton).toContain('data-variant="outline"') expect(stageAllButton).not.toContain('disabled=""') expect(stageAllButton).toContain('lucide-plus') expect(stageAllButton).toContain('rounded-r-none') @@ -419,6 +420,7 @@ describe('CommitArea', () => { const pushButton = firstButton(markup) expect(pushButton).toContain('Push') + expect(pushButton).toContain('data-variant="outline"') expect(pushButton).not.toContain('disabled=""') expect(pushButton).toContain('lucide-arrow-up') expect(pushButton).toContain('rounded-r-none') diff --git a/src/renderer/src/components/right-sidebar/SourceControl.tsx b/src/renderer/src/components/right-sidebar/SourceControl.tsx index b52cda33e..d54af41bf 100644 --- a/src/renderer/src/components/right-sidebar/SourceControl.tsx +++ b/src/renderer/src/components/right-sidebar/SourceControl.tsx @@ -223,7 +223,11 @@ import { type CreatePrIntentRunToken } from './source-control-create-pr-intent-flow' import { resolveVisibleCreatePrHeaderAction } from './source-control-create-pr-intent-state' -import { resolveCreatePrHeaderAction } from './source-control-primary-create-pr-intent-action' +import { + buildLoadingHostedReviewCreationEligibility, + resolveCreatePrHeaderAction, + resolveProvisionalHostedReviewProvider +} from './source-control-primary-create-pr-intent-action' import { getNextSourceControlViewMode, shouldShowSourceControlCompareUnavailableCard, @@ -562,6 +566,13 @@ type HostedReviewCreationState = { data: HostedReviewCreationEligibility } +type HostedReviewCreationRequestState = { + repoId: string + worktreeId: string + branch: string + status: 'loading' | 'failed' +} + type CreatedHostedReview = { provider: HostedReviewProvider number: number @@ -933,6 +944,8 @@ function SourceControlInner(): React.JSX.Element { const generateError = generateErrors[activeWorktreeId ?? ''] ?? null const [hostedReviewCreationState, setHostedReviewCreationState] = useState(null) + const [hostedReviewCreationRequestState, setHostedReviewCreationRequestState] = + useState(null) const createPrInFlightRef = useRef>({}) const [createPrInFlightByWorktree, setCreatePrInFlightByWorktree] = useState< Record @@ -1285,6 +1298,56 @@ function SourceControlInner(): React.JSX.Element { const linkedBitbucketPR = activeWorktree?.linkedBitbucketPR ?? null const linkedAzureDevOpsPR = activeWorktree?.linkedAzureDevOpsPR ?? null const linkedGiteaPR = activeWorktree?.linkedGiteaPR ?? null + const shouldResolveHostedReviewCreation = + isBranchVisible && + Boolean(activeRepo) && + !isFolder && + Boolean(branchName) && + branchName !== 'HEAD' && + Boolean(activeWorktreeId) + const hostedReviewCreationRequestMatchesCurrent = + hostedReviewCreationRequestState !== null && + activeRepo?.id === hostedReviewCreationRequestState.repoId && + activeWorktreeId === hostedReviewCreationRequestState.worktreeId && + branchName === hostedReviewCreationRequestState.branch + const isHostedReviewCreationLoading = + shouldResolveHostedReviewCreation && + hostedReviewCreationRequestMatchesCurrent && + hostedReviewCreationRequestState.status === 'loading' && + hostedReviewCreation === null && + hostedReview === null + const hostedReviewCreationForHeader = useMemo(() => { + if (hostedReviewCreation) { + return hostedReviewCreation + } + if (!isHostedReviewCreationLoading) { + return null + } + const provider = resolveProvisionalHostedReviewProvider({ + hostedReview, + hostedReviewCreationState, + activeRepoId: activeRepo?.id ?? null, + linkedGitHubPR, + fallbackGitHubPR: fallbackGitHubPRNumber, + linkedGitLabMR, + linkedBitbucketPR, + linkedAzureDevOpsPR, + linkedGiteaPR + }) + return buildLoadingHostedReviewCreationEligibility(provider) + }, [ + activeRepo?.id, + fallbackGitHubPRNumber, + hostedReview, + hostedReviewCreation, + hostedReviewCreationState, + isHostedReviewCreationLoading, + linkedAzureDevOpsPR, + linkedBitbucketPR, + linkedGitHubPR, + linkedGitLabMR, + linkedGiteaPR + ]) const hasLinkedHostedReview = (linkedGitHubPR ?? fallbackGitHubPRNumber) !== null || linkedGitLabMR !== null || @@ -2557,6 +2620,7 @@ function SourceControlInner(): React.JSX.Element { useEffect(() => { if (!isBranchVisible || !activeRepo || isFolder || !branchName || !activeWorktreeId) { setHostedReviewCreationState(null) + setHostedReviewCreationRequestState(null) return } // Why: skip refetches while the user's PR flow is mid-flight. AI generation, @@ -2564,9 +2628,16 @@ function SourceControlInner(): React.JSX.Element { // state temporarily. Recomputing eligibility mid-flow can tear down the // composer or rotate dropdown hints before the final refresh restores truth. if (prGenerating || isCreatingPr || isCreatePrIntentInFlight) { + setHostedReviewCreationRequestState(null) return } let stale = false + setHostedReviewCreationRequestState({ + repoId: activeRepo.id, + worktreeId: activeWorktreeId, + branch: branchName, + status: 'loading' + }) void getHostedReviewCreationEligibility({ repoPath: activeRepo.path, repoId: activeRepo.id, @@ -2592,12 +2663,19 @@ function SourceControlInner(): React.JSX.Element { branch: branchName, data: result }) + setHostedReviewCreationRequestState(null) } }) .catch((error) => { console.warn('[SourceControl] hosted review creation eligibility failed', error) if (!stale) { setHostedReviewCreationState(null) + setHostedReviewCreationRequestState({ + repoId: activeRepo.id, + worktreeId: activeWorktreeId, + branch: branchName, + status: 'failed' + }) } }) return () => { @@ -2609,6 +2687,7 @@ function SourceControlInner(): React.JSX.Element { effectiveBaseRef, getHostedReviewCreationEligibility, hasUncommittedEntries, + setHostedReviewCreationRequestState, isBranchVisible, isCreatingPr, isCreatePrIntentInFlight, @@ -3498,7 +3577,9 @@ function SourceControlInner(): React.JSX.Element { prState: hostedReview?.state ?? null, isPRStateLoading: isHostedReviewStateLoading, inFlightRemoteOpKind, - hostedReviewCreation, + hostedReviewCreation: hostedReviewCreationForHeader, + isHostedReviewCreationLoading: + isHostedReviewCreationLoading && hostedReviewCreationForHeader !== null, branchCommitsAhead: branchSummary?.status === 'ready' ? (branchSummary.commitsAhead ?? 0) : undefined, hasCurrentBranch: Boolean(branchName), @@ -3525,25 +3606,27 @@ function SourceControlInner(): React.JSX.Element { hasStageableChanges, hasUnstagedChanges, hostedReview?.state, - hostedReviewCreation, + hostedReviewCreationForHeader, hostedReviewCreateCopy.reviewLabel, inFlightRemoteOpKind, isAbortingOperation, isCommitting, isCreatePrIntentInFlight, isCreatingPr, + isHostedReviewCreationLoading, isHostedReviewStateLoading, isRemoteOperationActive, remoteStatus, unresolvedConflicts.length ]) const directCreatePrAction = - createPrHeaderAction?.kind === 'create_pr' ? createPrHeaderAction : null + createPrHeaderAction?.kind === 'create_pr' && + hostedReviewCreation?.canCreate === true && + (!createPrHeaderAction.disabled || isCreatingPr) + ? createPrHeaderAction + : null const visibleCreatePrHeaderAction = resolveVisibleCreatePrHeaderAction({ - createPrHeaderAction, - directCreatePrAction, - isCreatePrIntentInFlight, - primaryActionKind: primaryAction.kind + createPrHeaderAction }) const dropdownItems: DropdownEntry[] = useMemo( @@ -6138,25 +6221,46 @@ export function CommitArea({ ) : ( - + + + + + + {generateDisabledReason ?? + translate( + 'auto.components.right.sidebar.SourceControl.b16b8f0e4b', + 'ai commit msg' + )} + + ))} ) : null} @@ -6176,6 +6280,7 @@ export function CommitArea({