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({