diff --git a/mobile/src/components/ActionSheetModal.tsx b/mobile/src/components/ActionSheetModal.tsx index 774adcc3c40..49a25ebbc78 100644 --- a/mobile/src/components/ActionSheetModal.tsx +++ b/mobile/src/components/ActionSheetModal.tsx @@ -15,6 +15,8 @@ export type ActionSheetAction = { destructive?: boolean disabled?: boolean hint?: string + /** Short trailing state, e.g. "↑2" or "Up to date". */ + status?: string /** Marks the choice that is current, as a trailing check. */ checked?: boolean loading?: boolean @@ -77,6 +79,7 @@ export function ActionSheetContent({ title, message, children, actions, onClose key={action.id ?? action.label} title={action.label} subtitle={action.hint} + value={action.status} leading={ action.renderIcon?.() ?? ( press(action)} accessibilityRole="menuitem" - accessibilityLabel={action.label} + accessibilityLabel={ + action.status ? `${action.label}, ${action.status}` : action.label + } accessibilityHint={action.hint} accessibilityState={ action.checked === undefined ? undefined : { checked: action.checked } @@ -213,6 +215,11 @@ export function PullDownMenu({ visible, anchorRef, groups, onClose }: PullDownMe ) : null} + {action.status ? ( + + {action.status} + + ) : null} {action.checked ? ( ) : action.renderIcon ? ( @@ -280,5 +287,12 @@ const styles = themedStyleSheet(() => ({ hint: { color: colors.textSecondary, fontSize: typography.metaSize + }, + status: { + marginLeft: 'auto', + flexShrink: 0, + color: colors.textSecondary, + fontSize: typography.metaSize, + fontVariant: ['tabular-nums'] } })) diff --git a/mobile/src/i18n/locales/en.json b/mobile/src/i18n/locales/en.json index f14faed6778..64f6da0b899 100644 --- a/mobile/src/i18n/locales/en.json +++ b/mobile/src/i18n/locales/en.json @@ -3482,7 +3482,12 @@ "commitThenPullPush": "Commit, then pull and push", "resolveConflicts": "Resolve conflicts before committing", "stageFile": "Stage at least one file to commit", - "enterMessage": "Enter a commit message to commit" + "enterMessage": "Enter a commit message to commit", + "statusConflicts": "Conflicts", + "statusNothingStaged": "Nothing staged", + "statusNeedsMessage": "Needs message", + "statusNotPublished": "Not published", + "statusNoBranch": "No branch" }, "createPrAction": { "createReview": "Create {{titleLabel}}", @@ -3559,7 +3564,15 @@ "nothingToPushTo": "Nothing to push to {{upstreamName}}", "nothingToForcePushTo": "Nothing to force push to {{upstreamName}}", "rebaseFromNamedBase": "Rebase from {{baseRef}}", - "rebaseWithLatestFrom": "Rebase current branch with latest commits from {{baseRef}}" + "rebaseWithLatestFrom": "Rebase current branch with latest commits from {{baseRef}}", + "statusUpToDate": "Up to date", + "statusSetsUpstream": "Sets upstream", + "statusNotPublished": "Not published", + "statusNoBranch": "No branch", + "statusMayFail": "May fail", + "statusPublished": "Published", + "statusStashFirst": "Stash first", + "statusReplaces": "Replaces ↓{{behind}}" }, "actions": { "createPr": "Create PR", diff --git a/mobile/src/source-control/mobile-commit-dropdown-copy.ts b/mobile/src/source-control/mobile-commit-dropdown-copy.ts index 6ed43bd8647..7cc182bde00 100644 --- a/mobile/src/source-control/mobile-commit-dropdown-copy.ts +++ b/mobile/src/source-control/mobile-commit-dropdown-copy.ts @@ -69,6 +69,18 @@ export function mobileCommitDropdownCopy(t: Translate): CommitDropdownCopy { case 'Enter a commit message to commit': return t('sourceControl.commitDropdown.enterMessage', 'Enter a commit message to commit') } - } + }, + commitDisabledStatus: (reason) => { + switch (reason) { + case 'Resolve conflicts before committing': + return t('sourceControl.commitDropdown.statusConflicts', 'Conflicts') + case 'Stage at least one file to commit': + return t('sourceControl.commitDropdown.statusNothingStaged', 'Nothing staged') + case 'Enter a commit message to commit': + return t('sourceControl.commitDropdown.statusNeedsMessage', 'Needs message') + } + }, + statusNotPublished: t('sourceControl.commitDropdown.statusNotPublished', 'Not published'), + statusNoBranch: t('sourceControl.commitDropdown.statusNoBranch', 'No branch') } } diff --git a/mobile/src/source-control/mobile-remote-dropdown-copy.ts b/mobile/src/source-control/mobile-remote-dropdown-copy.ts index a8cea9cbbb3..8f5e9a55ecf 100644 --- a/mobile/src/source-control/mobile-remote-dropdown-copy.ts +++ b/mobile/src/source-control/mobile-remote-dropdown-copy.ts @@ -160,6 +160,15 @@ export function mobileRemoteDropdownCopy(t: Translate): RemoteDropdownCopy { manualForcePush: (ahead, behind, upstreamName) => localizedManualForcePush(ahead, behind, upstreamName, t), unpublishedForcePush: (branchCommitsAhead) => - localizedUnpublishedForcePush(branchCommitsAhead, t) + localizedUnpublishedForcePush(branchCommitsAhead, t), + statusUpToDate: t('sourceControl.remoteDropdown.statusUpToDate', 'Up to date'), + statusSetsUpstream: t('sourceControl.remoteDropdown.statusSetsUpstream', 'Sets upstream'), + statusNotPublished: t('sourceControl.remoteDropdown.statusNotPublished', 'Not published'), + statusNoBranch: t('sourceControl.remoteDropdown.statusNoBranch', 'No branch'), + statusMayFail: t('sourceControl.remoteDropdown.statusMayFail', 'May fail'), + statusPublished: t('sourceControl.remoteDropdown.statusPublished', 'Published'), + statusStashFirst: t('sourceControl.remoteDropdown.statusStashFirst', 'Stash first'), + statusReplaces: (behind) => + t('sourceControl.remoteDropdown.statusReplaces', 'Replaces ↓{{behind}}', { behind }) } } diff --git a/mobile/src/source-control/mobile-source-control-actions.ts b/mobile/src/source-control/mobile-source-control-actions.ts index cd819d69476..c4c453ddea4 100644 --- a/mobile/src/source-control/mobile-source-control-actions.ts +++ b/mobile/src/source-control/mobile-source-control-actions.ts @@ -31,6 +31,7 @@ export type MobileSourceControlAction = { iconKey: MobileSourceControlActionIcon disabled?: boolean hint?: string + status?: string loading?: boolean skipAutoClose?: boolean closeBeforePress?: boolean @@ -84,7 +85,7 @@ export function buildMobileSourceControlActions( const busy = args.busyAction !== null const blockForce = (item: DropdownItem): DropdownItem => args.forcePushBlockedReason - ? { ...item, disabled: true, title: args.forcePushBlockedReason } + ? { ...item, disabled: true, title: args.forcePushBlockedReason, status: undefined } : item const row = ( item: DropdownItem, @@ -98,6 +99,7 @@ export function buildMobileSourceControlActions( disabled: busy || item.disabled, // Mobile has no tooltips: show why a row is disabled, and always what Force Push replaces. hint: item.disabled || item.kind === 'force_push' ? item.title : undefined, + status: item.status, loading: args.busyAction === actionId, skipAutoClose: true, onPress diff --git a/src/renderer/src/components/right-sidebar/source-control/commit/commit-area.tsx b/src/renderer/src/components/right-sidebar/source-control/commit/commit-area.tsx index 4dc129b24b9..bf7a0537a43 100644 --- a/src/renderer/src/components/right-sidebar/source-control/commit/commit-area.tsx +++ b/src/renderer/src/components/right-sidebar/source-control/commit/commit-area.tsx @@ -1,4 +1,4 @@ -import React, { useId, useMemo } from 'react' +import React, { useMemo } from 'react' import { ArrowDownUp, ArrowUp, Check, CloudUpload, GitPullRequestArrow, Plus } from 'lucide-react' import { DropdownMenuContent, @@ -6,6 +6,7 @@ import { DropdownMenuSeparator } from '@/components/ui/dropdown-menu' import { useTranslate } from '@/i18n/use-translate' +import { cn } from '@/lib/class-names' import { hasExpandedCommitFailureDetails, summarizeCommitFailure @@ -80,7 +81,6 @@ export function CommitArea({ onDropdownAction }: CommitAreaProps): React.JSX.Element { const t = useTranslate() - const actionDescriptionId = useId() // Cap rows so long messages scroll internally instead of pushing Commit offscreen. const rows = getCommitMessageTextareaRows(commitMessage) // Spin the primary only for its matching operation; Fetch uses the chevron and commits use isCommitting. @@ -173,41 +173,44 @@ export function CommitArea({ 'More commit and remote actions' ) const dropdownMenuContent = ( - + {dropdownItems.map((entry) => entry.kind === 'separator' ? ( ) : ( -
- { - if (entry.disabled) { - event.preventDefault() - return - } - onDropdownAction(entry.kind) - }} - > - - {entry.label} - {!entry.disabled && ( - {entry.title} + { + if (entry.disabled) { + event.preventDefault() + return + } + onDropdownAction(entry.kind) + }} + > + + {entry.label} + + {entry.status && ( + - - {entry.disabled && ( -

- {entry.title} -

+ {entry.status} +
)} -
+ ) )}
diff --git a/src/renderer/src/components/right-sidebar/source-control/panel/source-control-dropdown-items.ts b/src/renderer/src/components/right-sidebar/source-control/panel/source-control-dropdown-items.ts index 00e369e0a99..096ce79280f 100644 --- a/src/renderer/src/components/right-sidebar/source-control/panel/source-control-dropdown-items.ts +++ b/src/renderer/src/components/right-sidebar/source-control/panel/source-control-dropdown-items.ts @@ -39,6 +39,26 @@ function localizedCommitDisabledReason(reason: CommitDisabledReason): string { } } +function localizedCommitDisabledStatus(reason: CommitDisabledReason): string { + switch (reason) { + case 'Resolve conflicts before committing': + return translate( + 'auto.components.right.sidebar.source.control.dropdown.items.statusConflicts', + 'Conflicts' + ) + case 'Stage at least one file to commit': + return translate( + 'auto.components.right.sidebar.source.control.dropdown.items.statusNothingStaged', + 'Nothing staged' + ) + case COMMIT_MESSAGE_REQUIRED_REASON: + return translate( + 'auto.components.right.sidebar.source.control.dropdown.items.statusNeedsMessage', + 'Needs message' + ) + } +} + function localizedCommitCopy(t: Translate = translate): CommitDropdownCopy { return { commit: t('auto.components.right.sidebar.source.control.dropdown.items.2b8e6595fd', 'Commit'), @@ -110,7 +130,16 @@ function localizedCommitCopy(t: Translate = translate): CommitDropdownCopy { 'auto.components.right.sidebar.source.control.dropdown.items.titleCommitThenPullPush', 'Commit, then pull and push' ), - commitDisabledReason: localizedCommitDisabledReason + commitDisabledReason: localizedCommitDisabledReason, + commitDisabledStatus: localizedCommitDisabledStatus, + statusNotPublished: t( + 'auto.components.right.sidebar.source.control.dropdown.items.statusNotPublished', + 'Not published' + ), + statusNoBranch: t( + 'auto.components.right.sidebar.source.control.dropdown.items.statusNoBranch', + 'No branch' + ) } } @@ -183,6 +212,8 @@ export function resolveDropdownItems( 'auto.components.right.sidebar.source.control.dropdown.items.7aad2c0240', 'Hosted review operation in progress…' ), + status: undefined, + statusTone: undefined, disabled: true } ) diff --git a/src/renderer/src/components/right-sidebar/source-control/panel/source-control-dropdown-remote-localized-copy.ts b/src/renderer/src/components/right-sidebar/source-control/panel/source-control-dropdown-remote-localized-copy.ts index 9228b13d6b7..2046a8a9eb2 100644 --- a/src/renderer/src/components/right-sidebar/source-control/panel/source-control-dropdown-remote-localized-copy.ts +++ b/src/renderer/src/components/right-sidebar/source-control/panel/source-control-dropdown-remote-localized-copy.ts @@ -203,6 +203,40 @@ export function localizedRemoteCopy(t: Translate = translate): RemoteDropdownCop syncCounts: localizedSyncCounts, forcePushWithLease: localizedForcePushWithLease, manualForcePush: localizedManualForcePush, - unpublishedForcePush: localizedUnpublishedForcePush + unpublishedForcePush: localizedUnpublishedForcePush, + statusUpToDate: t( + 'auto.components.right.sidebar.source.control.dropdown.items.statusUpToDate', + 'Up to date' + ), + statusSetsUpstream: t( + 'auto.components.right.sidebar.source.control.dropdown.items.statusSetsUpstream', + 'Sets upstream' + ), + statusNotPublished: t( + 'auto.components.right.sidebar.source.control.dropdown.items.statusNotPublished', + 'Not published' + ), + statusNoBranch: t( + 'auto.components.right.sidebar.source.control.dropdown.items.statusNoBranch', + 'No branch' + ), + statusMayFail: t( + 'auto.components.right.sidebar.source.control.dropdown.items.statusMayFail', + 'May fail' + ), + statusPublished: t( + 'auto.components.right.sidebar.source.control.dropdown.items.statusPublished', + 'Published' + ), + statusStashFirst: t( + 'auto.components.right.sidebar.source.control.dropdown.items.statusStashFirst', + 'Stash first' + ), + statusReplaces: (behind) => + t( + 'auto.components.right.sidebar.source.control.dropdown.items.statusReplaces', + 'Replaces ↓{{behind}}', + { behind } + ) } } diff --git a/src/renderer/src/components/right-sidebar/source-control/review/source-control-dropdown-review-items.ts b/src/renderer/src/components/right-sidebar/source-control/review/source-control-dropdown-review-items.ts index 77dba32b803..3f321c5d701 100644 --- a/src/renderer/src/components/right-sidebar/source-control/review/source-control-dropdown-review-items.ts +++ b/src/renderer/src/components/right-sidebar/source-control/review/source-control-dropdown-review-items.ts @@ -101,6 +101,36 @@ export function buildHostedReviewDropdownItems( } })() + const createBlockedStatus = ((): string | undefined => { + switch (hostedReviewCreation?.blockedReason) { + case 'dirty': + return t( + 'auto.components.right.sidebar.source.control.dropdown.items.statusCommitFirst', + 'Commit first' + ) + case 'detached_head': + return t( + 'auto.components.right.sidebar.source.control.dropdown.items.statusNoBranch', + 'No branch' + ) + case 'existing_review': + return t( + 'auto.components.right.sidebar.source.control.dropdown.items.statusReviewOpen', + '{{shortLabel}} open', + { + shortLabel: createReviewCopy.shortLabel + } + ) + case 'no_upstream': + return t( + 'auto.components.right.sidebar.source.control.dropdown.items.statusNotPublished', + 'Not published' + ) + default: + return undefined + } + })() + const createPR: DropdownItem = { kind: 'create_pr', label: t( @@ -116,6 +146,7 @@ export function buildHostedReviewDropdownItems( ) : createBlockedHint, hint: hostedReviewCreation?.canCreate ? undefined : createBlockedHint, + status: hostedReviewCreation?.canCreate ? undefined : createBlockedStatus, disabled: globalBusy || !supportsHostedReviewCreation(hostedReviewCreation?.provider) || @@ -160,6 +191,7 @@ export function buildHostedReviewDropdownItems( ) : createBlockedHint, hint: canPushAndCreate ? undefined : createBlockedHint, + status: canPushAndCreate ? undefined : createBlockedStatus, disabled: !canPushAndCreate } diff --git a/src/renderer/src/i18n/locales/en.json b/src/renderer/src/i18n/locales/en.json index 6b5b44dcb92..4b797077301 100644 --- a/src/renderer/src/i18n/locales/en.json +++ b/src/renderer/src/i18n/locales/en.json @@ -14969,7 +14969,20 @@ "titleManualForcePush_other": "Force push {{count}} local commits with lease to update {{upstreamName}}.", "titleUnpublishedForcePushBranch": "Force push this branch with lease and set an upstream if needed.", "titleUnpublishedForcePushCount_one": "Force push {{count}} branch commit with lease and set an upstream if needed.", - "titleUnpublishedForcePushCount_other": "Force push {{count}} branch commits with lease and set an upstream if needed." + "titleUnpublishedForcePushCount_other": "Force push {{count}} branch commits with lease and set an upstream if needed.", + "statusConflicts": "Conflicts", + "statusNothingStaged": "Nothing staged", + "statusNeedsMessage": "Needs message", + "statusNotPublished": "Not published", + "statusNoBranch": "No branch", + "statusUpToDate": "Up to date", + "statusSetsUpstream": "Sets upstream", + "statusMayFail": "May fail", + "statusPublished": "Published", + "statusStashFirst": "Stash first", + "statusReplaces": "Replaces ↓{{behind}}", + "statusCommitFirst": "Commit first", + "statusReviewOpen": "{{shortLabel}} open" } }, "primary": { diff --git a/src/shared/source-control/dropdown/source-control-dropdown-commit-items.ts b/src/shared/source-control/dropdown/source-control-dropdown-commit-items.ts index a3a8e50ba14..45e091a1fb9 100644 --- a/src/shared/source-control/dropdown/source-control-dropdown-commit-items.ts +++ b/src/shared/source-control/dropdown/source-control-dropdown-commit-items.ts @@ -1,6 +1,9 @@ // Share commit blockers across Commit, Commit & Push, and Commit & Sync so disabled reasons agree. -import type { CommitDisabledReason } from '../decisions/source-control-commit-eligibility' +import { + COMMIT_MESSAGE_REQUIRED_REASON, + type CommitDisabledReason +} from '../decisions/source-control-commit-eligibility' import type { DropdownItem } from './source-control-dropdown-item-types' import type { DropdownActionContext } from './source-control-dropdown-action-context' @@ -26,6 +29,20 @@ export type CommitDropdownCopy = { commitThenPullPush: string // Eligibility compares the English reasons, so copy translates them only for display. commitDisabledReason: (reason: CommitDisabledReason) => string + commitDisabledStatus: (reason: CommitDisabledReason) => string + statusNotPublished: string + statusNoBranch: string +} + +export function englishCommitDisabledStatus(reason: CommitDisabledReason): string { + switch (reason) { + case 'Resolve conflicts before committing': + return 'Conflicts' + case 'Stage at least one file to commit': + return 'Nothing staged' + case COMMIT_MESSAGE_REQUIRED_REASON: + return 'Needs message' + } } export const ENGLISH_COMMIT_DROPDOWN_COPY: CommitDropdownCopy = { @@ -47,7 +64,10 @@ export const ENGLISH_COMMIT_DROPDOWN_COPY: CommitDropdownCopy = { publishBranchFirstToSync: 'Publish the branch first to sync commits', useCommitAndForcePush: 'Use Commit & Force Push — remote only has older copies of local commits', commitThenPullPush: 'Commit, then pull and push', - commitDisabledReason: (reason) => reason + commitDisabledReason: (reason) => reason, + commitDisabledStatus: englishCommitDisabledStatus, + statusNotPublished: 'Not published', + statusNoBranch: 'No branch' } export type CommitDropdownItems = { @@ -77,11 +97,20 @@ export function buildCommitDropdownItems( } = ctx const commitDisabledTitle = commitDisabledReason === null ? null : copy.commitDisabledReason(commitDisabledReason) + const commitDisabledStatus = + commitDisabledReason === null ? undefined : copy.commitDisabledStatus(commitDisabledReason) + // Branch blockers outrank commit blockers, matching the title ladders below. + const branchBlockedStatus = publishBlockedByDetachedHead + ? copy.statusNoBranch + : !upstreamLoading && !hasUpstream + ? copy.statusNotPublished + : undefined const commit: DropdownItem = { kind: 'commit', label: copy.commit, title: commitDisabledTitle ?? copy.commitStagedChanges, + status: commitDisabledStatus, disabled: !canCommit } @@ -108,6 +137,12 @@ export function buildCommitDropdownItems( kind: 'commit_push', label: shouldForcePushWithLease ? copy.commitForcePush : copy.commitPush, title: commitPushTitle, + status: + upstreamLoading || publishBlockedByPRLoading || publishBlockedByMergedPR + ? undefined + : !hasUpstream && hasOpenHostedReview && canPushLinkedReviewWithoutUpstream + ? commitDisabledStatus + : (branchBlockedStatus ?? commitDisabledStatus), // Match Push: without upstream, Commit & Push requires a known open-review head. disabled: globalBusy || @@ -145,6 +180,10 @@ export function buildCommitDropdownItems( kind: 'commit_sync', label: copy.commitSync, title: commitSyncTitle, + status: + upstreamLoading || publishBlockedByPRLoading || publishBlockedByMergedPR + ? undefined + : (branchBlockedStatus ?? commitDisabledStatus), disabled: globalBusy || upstreamLoading || diff --git a/src/shared/source-control/dropdown/source-control-dropdown-item-types.ts b/src/shared/source-control/dropdown/source-control-dropdown-item-types.ts index ac0a2b288a5..896f0c391c2 100644 --- a/src/shared/source-control/dropdown/source-control-dropdown-item-types.ts +++ b/src/shared/source-control/dropdown/source-control-dropdown-item-types.ts @@ -32,6 +32,11 @@ export type DropdownItem = { title: string disabled: boolean hint?: string + // Short right-aligned state; `title` keeps the full sentence for screen readers. + status?: string + statusTone?: 'active' | 'warning' + // Nothing to do right now, but still clickable (counts can be stale until a fetch). + idle?: boolean variant?: 'default' | 'destructive' } diff --git a/src/shared/source-control/dropdown/source-control-dropdown-labels.ts b/src/shared/source-control/dropdown/source-control-dropdown-labels.ts index a24c58719bf..4df2193f00a 100644 --- a/src/shared/source-control/dropdown/source-control-dropdown-labels.ts +++ b/src/shared/source-control/dropdown/source-control-dropdown-labels.ts @@ -14,15 +14,16 @@ export function describeSyncCounts(ahead: number, behind: number): string { return `Pull ${behind}, push ${ahead}` } -export function formatCountLabel(base: string, count: number): string { - return count > 0 ? `${base} (${count})` : base +export function formatAheadStatus(ahead: number): string { + return `↑${ahead}` } -export function formatSyncLabel(base: string, ahead: number, behind: number): string { - if (ahead === 0 && behind === 0) { - return base - } - return `${base} (↓${behind} ↑${ahead})` +export function formatBehindStatus(behind: number): string { + return `↓${behind}` +} + +export function formatSyncStatus(ahead: number, behind: number): string { + return `↓${behind} ↑${ahead}` } export function formatForcePushTitle( diff --git a/src/shared/source-control/dropdown/source-control-dropdown-remote-copy.ts b/src/shared/source-control/dropdown/source-control-dropdown-remote-copy.ts index e8130c32f27..c2160c25104 100644 --- a/src/shared/source-control/dropdown/source-control-dropdown-remote-copy.ts +++ b/src/shared/source-control/dropdown/source-control-dropdown-remote-copy.ts @@ -64,6 +64,14 @@ export type RemoteDropdownCopy = { forcePushWithLease: (branchCommitsAhead: number | undefined, upstreamName?: string) => string manualForcePush: (ahead: number, behind: number, upstreamName?: string) => string unpublishedForcePush: (branchCommitsAhead: number | undefined) => string + statusUpToDate: string + statusSetsUpstream: string + statusNotPublished: string + statusNoBranch: string + statusMayFail: string + statusPublished: string + statusStashFirst: string + statusReplaces: (behind: number) => string } export const ENGLISH_REMOTE_DROPDOWN_COPY: RemoteDropdownCopy = { @@ -121,5 +129,13 @@ export const ENGLISH_REMOTE_DROPDOWN_COPY: RemoteDropdownCopy = { syncCounts: describeSyncCounts, forcePushWithLease: formatForcePushTitle, manualForcePush: formatManualForcePushTitle, - unpublishedForcePush: formatUnpublishedForcePushTitle + unpublishedForcePush: formatUnpublishedForcePushTitle, + statusUpToDate: 'Up to date', + statusSetsUpstream: 'Sets upstream', + statusNotPublished: 'Not published', + statusNoBranch: 'No branch', + statusMayFail: 'May fail', + statusPublished: 'Published', + statusStashFirst: 'Stash first', + statusReplaces: (behind) => `Replaces ↓${behind}` } diff --git a/src/shared/source-control/dropdown/source-control-dropdown-remote-items.ts b/src/shared/source-control/dropdown/source-control-dropdown-remote-items.ts index 997b30d3f65..3a657e4896e 100644 --- a/src/shared/source-control/dropdown/source-control-dropdown-remote-items.ts +++ b/src/shared/source-control/dropdown/source-control-dropdown-remote-items.ts @@ -1,9 +1,10 @@ import type { DropdownItem } from './source-control-dropdown-item-types' import type { DropdownActionContext } from './source-control-dropdown-action-context' import { - formatCountLabel, + formatAheadStatus, + formatBehindStatus, formatRebaseBaseRef, - formatSyncLabel + formatSyncStatus } from './source-control-dropdown-labels' import { ENGLISH_REMOTE_DROPDOWN_COPY, @@ -45,10 +46,40 @@ export function buildRemoteDropdownItems( shouldForcePushWithLease, pushLabelCount } = ctx + const remoteBlockedStatus = publishBlockedByDetachedHead + ? copy.statusNoBranch + : !upstreamLoading && !hasUpstream + ? copy.statusNotPublished + : undefined + // Pull-side counts can be stale until a fetch, and these actions fetch first, so they stay clickable. + const incomingStatus = (incoming: string | undefined): Partial => { + if (remoteBlockedStatus || upstreamLoading) { + return { status: remoteBlockedStatus } + } + return incoming + ? { status: incoming, statusTone: 'active' } + : { status: copy.statusUpToDate, idle: true } + } + const pushIsLocalNoOp = + hasUpstream && + !upstreamLoading && + !shouldForcePushWithLease && + !canPushUntrackedHostedReview && + ahead === 0 + const forcePushIsLocalNoOp = hasUpstream && !upstreamLoading && pushLabelCount === 0 const push: DropdownItem = { kind: 'push', - label: formatCountLabel(copy.push, ahead), + label: copy.push, + ...(publishBlockedByDetachedHead + ? { status: copy.statusNoBranch } + : pushBlockedByOpenHostedReviewTarget || upstreamLoading || canPushUntrackedHostedReview + ? {} + : !hasUpstream + ? { status: copy.statusSetsUpstream } + : ahead > 0 + ? { status: formatAheadStatus(ahead), statusTone: 'active' as const } + : { status: copy.statusUpToDate }), title: publishBlockedByDetachedHead ? copy.checkOutBranchToPush : pushBlockedByOpenHostedReviewTarget @@ -69,12 +100,25 @@ export function buildRemoteDropdownItems( : copy.nothingToPush : copy.pushCount(ahead), // Push can set upstream and coexist with force-with-lease; detached HEAD and unknown review targets still block it. - disabled: globalBusy || publishBlockedByDetachedHead || pushBlockedByOpenHostedReviewTarget + disabled: + globalBusy || + publishBlockedByDetachedHead || + pushBlockedByOpenHostedReviewTarget || + pushIsLocalNoOp } const forcePush: DropdownItem = { kind: 'force_push', - label: formatCountLabel(copy.forcePush, pushLabelCount), + label: copy.forcePush, + ...(publishBlockedByDetachedHead + ? { status: copy.statusNoBranch } + : pushBlockedByOpenHostedReviewTarget || upstreamLoading || !hasUpstream + ? {} + : pushLabelCount === 0 + ? { status: copy.statusUpToDate } + : behind > 0 && !shouldForcePushWithLease + ? { status: copy.statusReplaces(behind), statusTone: 'warning' as const } + : { status: formatAheadStatus(pushLabelCount), statusTone: 'active' as const }), title: publishBlockedByDetachedHead ? copy.checkOutBranchToForcePush : pushBlockedByOpenHostedReviewTarget @@ -91,12 +135,19 @@ export function buildRemoteDropdownItems( ? copy.forcePushWithLease(branchCommitsAhead, upstreamStatus?.upstreamName) : copy.manualForcePush(pushLabelCount, behind, upstreamStatus?.upstreamName), // Match Push target safety; force-with-lease must not push the wrong review head. - disabled: globalBusy || publishBlockedByDetachedHead || pushBlockedByOpenHostedReviewTarget + disabled: + globalBusy || + publishBlockedByDetachedHead || + pushBlockedByOpenHostedReviewTarget || + forcePushIsLocalNoOp } const pull: DropdownItem = { kind: 'pull', - label: formatCountLabel(copy.pull, behind), + label: copy.pull, + ...incomingStatus( + behind > 0 && !shouldForcePushWithLease ? formatBehindStatus(behind) : undefined + ), title: upstreamLoading ? copy.checkingBranchStatus : publishBlockedByPRLoading @@ -117,7 +168,16 @@ export function buildRemoteDropdownItems( const fastForward: DropdownItem = { kind: 'fast_forward', - label: formatCountLabel(copy.fastForward, behind), + label: copy.fastForward, + ...(behind > 0 && + ahead > 0 && + !shouldForcePushWithLease && + !remoteBlockedStatus && + !upstreamLoading + ? { status: copy.statusMayFail, statusTone: 'warning' as const } + : incomingStatus( + behind > 0 && !shouldForcePushWithLease ? formatBehindStatus(behind) : undefined + )), title: upstreamLoading ? copy.checkingBranchStatus : publishBlockedByPRLoading @@ -140,7 +200,10 @@ export function buildRemoteDropdownItems( const sync: DropdownItem = { kind: 'sync', - label: formatSyncLabel(copy.sync, ahead, behind), + label: copy.sync, + ...(shouldForcePushWithLease + ? {} + : incomingStatus(ahead > 0 || behind > 0 ? formatSyncStatus(ahead, behind) : undefined)), title: upstreamLoading ? copy.checkingBranchStatus : publishBlockedByPRLoading @@ -178,6 +241,10 @@ export function buildRemoteDropdownItems( } return copy.rebaseWithLatestFrom(rebaseBaseLabel) })(), + status: + rebaseBaseLabel && hasRemoteBaseRef && hasDirtyLocalChanges + ? copy.statusStashFirst + : undefined, disabled: globalBusy || !rebaseBaseRef || !hasRemoteBaseRef } @@ -198,6 +265,8 @@ export function buildRemoteDropdownItems( : publishBlockedByDetachedHead ? copy.publishNoBranch : copy.publishBranch, + // Detached HEAD already reads "No Branch" in the label. + status: hasUpstream && !upstreamLoading ? copy.statusPublished : undefined, title: upstreamLoading ? copy.checkingBranchStatus : publishBlockedByPRLoading diff --git a/src/shared/source-control/dropdown/source-control-dropdown-status.test.ts b/src/shared/source-control/dropdown/source-control-dropdown-status.test.ts new file mode 100644 index 00000000000..2ca741418ff --- /dev/null +++ b/src/shared/source-control/dropdown/source-control-dropdown-status.test.ts @@ -0,0 +1,70 @@ +import { describe, expect, it } from 'vitest' +import type { DropdownActionInputs } from './source-control-dropdown-item-types' +import { deriveDropdownActionContext } from './source-control-dropdown-action-context' +import { buildRemoteDropdownItems } from './source-control-dropdown-remote-items' +import { buildCommitDropdownItems } from './source-control-dropdown-commit-items' + +function inputs(overrides: Partial): DropdownActionInputs { + return { + stagedCount: 0, + hasUnstagedChanges: false, + hasStageableChanges: false, + hasPartiallyStagedChanges: false, + hasMessage: false, + hasUnresolvedConflicts: false, + isCommitting: false, + isRemoteOperationActive: false, + upstreamStatus: { hasUpstream: true, upstreamName: 'origin/feature', ahead: 0, behind: 0 }, + hasCurrentBranch: true, + rebaseBaseRef: 'origin/main', + ...overrides + } +} + +function build(overrides: Partial) { + const ctx = deriveDropdownActionContext(inputs(overrides)) + return { ...buildRemoteDropdownItems(ctx), ...buildCommitDropdownItems(ctx) } +} + +describe('dropdown row status', () => { + it('moves counts out of labels and disables only the local push no-ops', () => { + const upToDate = build({}) + expect(upToDate.push).toMatchObject({ label: 'Push', status: 'Up to date', disabled: true }) + expect(upToDate.forcePush).toMatchObject({ status: 'Up to date', disabled: true }) + // Counts can be stale until a fetch, so fetching actions stay clickable. + expect(upToDate.pull).toMatchObject({ status: 'Up to date', idle: true, disabled: false }) + expect(upToDate.sync).toMatchObject({ status: 'Up to date', idle: true, disabled: false }) + + const diverged = build({ + upstreamStatus: { hasUpstream: true, upstreamName: 'origin/feature', ahead: 1, behind: 3 } + }) + expect(diverged.push).toMatchObject({ label: 'Push', status: '↑1', disabled: false }) + expect(diverged.forcePush).toMatchObject({ status: 'Replaces ↓3', statusTone: 'warning' }) + expect(diverged.pull).toMatchObject({ label: 'Pull', status: '↓3' }) + expect(diverged.fastForward.status).toBe('May fail') + expect(diverged.sync).toMatchObject({ label: 'Sync', status: '↓3 ↑1' }) + }) + + it('explains unpublished branches with staged files', () => { + const items = build({ + stagedCount: 2, + upstreamStatus: { hasUpstream: false, ahead: 0, behind: 0 } + }) + expect(items.commit.status).toBe('Needs message') + expect(items.commitPush.status).toBe('Not published') + expect(items.push.status).toBe('Sets upstream') + expect(items.pull).toMatchObject({ status: 'Not published', disabled: true }) + expect(items.rebase.status).toBe('Stash first') + }) + + it('reports detached HEAD as no branch', () => { + const items = build({ + hasCurrentBranch: false, + upstreamStatus: { hasUpstream: false, ahead: 0, behind: 0 } + }) + expect(items.commit.status).toBe('Nothing staged') + expect(items.commitSync.status).toBe('No branch') + expect(items.push).toMatchObject({ status: 'No branch', disabled: true }) + expect(items.sync.status).toBe('No branch') + }) +})