mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 02:47:34 +00:00
Show Source Control menu rows on one line with a short status
This commit is contained in:
@@ -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?.() ?? (
|
||||
<Icon
|
||||
|
||||
@@ -196,7 +196,9 @@ export function PullDownMenu({ visible, anchorRef, groups, onClose }: PullDownMe
|
||||
disabled={action.disabled || action.loading}
|
||||
onPress={() => 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
|
||||
</Text>
|
||||
) : null}
|
||||
</View>
|
||||
{action.status ? (
|
||||
<Text style={styles.status} numberOfLines={1}>
|
||||
{action.status}
|
||||
</Text>
|
||||
) : null}
|
||||
{action.checked ? (
|
||||
<Check size={17} color={tint} strokeWidth={2.2} />
|
||||
) : 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']
|
||||
}
|
||||
}))
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 = (
|
||||
<DropdownMenuContent align="end" className="w-72 max-w-[calc(100vw-1rem)]">
|
||||
<DropdownMenuContent align="end" className="w-58 max-w-[calc(100vw-1rem)]">
|
||||
{dropdownItems.map((entry) =>
|
||||
entry.kind === 'separator' ? (
|
||||
<DropdownMenuSeparator key={entry.id} />
|
||||
) : (
|
||||
<div key={entry.kind}>
|
||||
<DropdownMenuItem
|
||||
aria-disabled={entry.disabled || undefined}
|
||||
variant={entry.variant}
|
||||
textValue={entry.label}
|
||||
aria-describedby={entry.disabled ? `${actionDescriptionId}-${entry.kind}` : undefined}
|
||||
onSelect={(event) => {
|
||||
if (entry.disabled) {
|
||||
event.preventDefault()
|
||||
return
|
||||
}
|
||||
onDropdownAction(entry.kind)
|
||||
}}
|
||||
>
|
||||
<span className="flex min-w-0 flex-col break-words">
|
||||
<span>{entry.label}</span>
|
||||
{!entry.disabled && (
|
||||
<span className="text-2xs text-muted-foreground">{entry.title}</span>
|
||||
<DropdownMenuItem
|
||||
key={entry.kind}
|
||||
className="min-h-7"
|
||||
aria-disabled={entry.disabled || undefined}
|
||||
aria-description={entry.title}
|
||||
variant={entry.variant}
|
||||
textValue={entry.label}
|
||||
onSelect={(event) => {
|
||||
if (entry.disabled) {
|
||||
event.preventDefault()
|
||||
return
|
||||
}
|
||||
onDropdownAction(entry.kind)
|
||||
}}
|
||||
>
|
||||
<span className={cn('min-w-0 truncate', entry.idle && 'text-muted-foreground')}>
|
||||
{entry.label}
|
||||
</span>
|
||||
{entry.status && (
|
||||
<span
|
||||
className={cn(
|
||||
'ml-auto shrink-0 pl-3 text-2xs whitespace-nowrap tabular-nums',
|
||||
entry.statusTone === 'warning'
|
||||
? 'text-status-warning-text'
|
||||
: entry.statusTone === 'active'
|
||||
? 'text-foreground'
|
||||
: 'text-muted-foreground'
|
||||
)}
|
||||
</span>
|
||||
</DropdownMenuItem>
|
||||
{entry.disabled && (
|
||||
<p
|
||||
id={`${actionDescriptionId}-${entry.kind}`}
|
||||
className="px-2.5 pb-1 text-2xs text-muted-foreground break-words"
|
||||
>
|
||||
{entry.title}
|
||||
</p>
|
||||
{entry.status}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</DropdownMenuItem>
|
||||
)
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
|
||||
+32
-1
@@ -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
|
||||
}
|
||||
)
|
||||
|
||||
+35
-1
@@ -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 }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+32
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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": {
|
||||
|
||||
@@ -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 ||
|
||||
|
||||
@@ -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'
|
||||
}
|
||||
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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}`
|
||||
}
|
||||
|
||||
@@ -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<DropdownItem> => {
|
||||
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
|
||||
|
||||
@@ -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>): 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<DropdownActionInputs>) {
|
||||
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')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user