Clean up folder Source Control cards and add Remove from Parent (#40850)

* wip(folder-sc): card header cleanup and Remove from Parent in card menu

Work in progress handed to a Codex session; see ~/orca-qa/folder-sc-card/handoff-codex.md.

* test(source-control): cover collapsed folder card identity

* Keep folder card controls usable while status is unavailable

* Retain branch before card body mounts and allow conflict rows to grow

* Preserve source control label size and folder card parent actions
This commit is contained in:
Brennan Benson
2026-11-10 12:58:29 -08:00
committed by GitHub
parent d5759e67a2
commit 6d3d8245b2
13 changed files with 420 additions and 238 deletions
@@ -158,17 +158,20 @@ async function render(visible = true) {
)
}
it('labels same-repo sections by worktree name and a detached section by its HEAD', async () => {
it('identifies same-repo cards by name and shows their branch when collapsed', async () => {
const [onBranch, detached] = setup(2)
useAppStore.setState({
worktreesByRepo: { repo: [onBranch!, { ...detached!, branch: '', head: 'abc1234def' }] }
})
await render()
expect(
[...container.querySelectorAll('section button[aria-expanded]')].map(
(toggle) => toggle.textContent
)
).toEqual(['ChildChild 0feature-0', 'ChildChild 1Detached HEAD · abc1234'])
const toggles = [
...container.querySelectorAll<HTMLButtonElement>('section button[aria-expanded]')
]
expect(toggles.map((toggle) => toggle.textContent)).toEqual(['ChildChild 0', 'ChildChild 1'])
expect([...container.querySelectorAll('section')].map((section) => section.textContent)).toEqual([
'ChildChild 0feature-0',
'ChildChild 1Detached HEAD · abc1234'
])
})
function ScopedStatusObserver({ owner }: { owner: SourceControlScope }) {
@@ -26,6 +26,8 @@ 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'
import { useSectionOnScreen } from './source-control/panel/section-viewport-presence'
@@ -112,6 +114,7 @@ const WorktreeSection = memo(
: null
)
const panel = useMemo(() => <SourceControlPanel />, [])
const [actionsSlot, setActionsSlot] = useState<HTMLDivElement | null>(null)
const identity = getWorktreeGitIdentityDisplay(owner.worktree)
return (
<section
@@ -131,8 +134,15 @@ const WorktreeSection = memo(
behind={remote?.behind}
changeCount={entries.length}
expanded={isExpanded}
showBranchInHeader={!bodyShown || !bodyMounted || isFolderRepo(owner.repo)}
actions={
isExpanded && (!bodyShown || !bodyMounted || isFolderRepo(owner.repo)) ? (
<SourceControlHeaderOverflowMenu worktree={owner.worktree} />
) : null
}
onToggle={() => setExpanded(!isExpanded)}
onOpen={() => useAppStore.getState().setActiveWorktree(id, owner.executionHostId)}
actionsSlotRef={setActionsSlot}
/>
{isExpanded &&
(!connected ? (
@@ -154,9 +164,11 @@ const WorktreeSection = memo(
// A read error renders the body's existing failure banner with Retry.
<div hidden={!bodyShown}>
<OverlayActivityOwner.Provider value={onOverlayActivity}>
<SourceControlScopeProvider owner={owner} active={bodyActive}>
{panel}
</SourceControlScopeProvider>
<SourceControlHeaderActionsSlot.Provider value={bodyShown ? actionsSlot : null}>
<SourceControlScopeProvider owner={owner} active={bodyActive}>
{panel}
</SourceControlScopeProvider>
</SourceControlHeaderActionsSlot.Provider>
</OverlayActivityOwner.Provider>
</div>
)}
@@ -36,6 +36,7 @@ function Cards() {
expanded
onToggle={() => {}}
onOpen={() => {}}
actionsSlotRef={() => {}}
/>
<SectionBody files={['src/main/index.ts', 'src/renderer/App.tsx', 'README.md']} />
</section>
@@ -48,6 +49,7 @@ function Cards() {
expanded
onToggle={() => {}}
onOpen={() => {}}
actionsSlotRef={() => {}}
/>
<SectionBody files={['package.json']} />
</section>
@@ -59,6 +61,7 @@ function Cards() {
expanded={false}
onToggle={() => {}}
onOpen={() => {}}
actionsSlotRef={() => {}}
/>
</section>
</div>
@@ -82,6 +85,7 @@ export const narrow = defineFixture({
expanded={false}
onToggle={() => {}}
onOpen={() => {}}
actionsSlotRef={() => {}}
/>
</section>
</div>
@@ -15,8 +15,31 @@ 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. */
actionsSlotRef: (element: HTMLDivElement | null) => void
}
function AheadBehind({ ahead, behind }: { ahead?: number; behind?: number }): React.JSX.Element {
return (
<>
{!!ahead && (
<span className="flex shrink-0 items-center tabular-nums">
<ArrowUp className="size-3" />
{ahead}
</span>
)}
{!!behind && (
<span className="flex shrink-0 items-center tabular-nums">
<ArrowDown className="size-3" />
{behind}
</span>
)}
</>
)
}
export function FolderWorktreeSectionHeader({
@@ -27,86 +50,101 @@ export function FolderWorktreeSectionHeader({
behind,
changeCount,
expanded,
showBranchInHeader = !expanded,
actions,
onToggle,
onOpen
onOpen,
actionsSlotRef
}: FolderWorktreeSectionHeaderProps): React.JSX.Element {
const t = useTranslate()
const openLabel = t(
'auto.components.rightSidebar.FolderWorkspaceSourceControl.openWorktree',
'Open this worktree'
)
const showWorktreeName = !!worktreeName && worktreeName !== branch
// Expanded cards show the branch once, in the body's picker; collapsed cards have no body.
const showSummaryRow = showBranchInHeader && (!!branch || !!ahead || !!behind || changeCount > 0)
return (
// Pinned within its own card, above the panel's sticky COMMITS dock.
<div
className={`sticky top-0 z-20 flex items-center gap-1 bg-card pr-1 ${expanded ? 'border-b border-input' : ''}`}
className={`group/card-header sticky top-0 z-20 flex flex-col gap-0.5 bg-card py-1.5 pl-2 pr-1 text-xs hover:bg-accent ${expanded ? 'border-b border-input' : ''}`}
>
<button
type="button"
aria-expanded={expanded}
onClick={onToggle}
className="flex min-w-0 flex-1 flex-col gap-0.5 py-1.5 pl-2 text-left text-xs hover:bg-accent focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring"
>
<span className="flex w-full min-w-0 items-center gap-1.5">
<span className="flex min-h-5 w-full min-w-0 items-center gap-1.5">
{/* Its ::after covers the header so any empty space toggles; the other controls sit above it. */}
<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"
>
<ChevronRight
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. */}
{worktreeName && worktreeName !== branch && (
<span
title={worktreeName}
className="min-w-0 flex-1 basis-0 truncate text-muted-foreground"
>
{showWorktreeName && (
<span className="min-w-0 truncate text-muted-foreground" title={worktreeName}>
{worktreeName}
</span>
)}
{changeCount > 0 && (
<span className="ml-auto shrink-0 rounded-full bg-muted px-1.5 text-2xs text-foreground">
{changeCount}
</button>
<Tooltip>
<TooltipTrigger asChild>
<Button
variant="ghost"
size="icon"
className="relative z-10 -my-0.5 size-5 shrink-0"
onClick={onOpen}
aria-label={openLabel}
>
<ArrowUpRight className="size-3.5 text-muted-foreground group-hover/card-header:text-foreground" />
</Button>
</TooltipTrigger>
<TooltipContent>{openLabel}</TooltipContent>
</Tooltip>
<span className="min-w-0 flex-1" />
{expanded && (
<span className="flex shrink-0 items-center gap-1 text-muted-foreground">
<AheadBehind ahead={ahead} behind={behind} />
</span>
)}
<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" title={branch}>
{branch}
</span>
</span>
)}
</span>
{(branch || !!ahead || !!behind) && (
<span className="flex w-full min-w-0 items-center gap-1 pl-[1.625rem] text-muted-foreground">
{branch && (
<span
title={branch}
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>
)}
{!!ahead && (
<span className="ml-auto flex shrink-0 items-center">
<ArrowUp className="size-3" />
{ahead}
</span>
)}
{!!behind && (
<span className={`flex shrink-0 items-center ${ahead ? '' : 'ml-auto'}`}>
<ArrowDown className="size-3" />
{behind}
<span className="ml-auto flex shrink-0 items-center gap-1">
{!expanded && <AheadBehind ahead={ahead} behind={behind} />}
{!expanded && changeCount > 0 && (
<span className="text-2xs tabular-nums">
{t(
'auto.components.rightSidebar.FolderWorkspaceSourceControl.changeCount',
'{{count}} changes',
{ count: changeCount, defaultValue_one: '{{count}} change' }
)}
</span>
)}
</span>
)}
</button>
<Tooltip>
<TooltipTrigger asChild>
<Button
variant="ghost"
size="icon"
className="size-6 shrink-0"
onClick={onOpen}
aria-label={openLabel}
>
<ArrowUpRight className="size-3.5" />
</Button>
</TooltipTrigger>
<TooltipContent>{openLabel}</TooltipContent>
</Tooltip>
</span>
)}
</div>
)
}
@@ -3,6 +3,7 @@ import { ChevronDown } from 'lucide-react'
import { cn } from '@/lib/class-names'
import { Button } from '@/components/ui/button'
import { useTranslate } from '@/i18n/use-translate'
import { useSourceControlScope } from '../panel/worktree-scope'
export function SectionHeader({
label,
@@ -23,22 +24,27 @@ export function SectionHeader({
actions?: React.ReactNode
}): React.JSX.Element {
const t = useTranslate()
// Folder cards keep the gap above the first file equal to the one below the last.
const compact = useSourceControlScope() !== null
// Share the rounded container so hover styling spans the whole row.
return (
<div className="pl-1 pr-3 pt-3 pb-1">
<div className={cn('pl-1 pr-3 pt-3', compact ? 'pb-0' : 'pb-1')}>
<div className="group/section flex items-center gap-x-1 rounded-md pr-1 hover:bg-accent hover:text-accent-foreground">
<Button
type="button"
variant="ghost"
size="xs"
className="h-auto min-h-6 min-w-0 flex-1 justify-start gap-x-1 gap-y-0 py-0.5 text-left font-semibold uppercase tracking-wider text-foreground/70 group-hover/section:text-accent-foreground"
size={compact ? 'chip' : 'xs'}
className={cn(
'h-auto min-w-0 flex-1 justify-start text-left',
compact ? 'min-h-4' : 'min-h-6'
)}
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-xs 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}
@@ -59,7 +65,9 @@ export function SectionHeader({
)}
</span>
</Button>
<div className="ml-auto flex shrink-0 items-center justify-end">{actions}</div>
<div className={cn('ml-auto flex shrink-0 items-center justify-end', compact && '-my-1')}>
{actions}
</div>
</div>
</div>
)
@@ -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
@@ -103,6 +103,7 @@ export function SourceControlBranchContextRow({
headControl,
manualReviewUrl,
branchLineTotal,
reviewControl,
onChangeBaseRef,
onRetry
}: {
@@ -112,6 +113,7 @@ export function SourceControlBranchContextRow({
headControl?: React.ReactNode
manualReviewUrl?: string | null
branchLineTotal?: GitBranchLineTotal | null
reviewControl?: React.ReactNode
onChangeBaseRef: () => void
onRetry: () => void
}): React.JSX.Element | null {
@@ -124,8 +126,11 @@ export function SourceControlBranchContextRow({
return null
}
return (
<div className="min-w-0 text-[11px] text-muted-foreground">
{headControl ?? <HeadIdentity display={headDisplay} />}
<div className="flex min-w-0 items-center gap-1.5 text-[11px] text-muted-foreground">
<span className="min-w-0 flex-1">
{headControl ?? <HeadIdentity display={headDisplay} />}
</span>
{reviewControl}
</div>
)
}
@@ -159,7 +164,12 @@ export function SourceControlBranchContextRow({
onChangeBaseRef={onChangeBaseRef}
changeBaseTitle={changeBaseTitle}
leading={<Loader2 className="size-3 shrink-0 animate-spin" aria-hidden="true" />}
trailing={<ManualReviewLinkButton url={manualReviewUrl} />}
trailing={
<>
<ManualReviewLinkButton url={manualReviewUrl} />
{reviewControl}
</>
}
/>
<span className="sr-only">
{t('auto.components.right.sidebar.SourceControl.11b5dd8e41', 'Comparing against')}
@@ -189,6 +199,7 @@ export function SourceControlBranchContextRow({
label={t('auto.components.right.sidebar.SourceControl.286dbda4d6', 'Retry')}
onClick={onRetry}
/>
{reviewControl}
</>
}
/>
@@ -224,6 +235,7 @@ export function SourceControlBranchContextRow({
<>
{compareStatNodes}
<ManualReviewLinkButton url={manualReviewUrl} />
{reviewControl}
</>
}
headTrailing={<SourceControlBranchLineTotalChip branchLineTotal={branchLineTotal} />}
@@ -0,0 +1,8 @@
import { createContext, useContext } from 'react'
// A folder card's header hosts its panel's filter and overflow buttons; null while the card is collapsed.
export const SourceControlHeaderActionsSlot = createContext<HTMLElement | null>(null)
export function useSourceControlHeaderActionsSlot(): HTMLElement | null {
return useContext(SourceControlHeaderActionsSlot)
}
@@ -1,5 +1,14 @@
import React from 'react'
import { List, ListTree, MessageSquare, MoreHorizontal, RefreshCw, Settings2 } from 'lucide-react'
import {
List,
ListTree,
MessageSquare,
MoreHorizontal,
RefreshCw,
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'
@@ -11,17 +20,11 @@ import {
DropdownMenuTrigger
} from '@/components/ui/dropdown-menu'
import { useTranslate } from '@/i18n/use-translate'
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
@@ -30,10 +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')
@@ -46,13 +59,13 @@ export function SourceControlHeaderOverflowMenu({
type="button"
variant="ghost"
size="icon-xs"
className="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>
@@ -64,31 +77,58 @@ 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}
{ownerWorktree ? (
<>
{panelActions ? <DropdownMenuSeparator /> : null}
{/* Same unlink as the sidebar's Parent & Children menu; the worktree itself stays. */}
<DropdownMenuItem
onSelect={() =>
void unnestWorktrees([ownerWorktree], useAppStore.getState().updateWorktreeLineage)
}
>
<Unlink className="size-3.5" />
{t('auto.components.sidebar.WorktreeContextMenu.579b1a8e61', 'Remove from Parent')}
</DropdownMenuItem>
</>
) : null}
@@ -1,5 +1,6 @@
import { ImeInput } from '@/lib/text-input/ime/ime-text-field'
import React, { useCallback, useEffect, useRef } from 'react'
import { createPortal } from 'react-dom'
import { Search, X } from 'lucide-react'
import type { GitBranchCompareSummary } from '../../../../../../shared/git/diff/git-diff-compare-types'
import type { GitBranchLineTotal } from '../../../../../../shared/git/status/git-status-types'
@@ -18,6 +19,8 @@ import {
import { SourceControlBranchContextRow } from './branch-context-row'
import { shouldShowSourceControlBranchContextChrome } from './branch-context-stats'
import { SourceControlHeaderOverflowMenu } from './header-overflow-menu'
import { useSourceControlHeaderActionsSlot } from './header-actions-slot'
import { useSourceControlScope } from './worktree-scope'
type SourceControlHeaderToolbarProps = {
filterQuery: string
@@ -61,7 +64,7 @@ function renderOverflowMenu(
| 'onExpandNotes'
>
): React.JSX.Element {
return <SourceControlHeaderOverflowMenu {...props} />
return <SourceControlHeaderOverflowMenu panelActions={props} />
}
export function SourceControlHeaderToolbar({
@@ -93,6 +96,8 @@ export function SourceControlHeaderToolbar({
branchLineTotal
}: SourceControlHeaderToolbarProps): React.JSX.Element {
const t = useTranslate()
const embedded = useSourceControlScope() !== null
const actionsSlot = useSourceControlHeaderActionsSlot()
const filterInputRef = useRef<HTMLInputElement>(null)
const normalizedFilter = filterQuery.trim()
const showCollapsedToolbar = !filterExpanded
@@ -134,6 +139,139 @@ export function SourceControlHeaderToolbar({
})
: t('auto.components.right.sidebar.SourceControl.b3c8f1a902', 'Filter files by name')
const reviewControl = hostedReview ? (
<HostedReviewToolbarLink
review={hostedReview}
compact={embedded}
onOpenHostedReviewInChecks={onOpenHostedReviewInChecks}
/>
) : suppressedGitHubPRNumber !== null ? (
<SuppressedGitHubPRToolbar
number={suppressedGitHubPRNumber}
onRelink={onRelinkSuppressedGitHubPR}
/>
) : visibleCreatePrHeaderAction ? (
<CreatePrHeaderButton
action={visibleCreatePrHeaderAction}
isCreatePrIntentInFlight={isCreatePrIntentInFlight}
isCreatingPr={isCreatingPr}
onClick={onCreatePrHeaderClick}
/>
) : null
const filterToggle = (
<button
type="button"
data-testid="source-control-filter-toggle"
className={cn(
'relative inline-flex shrink-0 items-center justify-center rounded-sm text-muted-foreground transition-colors hover:bg-accent hover:text-foreground',
embedded ? 'size-6' : 'size-7',
(normalizedFilter || (embedded && filterExpanded)) && 'bg-muted text-foreground'
)}
onClick={embedded && filterExpanded ? collapseFilter : expandFilter}
aria-label={filterToggleTitle}
title={filterToggleTitle}
aria-expanded={embedded ? filterExpanded : false}
>
<Search className="size-3.5" />
{normalizedFilter ? (
<span className="absolute right-1 top-1 size-1.5 rounded-full bg-foreground" />
) : null}
</button>
)
const filterRow = (
<>
{/* Give expanded search the row so PR links and overflow controls do not squeeze typing. */}
<div className="flex min-w-0 w-full flex-1 items-center gap-1.5">
<Search className="size-3.5 shrink-0 text-muted-foreground" />
<ImeInput
ref={filterInputRef}
data-testid="source-control-filter-input"
type="text"
value={filterQuery}
onChange={(event) => onFilterQueryChange(event.target.value)}
onKeyDown={(event) => {
if (event.key === 'Escape') {
event.preventDefault()
collapseFilter()
}
}}
placeholder={t('auto.components.right.sidebar.SourceControl.c35baf2f1e', 'Filter files…')}
className="min-w-0 w-full flex-1 bg-transparent text-xs text-foreground outline-none placeholder:text-muted-foreground"
aria-label={t('auto.components.right.sidebar.SourceControl.c35baf2f1e', 'Filter files…')}
/>
</div>
<Button
type="button"
variant="ghost"
size="icon-xs"
className="size-7 shrink-0 text-muted-foreground hover:text-foreground"
aria-label={t(
'auto.components.right.sidebar.SourceControl.d4f8c2a901',
'Clear and close filter'
)}
title={t(
'auto.components.right.sidebar.SourceControl.d4f8c2a901',
'Clear and close filter'
)}
onClick={clearAndCollapseFilter}
>
<X className="size-3.5" />
</Button>
</>
)
const showBranchContext = shouldShowSourceControlBranchContextChrome(
branchSummary,
compareBaseRef,
headDisplay
)
const branchContextRow = (reviewTrailing?: React.ReactNode) => (
<SourceControlBranchContextRow
summary={branchSummary}
compareBaseRef={compareBaseRef}
headDisplay={headDisplay}
headControl={headControl}
manualReviewUrl={manualReviewUrl}
branchLineTotal={branchLineTotal}
reviewControl={reviewTrailing}
onChangeBaseRef={onChangeBaseRef}
onRetry={onRefreshBranchCompare}
/>
)
if (embedded) {
// The card header owns filter and overflow; the PR control joins the compare row's base line.
const reviewRowShown = reviewControl !== null && !showBranchContext
return (
<>
{actionsSlot
? createPortal(
<>
{filterToggle}
{renderOverflowMenu(overflowProps)}
</>,
actionsSlot
)
: null}
{filterExpanded || showBranchContext || reviewRowShown ? (
<div className="flex flex-col gap-1 border-b border-border px-3 py-1.5">
{filterExpanded ? (
<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 ? (
<div className="flex min-w-0 items-center">{reviewControl}</div>
) : null}
</div>
) : null}
</>
)
}
return (
<div className="border-b border-border px-3 pt-1.5 pb-1">
<div
@@ -142,112 +280,20 @@ export function SourceControlHeaderToolbar({
>
{showCollapsedToolbar ? (
<>
{hostedReview ? (
<HostedReviewToolbarLink
review={hostedReview}
onOpenHostedReviewInChecks={onOpenHostedReviewInChecks}
/>
) : suppressedGitHubPRNumber !== null ? (
<SuppressedGitHubPRToolbar
number={suppressedGitHubPRNumber}
onRelink={onRelinkSuppressedGitHubPR}
/>
) : visibleCreatePrHeaderAction ? (
<CreatePrHeaderButton
action={visibleCreatePrHeaderAction}
isCreatePrIntentInFlight={isCreatePrIntentInFlight}
isCreatingPr={isCreatingPr}
onClick={onCreatePrHeaderClick}
/>
) : (
<span className="min-w-0 flex-1" aria-hidden="true" />
)}
{reviewControl ?? <span className="min-w-0 flex-1" aria-hidden="true" />}
{(visibleCreatePrHeaderAction || suppressedGitHubPRNumber !== null) && !hostedReview ? (
// Pin filter/overflow right without stretching Create PR.
<span className="min-w-0 flex-1" aria-hidden="true" />
) : null}
<button
type="button"
data-testid="source-control-filter-toggle"
className={cn(
'relative inline-flex size-7 shrink-0 items-center justify-center rounded-sm text-muted-foreground transition-colors hover:bg-accent hover:text-foreground',
normalizedFilter && 'bg-muted text-foreground'
)}
onClick={expandFilter}
aria-label={filterToggleTitle}
title={filterToggleTitle}
aria-expanded={false}
>
<Search className="size-3.5" />
{normalizedFilter ? (
<span className="absolute right-1 top-1 size-1.5 rounded-full bg-foreground" />
) : null}
</button>
{filterToggle}
{renderOverflowMenu(overflowProps)}
</>
) : (
<>
{/* Give expanded search the row so PR links and overflow controls do not squeeze typing. */}
<div className="flex min-w-0 w-full flex-1 items-center gap-1.5">
<Search className="size-3.5 shrink-0 text-muted-foreground" />
<ImeInput
ref={filterInputRef}
data-testid="source-control-filter-input"
type="text"
value={filterQuery}
onChange={(event) => onFilterQueryChange(event.target.value)}
onKeyDown={(event) => {
if (event.key === 'Escape') {
event.preventDefault()
collapseFilter()
}
}}
placeholder={t(
'auto.components.right.sidebar.SourceControl.c35baf2f1e',
'Filter files…'
)}
className="min-w-0 w-full flex-1 bg-transparent text-xs text-foreground outline-none placeholder:text-muted-foreground"
aria-label={t(
'auto.components.right.sidebar.SourceControl.c35baf2f1e',
'Filter files…'
)}
/>
</div>
<Button
type="button"
variant="ghost"
size="icon-xs"
className="size-7 shrink-0 text-muted-foreground hover:text-foreground"
aria-label={t(
'auto.components.right.sidebar.SourceControl.d4f8c2a901',
'Clear and close filter'
)}
title={t(
'auto.components.right.sidebar.SourceControl.d4f8c2a901',
'Clear and close filter'
)}
onClick={clearAndCollapseFilter}
>
<X className="size-3.5" />
</Button>
</>
filterRow
)}
</div>
{shouldShowSourceControlBranchContextChrome(branchSummary, compareBaseRef, headDisplay) ? (
<div className="mt-1">
<SourceControlBranchContextRow
summary={branchSummary}
compareBaseRef={compareBaseRef}
headDisplay={headDisplay}
headControl={headControl}
manualReviewUrl={manualReviewUrl}
branchLineTotal={branchLineTotal}
onChangeBaseRef={onChangeBaseRef}
onRetry={onRefreshBranchCompare}
/>
</div>
) : null}
{showBranchContext ? <div className="mt-1">{branchContextRow()}</div> : null}
</div>
)
}
+4
View File
@@ -624,6 +624,10 @@
"worktreeCountLabel_one": "{{count}} worktree",
"worktreeCountLabel_other": "{{count}} worktrees"
},
"FolderWorkspaceSourceControl": {
"changeCount_one": "{{count}} change",
"changeCount_other": "{{count}} changes"
},
"FolderWorkspaceWorktreesPanel": {
"attachedCount_one": "{{count}} attached worktree",
"attachedCount_other": "{{count}} attached worktrees"
+2
View File
@@ -18872,6 +18872,8 @@
"reloaded": "Reloaded"
},
"FolderWorkspaceSourceControl": {
"changeCount_one": "{{count}} change",
"changeCount_other": "{{count}} changes",
"openWorktree": "Open this worktree",
"reconnect": "Reconnect to see this worktree’s changes."
},