Keep folder card controls usable while status is unavailable

This commit is contained in:
Brennan Benson
2026-11-10 11:06:08 -08:00
parent 0d0c8e1232
commit e17f0db177
8 changed files with 128 additions and 92 deletions
@@ -168,7 +168,6 @@ it('identifies same-repo cards by name and shows their branch when collapsed', a
...container.querySelectorAll<HTMLButtonElement>('section button[aria-expanded]')
]
expect(toggles.map((toggle) => toggle.textContent)).toEqual(['ChildChild 0', 'ChildChild 1'])
await act(async () => toggles.forEach((toggle) => toggle.click()))
expect([...container.querySelectorAll('section')].map((section) => section.textContent)).toEqual([
'ChildChild 0feature-0',
'ChildChild 1Detached HEAD · abc1234'
@@ -26,6 +26,7 @@ import {
SourceControlScopeProvider,
type SourceControlScope
} from './source-control/panel/worktree-scope'
import { SourceControlHeaderOverflowMenu } from './source-control/panel/header-overflow-menu'
import { SourceControlHeaderActionsSlot } from './source-control/panel/header-actions-slot'
import { useWorktreeGitStatusObservation } from './source-control/sync/use-worktree-git-status-observation'
import { useSourceControlWatchConsumer } from '@/hooks/source-control-watch-consumers'
@@ -133,6 +134,12 @@ const WorktreeSection = memo(
behind={remote?.behind}
changeCount={entries.length}
expanded={isExpanded}
showBranchInHeader={!bodyShown}
actions={
isExpanded && (!bodyShown || !bodyMounted) ? (
<SourceControlHeaderOverflowMenu worktree={owner.worktree} />
) : null
}
onToggle={() => setExpanded(!isExpanded)}
onOpen={() => useAppStore.getState().setActiveWorktree(id, owner.executionHostId)}
actionsSlotRef={setActionsSlot}
@@ -15,6 +15,8 @@ type FolderWorktreeSectionHeaderProps = {
behind?: number
changeCount: number
expanded: boolean
showBranchInHeader?: boolean
actions?: React.ReactNode
onToggle: () => void
onOpen: () => void
/** Receives the embedded panel's filter and overflow buttons while expanded. */
@@ -48,6 +50,8 @@ export function FolderWorktreeSectionHeader({
behind,
changeCount,
expanded,
showBranchInHeader = !expanded,
actions,
onToggle,
onOpen,
actionsSlotRef
@@ -59,7 +63,7 @@ export function FolderWorktreeSectionHeader({
)
const showWorktreeName = !!worktreeName && worktreeName !== branch
// Expanded cards show the branch once, in the body's picker; collapsed cards have no body.
const showSummaryRow = !expanded && (!!branch || !!ahead || !!behind || changeCount > 0)
const showSummaryRow = showBranchInHeader && (!!branch || !!ahead || !!behind || changeCount > 0)
return (
// Pinned within its own card, above the panel's sticky COMMITS dock.
<div
@@ -70,6 +74,9 @@ export function FolderWorktreeSectionHeader({
<button
type="button"
aria-expanded={expanded}
aria-label={[repoName, showWorktreeName ? worktreeName : null, branch]
.filter(Boolean)
.join(', ')}
onClick={onToggle}
className="flex min-w-0 items-center gap-1.5 text-left after:absolute after:inset-0 focus-visible:outline-none focus-visible:after:ring-1 focus-visible:after:ring-inset focus-visible:after:ring-ring"
>
@@ -77,10 +84,14 @@ export function FolderWorktreeSectionHeader({
className={`size-3 shrink-0 text-muted-foreground ${expanded ? 'rotate-90' : ''}`}
/>
<FolderGit2 className="size-3.5 shrink-0 text-muted-foreground" />
<span className="min-w-0 truncate text-[13px] font-semibold">{repoName}</span>
<span className="min-w-0 truncate text-[13px] font-semibold" title={repoName}>
{repoName}
</span>
{/* Same-repo worktrees are told apart by name, as main did. */}
{showWorktreeName && (
<span className="min-w-0 truncate text-muted-foreground">{worktreeName}</span>
<span className="min-w-0 truncate text-muted-foreground" title={worktreeName}>
{worktreeName}
</span>
)}
</button>
<Tooltip>
@@ -88,11 +99,11 @@ export function FolderWorktreeSectionHeader({
<Button
variant="ghost"
size="icon"
className="relative z-10 -my-0.5 size-5 shrink-0 text-muted-foreground group-hover/card-header:text-foreground"
className="relative z-10 -my-0.5 size-5 shrink-0"
onClick={onOpen}
aria-label={openLabel}
>
<ArrowUpRight className="size-3.5" />
<ArrowUpRight className="size-3.5 text-muted-foreground" />
</Button>
</TooltipTrigger>
<TooltipContent>{openLabel}</TooltipContent>
@@ -106,19 +117,23 @@ export function FolderWorktreeSectionHeader({
<div
ref={actionsSlotRef}
className="relative z-10 -my-1 flex shrink-0 items-center empty:hidden"
/>
>
{actions}
</div>
</span>
{showSummaryRow && (
<span className="flex w-full min-w-0 items-center gap-1 pl-[2.375rem] pr-1 text-muted-foreground">
{branch && (
<span className="flex min-w-0 items-center gap-1 rounded-full border border-input px-1.5">
<GitBranch className="size-3 shrink-0" />
<span className="truncate">{branch}</span>
<span className="truncate" title={branch}>
{branch}
</span>
</span>
)}
<span className="ml-auto flex shrink-0 items-center gap-1">
<AheadBehind ahead={ahead} behind={behind} />
{changeCount > 0 && (
{!expanded && <AheadBehind ahead={ahead} behind={behind} />}
{!expanded && changeCount > 0 && (
<span className="text-2xs tabular-nums">
{t(
'auto.components.rightSidebar.FolderWorkspaceSourceControl.changeCount',
@@ -33,19 +33,15 @@ export function SectionHeader({
<Button
type="button"
variant="ghost"
size="xs"
className={cn(
'h-auto min-w-0 flex-1',
compact ? 'min-h-4 py-0' : 'min-h-6 py-0.5',
'justify-start gap-x-1 gap-y-0 text-left font-semibold uppercase tracking-wider text-foreground/70 group-hover/section:text-accent-foreground'
)}
size={compact ? 'chip' : 'xs'}
className={cn('min-w-0 flex-1 justify-start text-left')}
onClick={onToggle}
aria-expanded={!isCollapsed}
>
<ChevronDown
className={cn('size-3.5 shrink-0 transition-transform', isCollapsed && '-rotate-90')}
/>
<span className="min-w-0 flex-1">
<span className="min-w-0 flex-1 text-2xs font-semibold uppercase tracking-wider text-foreground/70 group-hover/section:text-accent-foreground">
<span className="flex min-w-0 items-center gap-1">
<span className="min-w-0 truncate" title={label}>
{label}
@@ -14,6 +14,7 @@ import {
import { ActionButton } from './action-button'
import { SectionHeader } from './section-header'
import { SourceControlSectionFileList } from './section-file-list'
import { useSourceControlScope } from '../panel/worktree-scope'
import {
getSourceControlSectionViewAction,
type SourceControlDisplaySection,
@@ -89,6 +90,7 @@ export function SourceControlUncommittedSections(props: {
requestDiscardEntry: (entry: GitStatusEntry) => void
diffCommentCountByPath: Map<string, number>
}): React.JSX.Element {
const embedded = useSourceControlScope() !== null
const t = useTranslate()
return (
<>
@@ -176,35 +178,37 @@ export function SourceControlUncommittedSections(props: {
}
/>
{!isCollapsed && (
<SourceControlSectionFileList
treeRows={props.visibleTreeRowsBySection[id] ?? []}
listRows={props.visibleListRowsBySection[id] ?? []}
sourceControlViewMode={props.sourceControlViewMode}
fileListScrollElement={props.fileListScrollElement}
normalizedFilter={props.normalizedFilter}
isExecutingBulk={props.isExecutingBulk}
collapsedTreeDirs={props.collapsedTreeDirs}
toggleTreeDir={props.toggleTreeDir}
requestDiscardPaths={props.requestDiscardPaths}
handleStageAllPaths={props.handleStageAllPaths}
handleUnstagePaths={props.handleUnstagePaths}
expandedSubmoduleKeys={props.expandedSubmoduleKeys}
toggleSubmodule={props.toggleSubmodule}
currentWorktreeId={props.currentWorktreeId}
worktreePath={props.worktreePath}
selectedKeySet={props.selectedKeySet}
activeOpenRowKeys={props.activeOpenRowKeys}
handleSelect={props.handleSelect}
handleContextMenu={props.handleContextMenu}
revealInExplorer={props.revealInExplorer}
activeConnectionId={props.activeConnectionId}
handleOpenDiff={props.handleOpenDiff}
handleStage={props.handleStage}
handleResolveConflict={props.handleResolveConflict}
handleUnstage={props.handleUnstage}
requestDiscardEntry={props.requestDiscardEntry}
diffCommentCountByPath={props.diffCommentCountByPath}
/>
<div className={embedded ? 'py-px' : undefined}>
<SourceControlSectionFileList
treeRows={props.visibleTreeRowsBySection[id] ?? []}
listRows={props.visibleListRowsBySection[id] ?? []}
sourceControlViewMode={props.sourceControlViewMode}
fileListScrollElement={props.fileListScrollElement}
normalizedFilter={props.normalizedFilter}
isExecutingBulk={props.isExecutingBulk}
collapsedTreeDirs={props.collapsedTreeDirs}
toggleTreeDir={props.toggleTreeDir}
requestDiscardPaths={props.requestDiscardPaths}
handleStageAllPaths={props.handleStageAllPaths}
handleUnstagePaths={props.handleUnstagePaths}
expandedSubmoduleKeys={props.expandedSubmoduleKeys}
toggleSubmodule={props.toggleSubmodule}
currentWorktreeId={props.currentWorktreeId}
worktreePath={props.worktreePath}
selectedKeySet={props.selectedKeySet}
activeOpenRowKeys={props.activeOpenRowKeys}
handleSelect={props.handleSelect}
handleContextMenu={props.handleContextMenu}
revealInExplorer={props.revealInExplorer}
activeConnectionId={props.activeConnectionId}
handleOpenDiff={props.handleOpenDiff}
handleStage={props.handleStage}
handleResolveConflict={props.handleResolveConflict}
handleUnstage={props.handleUnstage}
requestDiscardEntry={props.requestDiscardEntry}
diffCommentCountByPath={props.diffCommentCountByPath}
/>
</div>
)}
</div>
)
@@ -190,7 +190,8 @@ export function useSourceControlSelection({
return
}
const container = containerRef.current
const panel = containerRef.current
const container = panel?.closest('[data-source-control-worktree]') ?? panel
const target = e.target
if (!container || !(target instanceof Node) || container.contains(target)) {
return
@@ -8,6 +8,7 @@ import {
Settings2,
Unlink
} from 'lucide-react'
import type { Worktree } from '../../../../../../shared/worktree/types'
import type { SourceControlViewMode } from '../../../../../../shared/ui-chrome-types'
import { Button } from '@/components/ui/button'
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'
@@ -23,16 +24,7 @@ import { useAppStore } from '@/store'
import { unnestWorktrees } from '../../../sidebar/workspace-actions/parenting/worktree-unnest'
import { useSourceControlScopeOwner } from './worktree-scope'
export function SourceControlHeaderOverflowMenu({
sourceControlViewMode,
viewModeToggleDisabled,
onToggleViewMode,
onChangeBaseRef,
onRefreshBranchCompare,
branchCompareRefreshDisabled,
diffCommentCount,
onExpandNotes
}: {
type PanelActions = {
sourceControlViewMode: SourceControlViewMode
viewModeToggleDisabled: boolean
onToggleViewMode: () => void
@@ -41,11 +33,20 @@ export function SourceControlHeaderOverflowMenu({
branchCompareRefreshDisabled: boolean
diffCommentCount: number
onExpandNotes: () => void
}
export function SourceControlHeaderOverflowMenu({
panelActions,
worktree
}: {
panelActions?: PanelActions
worktree?: Worktree
}): React.JSX.Element {
const t = useTranslate()
const scopeOwner = useSourceControlScopeOwner()
const ownerWorktree = worktree ?? scopeOwner?.worktree
const viewModeLabel =
sourceControlViewMode === 'tree'
panelActions?.sourceControlViewMode === 'tree'
? t('auto.components.right.sidebar.SourceControl.a91f8e2b01', 'View as list')
: t('auto.components.right.sidebar.SourceControl.b82e9f3c12', 'View as tree')
@@ -58,13 +59,13 @@ export function SourceControlHeaderOverflowMenu({
type="button"
variant="ghost"
size="icon-xs"
className={`${scopeOwner ? 'size-6' : 'size-7'} text-muted-foreground hover:text-foreground`}
className={ownerWorktree ? 'size-6' : 'size-7'}
aria-label={t(
'auto.components.right.sidebar.SourceControl.f71c4a8d90',
'More source control actions'
)}
>
<MoreHorizontal className="size-3.5" />
<MoreHorizontal className="size-3.5 text-muted-foreground" />
</Button>
</DropdownMenuTrigger>
</TooltipTrigger>
@@ -76,44 +77,54 @@ export function SourceControlHeaderOverflowMenu({
</TooltipContent>
</Tooltip>
<DropdownMenuContent align="end" className="min-w-[180px]">
<DropdownMenuItem disabled={viewModeToggleDisabled} onSelect={onToggleViewMode}>
{sourceControlViewMode === 'tree' ? (
<List className="size-3.5" />
) : (
<ListTree className="size-3.5" />
)}
{viewModeLabel}
</DropdownMenuItem>
<DropdownMenuItem onSelect={onChangeBaseRef}>
<Settings2 className="size-3.5" />
{t('auto.components.right.sidebar.SourceControl.476b77745b', 'Change Base Ref')}…
</DropdownMenuItem>
<DropdownMenuItem disabled={branchCompareRefreshDisabled} onSelect={onRefreshBranchCompare}>
<RefreshCw className="size-3.5" />
{t('auto.components.right.sidebar.SourceControl.ed34038d0d', 'Refresh branch compare')}
</DropdownMenuItem>
{diffCommentCount > 0 ? (
{panelActions ? (
<>
<DropdownMenuSeparator />
<DropdownMenuItem onSelect={onExpandNotes}>
<MessageSquare className="size-3.5" />
{t('auto.components.right.sidebar.SourceControl.cc474e0b8c', 'Notes')}
<span className="ml-auto text-[11px] tabular-nums text-muted-foreground">
{diffCommentCount}
</span>
<DropdownMenuItem
disabled={panelActions.viewModeToggleDisabled}
onSelect={panelActions.onToggleViewMode}
>
{panelActions.sourceControlViewMode === 'tree' ? (
<List className="size-3.5" />
) : (
<ListTree className="size-3.5" />
)}
{viewModeLabel}
</DropdownMenuItem>
<DropdownMenuItem onSelect={panelActions.onChangeBaseRef}>
<Settings2 className="size-3.5" />
{t('auto.components.right.sidebar.SourceControl.476b77745b', 'Change Base Ref')}…
</DropdownMenuItem>
<DropdownMenuItem
disabled={panelActions.branchCompareRefreshDisabled}
onSelect={panelActions.onRefreshBranchCompare}
>
<RefreshCw className="size-3.5" />
{t(
'auto.components.right.sidebar.SourceControl.ed34038d0d',
'Refresh branch compare'
)}
</DropdownMenuItem>
{panelActions.diffCommentCount > 0 ? (
<>
<DropdownMenuSeparator />
<DropdownMenuItem onSelect={panelActions.onExpandNotes}>
<MessageSquare className="size-3.5" />
{t('auto.components.right.sidebar.SourceControl.cc474e0b8c', 'Notes')}
<span className="ml-auto text-[11px] tabular-nums text-muted-foreground">
{panelActions.diffCommentCount}
</span>
</DropdownMenuItem>
</>
) : null}
</>
) : null}
{scopeOwner ? (
{ownerWorktree ? (
<>
<DropdownMenuSeparator />
{panelActions ? <DropdownMenuSeparator /> : null}
{/* Same unlink as the sidebar's Parent & Children menu; the worktree itself stays. */}
<DropdownMenuItem
onSelect={() =>
void unnestWorktrees(
[scopeOwner.worktree],
useAppStore.getState().updateWorktreeLineage
)
void unnestWorktrees([ownerWorktree], useAppStore.getState().updateWorktreeLineage)
}
>
<Unlink className="size-3.5" />
@@ -64,7 +64,7 @@ function renderOverflowMenu(
| 'onExpandNotes'
>
): React.JSX.Element {
return <SourceControlHeaderOverflowMenu {...props} />
return <SourceControlHeaderOverflowMenu panelActions={props} />
}
export function SourceControlHeaderToolbar({
@@ -142,6 +142,7 @@ export function SourceControlHeaderToolbar({
const reviewControl = hostedReview ? (
<HostedReviewToolbarLink
review={hostedReview}
compact={embedded}
onOpenHostedReviewInChecks={onOpenHostedReviewInChecks}
/>
) : suppressedGitHubPRNumber !== null ? (
@@ -257,7 +258,9 @@ export function SourceControlHeaderToolbar({
{filterExpanded || showBranchContext || reviewRowShown ? (
<div className="flex flex-col gap-1 border-b border-border px-3 py-1.5">
{filterExpanded ? (
<div className="flex min-w-0 items-center gap-1.5">{filterRow}</div>
<div className="mb-1.5 flex min-w-0 items-center gap-1.5 border-b border-border pb-1.5">
{filterRow}
</div>
) : null}
{showBranchContext ? branchContextRow(reviewControl) : null}
{reviewRowShown ? (