mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 02:47:34 +00:00
Merge main before editor hint validation
This commit is contained in:
+14
-1
@@ -12,9 +12,15 @@ vi.mock('@/lib/workspace/tabs/workspace-tab-commands', () => ({
|
||||
import { handleGuestWindowCloseMessage } from './browser-page-window-close'
|
||||
import { BROWSER_GUEST_WINDOW_CLOSE_CHANNEL } from '../../../../../shared/browser-guest-window-close'
|
||||
|
||||
function seedTab(pageId: string, isPinned = false, siblingPageIds: string[] = []): void {
|
||||
function seedTab(
|
||||
pageId: string,
|
||||
isPinned = false,
|
||||
siblingPageIds: string[] = [],
|
||||
browserAnnotationsByPageId: Record<string, unknown[]> = {}
|
||||
): void {
|
||||
storeState.value = {
|
||||
closeBrowserPage: closeBrowserPageMock,
|
||||
browserAnnotationsByPageId,
|
||||
browserTabsByWorktree: { 'wt-1': [{ id: 'ws-1' }] },
|
||||
browserPagesByWorkspace: { 'ws-1': [{ id: pageId }, ...siblingPageIds.map((id) => ({ id }))] },
|
||||
unifiedTabsByWorktree: {
|
||||
@@ -40,6 +46,13 @@ describe('window.close() from a browser page', () => {
|
||||
expect(dispatchMock).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('never discards unsent notes', () => {
|
||||
seedTab('page-n', false, [], { 'page-n': [{ id: 'note-1' }] })
|
||||
closeFrom('page-n', { back: false, forward: false })
|
||||
expect(dispatchMock).not.toHaveBeenCalled()
|
||||
expect(closeBrowserPageMock).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('closes only the calling page when its Orca tab holds other pages', () => {
|
||||
seedTab('page-e', false, ['page-sibling'])
|
||||
closeFrom('page-e', { back: false, forward: false })
|
||||
|
||||
@@ -32,7 +32,8 @@ export function handleGuestWindowCloseMessage(
|
||||
const tab = (state.unifiedTabsByWorktree[owner.worktreeId] ?? []).find(
|
||||
(candidate) => candidate.contentType === 'browser' && candidate.entityId === owner.workspaceId
|
||||
)
|
||||
if (tab?.isPinned) {
|
||||
// A script may not discard what the user pinned or left unsent; the page's notes are all it closes.
|
||||
if (tab?.isPinned || (state.browserAnnotationsByPageId[pageId]?.length ?? 0) > 0) {
|
||||
return
|
||||
}
|
||||
pagesOpenedByPage.delete(pageId)
|
||||
|
||||
+9
-6
@@ -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>
|
||||
)
|
||||
}
|
||||
|
||||
+13
-5
@@ -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>
|
||||
)
|
||||
|
||||
+33
-29
@@ -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
|
||||
|
||||
+15
-3
@@ -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)
|
||||
}
|
||||
+78
-38
@@ -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}
|
||||
|
||||
+143
-97
@@ -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>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ export default function PinnedTabCloseDialog(): React.JSX.Element {
|
||||
const [previousRequest, setPreviousRequest] = useState(request)
|
||||
|
||||
const tabLabel = request?.tabLabel.trim()
|
||||
const unsentNotes = request?.unsentNotes === true
|
||||
|
||||
// Reset new requests before paint without reviving a cancelled request’s checkbox state.
|
||||
if (request !== previousRequest) {
|
||||
@@ -53,16 +54,26 @@ export default function PinnedTabCloseDialog(): React.JSX.Element {
|
||||
<DialogContent className="max-w-sm" showCloseButton={false}>
|
||||
<DialogHeader>
|
||||
<DialogTitle className="text-sm">
|
||||
{t(
|
||||
'auto.components.terminal.pane.PinnedTabCloseDialog.6c190f295a',
|
||||
'Close pinned tab?'
|
||||
)}
|
||||
{unsentNotes
|
||||
? t(
|
||||
'auto.components.terminal.pane.PinnedTabCloseDialog.unsent_notes_title',
|
||||
'Discard unsent notes?'
|
||||
)
|
||||
: t(
|
||||
'auto.components.terminal.pane.PinnedTabCloseDialog.6c190f295a',
|
||||
'Close pinned tab?'
|
||||
)}
|
||||
</DialogTitle>
|
||||
<DialogDescription className="text-xs">
|
||||
{t(
|
||||
'auto.components.terminal.pane.PinnedTabCloseDialog.0d1963f4a6',
|
||||
'This tab is pinned. Are you sure you want to close it?'
|
||||
)}
|
||||
{unsentNotes
|
||||
? t(
|
||||
'auto.components.terminal.pane.PinnedTabCloseDialog.unsent_notes_description',
|
||||
"This tab has notes you haven't sent. Closing it discards them."
|
||||
)
|
||||
: t(
|
||||
'auto.components.terminal.pane.PinnedTabCloseDialog.0d1963f4a6',
|
||||
'This tab is pinned. Are you sure you want to close it?'
|
||||
)}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
{tabLabel ? (
|
||||
@@ -70,19 +81,21 @@ export default function PinnedTabCloseDialog(): React.JSX.Element {
|
||||
{tabLabel}
|
||||
</p>
|
||||
) : null}
|
||||
<div className="flex items-center gap-2">
|
||||
<Checkbox
|
||||
id={checkboxId}
|
||||
checked={dontAskAgain}
|
||||
onCheckedChange={(checked) => setDontAskAgain(checked === true)}
|
||||
/>
|
||||
<Label htmlFor={checkboxId} className="text-xs font-normal text-muted-foreground">
|
||||
{t(
|
||||
'auto.components.terminal.pane.PinnedTabCloseDialog.dont_ask_again',
|
||||
"Don't ask again for pinned tabs"
|
||||
)}
|
||||
</Label>
|
||||
</div>
|
||||
{unsentNotes ? null : (
|
||||
<div className="flex items-center gap-2">
|
||||
<Checkbox
|
||||
id={checkboxId}
|
||||
checked={dontAskAgain}
|
||||
onCheckedChange={(checked) => setDontAskAgain(checked === true)}
|
||||
/>
|
||||
<Label htmlFor={checkboxId} className="text-xs font-normal text-muted-foreground">
|
||||
{t(
|
||||
'auto.components.terminal.pane.PinnedTabCloseDialog.dont_ask_again',
|
||||
"Don't ask again for pinned tabs"
|
||||
)}
|
||||
</Label>
|
||||
</div>
|
||||
)}
|
||||
<DialogFooter className="gap-2">
|
||||
<Button type="button" variant="outline" size="sm" onClick={dismissPinnedTabClose}>
|
||||
{t('auto.components.terminal.pane.PinnedTabCloseDialog.0b38ee2f86', 'Cancel')}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { useCallback } from 'react'
|
||||
import { hasUnsentBrowserNotes } from '@/store/slices/browser/annotations/browser-page-annotation'
|
||||
import { useAppStore } from '../store'
|
||||
import { editorTabsNeedingSavePrompt } from '@/store/slices/editor/tabs/editor-tab-close-target'
|
||||
import { isEditorTabContentType } from '@/store/slices/editor/tabs/editor-tab-content-type'
|
||||
@@ -46,7 +47,12 @@ export function useTerminalBulkCloseActions(
|
||||
.map((tab) => tab.id)
|
||||
for (const id of tabIds) {
|
||||
const unifiedTab = byId.get(id) ?? byEntity.get(id)
|
||||
if (unifiedTab?.isPinned) {
|
||||
// Bulk closes keep pinned tabs and tabs holding unsent browser notes open.
|
||||
if (
|
||||
unifiedTab?.isPinned ||
|
||||
(unifiedTab?.contentType === 'browser' &&
|
||||
hasUnsentBrowserNotes(state, unifiedTab.entityId))
|
||||
) {
|
||||
continue
|
||||
}
|
||||
if (unifiedTab && isEditorTabContentType(unifiedTab.contentType)) {
|
||||
|
||||
@@ -107,6 +107,7 @@ export async function useIpcEventsForCloseRouting({
|
||||
activeBrowserTabIdByWorktree: { 'wt-1': 'workspace-1' },
|
||||
browserTabsByWorktree: { 'wt-1': [{ id: 'workspace-1' }] },
|
||||
browserPagesByWorkspace: {},
|
||||
browserAnnotationsByPageId: {},
|
||||
openFiles: [],
|
||||
unifiedTabsByWorktree: {},
|
||||
closeBrowserTab: vi.fn(),
|
||||
|
||||
@@ -73,6 +73,7 @@ function storeState(activeWorktreeId: string) {
|
||||
[LOCAL_WT]: [{ id: 'ws-local' }],
|
||||
[REMOTE_WT]: [{ id: 'ws-remote' }]
|
||||
},
|
||||
browserAnnotationsByPageId: {},
|
||||
browserPagesByWorkspace: {
|
||||
'ws-local': [{ id: 'page-local' }],
|
||||
'ws-remote': [{ id: 'page-remote' }]
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
import { destroyPersistentWebview } from '@/components/browser-pane/host-guest/webview-registry'
|
||||
import {
|
||||
guardPinnedTabClose,
|
||||
isUnifiedTabPinned,
|
||||
resolvePinnedTabLabel
|
||||
} from '../../store/slices/tabs/closing/pinned-tab-close-guard'
|
||||
import { translate } from '@/i18n/i18n'
|
||||
import { closeBrowserTabWithReply } from './browser-tab-close-with-reply'
|
||||
import { useAppStore } from '../../store'
|
||||
import { acquireBrowserAutomationBootstrapLease } from './browser-automation-bootstrap-lease'
|
||||
import {
|
||||
@@ -209,28 +205,8 @@ export function registerBrowserRequestIpcBridge(unsubs: (() => void)[]): void {
|
||||
)
|
||||
})
|
||||
}
|
||||
const replyPinnedBrowserCloseCanceled = (tabId: string): void => {
|
||||
window.api.ui.replyTabClose({
|
||||
requestId: data.requestId,
|
||||
error: translate(
|
||||
'auto.hooks.useIpcEvents.2f6637fe6c',
|
||||
'Browser tab {{value0}} is pinned',
|
||||
{ value0: tabId }
|
||||
)
|
||||
})
|
||||
}
|
||||
const closeBrowserWorkspaceWithReply = (worktreeId: string, workspaceId: string): void => {
|
||||
const currentStore = useAppStore.getState()
|
||||
guardPinnedTabClose({
|
||||
isPinned: isUnifiedTabPinned(currentStore, worktreeId, workspaceId),
|
||||
tabLabel: resolvePinnedTabLabel(currentStore, worktreeId, workspaceId),
|
||||
onClose: () => {
|
||||
useAppStore.getState().closeBrowserTab(workspaceId)
|
||||
window.api.ui.replyTabClose({ requestId: data.requestId })
|
||||
},
|
||||
onCancel: () => replyPinnedBrowserCloseCanceled(workspaceId)
|
||||
})
|
||||
}
|
||||
const closeWithReply = (worktreeId: string, workspaceId: string, pageId?: string): void =>
|
||||
closeBrowserTabWithReply({ requestId: data.requestId, worktreeId, workspaceId, pageId })
|
||||
const tabToClose =
|
||||
explicitTargetId ??
|
||||
(data.worktreeId
|
||||
@@ -273,11 +249,15 @@ export function registerBrowserRequestIpcBridge(unsubs: (() => void)[]): void {
|
||||
replyBrowserTabNotFound(tabToClose)
|
||||
return
|
||||
}
|
||||
if (owningWorktreeId) {
|
||||
closeWithReply(
|
||||
owningWorktreeId,
|
||||
workspaceId,
|
||||
pages.length > 1 ? tabToClose : undefined
|
||||
)
|
||||
return
|
||||
}
|
||||
if (pages.length <= 1) {
|
||||
if (owningWorktreeId) {
|
||||
closeBrowserWorkspaceWithReply(owningWorktreeId, workspaceId)
|
||||
return
|
||||
}
|
||||
store.closeBrowserTab(workspaceId)
|
||||
} else {
|
||||
store.closeBrowserPage(tabToClose)
|
||||
@@ -295,7 +275,7 @@ export function registerBrowserRequestIpcBridge(unsubs: (() => void)[]): void {
|
||||
replyBrowserTabNotFound(tabToClose)
|
||||
return
|
||||
}
|
||||
closeBrowserWorkspaceWithReply(owningWorktreeId, tabToClose)
|
||||
closeWithReply(owningWorktreeId, tabToClose)
|
||||
return
|
||||
}
|
||||
if (explicitTargetId) {
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
import { translate } from '@/i18n/i18n'
|
||||
import { useAppStore } from '../../store'
|
||||
import { hasUnsentBrowserNotes } from '@/store/slices/browser/annotations/browser-page-annotation'
|
||||
import {
|
||||
guardPinnedTabClose,
|
||||
isUnifiedTabPinned,
|
||||
resolvePinnedTabLabel
|
||||
} from '../../store/slices/tabs/closing/pinned-tab-close-guard'
|
||||
|
||||
/** Closes a browser tab, or one page of it, for a CLI or extension request once the user allows it, then replies to main. */
|
||||
export function closeBrowserTabWithReply(params: {
|
||||
requestId: string
|
||||
worktreeId: string
|
||||
workspaceId: string
|
||||
/** Closes only this page, so the tab's pin does not guard it; its notes do. */
|
||||
pageId?: string
|
||||
}): void {
|
||||
const { requestId, worktreeId, workspaceId, pageId } = params
|
||||
const state = useAppStore.getState()
|
||||
const unsentNotes = pageId
|
||||
? (state.browserAnnotationsByPageId[pageId]?.length ?? 0) > 0
|
||||
: hasUnsentBrowserNotes(state, workspaceId)
|
||||
const closedId = pageId ?? workspaceId
|
||||
guardPinnedTabClose({
|
||||
isPinned: !pageId && isUnifiedTabPinned(state, worktreeId, workspaceId),
|
||||
tabLabel: resolvePinnedTabLabel(state, worktreeId, workspaceId),
|
||||
onClose: () => {
|
||||
const latest = useAppStore.getState()
|
||||
// Siblings may have closed while the prompt was open; the last page closes its tab.
|
||||
if (pageId && (latest.browserPagesByWorkspace[workspaceId]?.length ?? 0) > 1) {
|
||||
latest.closeBrowserPage(pageId)
|
||||
} else {
|
||||
latest.closeBrowserTab(workspaceId)
|
||||
}
|
||||
window.api.ui.replyTabClose({ requestId })
|
||||
},
|
||||
onCancel: () =>
|
||||
window.api.ui.replyTabClose({
|
||||
requestId,
|
||||
error: unsentNotes
|
||||
? translate(
|
||||
'auto.hooks.useIpcEvents.unsent_notes_close_canceled',
|
||||
'Browser tab {{value0}} has unsent notes, and the user kept it open',
|
||||
{ value0: closedId }
|
||||
)
|
||||
: translate('auto.hooks.useIpcEvents.2f6637fe6c', 'Browser tab {{value0}} is pinned', {
|
||||
value0: closedId
|
||||
})
|
||||
}),
|
||||
unsentNotes
|
||||
})
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import { hasUnsentBrowserNotes } from '@/store/slices/browser/annotations/browser-page-annotation'
|
||||
import { isLocalSessionTabCloseOwned } from '@/runtime/web-session-tabs-sync/closing/local-session-tab-close-owner'
|
||||
import { closeMobileSessionTabInStore } from '@/runtime/web-session-tabs-sync/closing/mobile-session-tab-close'
|
||||
import {
|
||||
@@ -35,7 +36,8 @@ export function registerSessionTabIpcBridge(unsubs: (() => void)[]): void {
|
||||
guardPinnedTabClose({
|
||||
isPinned: isUnifiedTabPinned(store, worktreeId, browserTarget.workspaceId),
|
||||
tabLabel: resolvePinnedTabLabel(store, worktreeId, browserTarget.workspaceId),
|
||||
onClose: () => useAppStore.getState().closeBrowserTab(browserTarget.workspaceId)
|
||||
onClose: () => useAppStore.getState().closeBrowserTab(browserTarget.workspaceId),
|
||||
unsentNotes: hasUnsentBrowserNotes(store, browserTarget.workspaceId)
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -111,7 +113,8 @@ export function registerSessionTabIpcBridge(unsubs: (() => void)[]): void {
|
||||
isPinned: isUnifiedTabPinned(store, worktreeId, visibleId),
|
||||
tabLabel: resolvePinnedTabLabel(store, worktreeId, visibleId),
|
||||
onClose: closeAndRespond,
|
||||
onCancel: () => respond(SESSION_TAB_CLOSE_CANCELED_ERROR)
|
||||
onCancel: () => respond(SESSION_TAB_CLOSE_CANCELED_ERROR),
|
||||
unsentNotes: browserTarget ? hasUnsentBrowserNotes(store, browserTarget.workspaceId) : false
|
||||
})
|
||||
})
|
||||
)
|
||||
|
||||
+4
@@ -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"
|
||||
|
||||
@@ -2288,6 +2288,7 @@
|
||||
"useIpcEvents": {
|
||||
"0e3cf53060": "Browser tab {{value0}} not found",
|
||||
"2f6637fe6c": "Browser tab {{value0}} is pinned",
|
||||
"unsent_notes_close_canceled": "Browser tab {{value0}} has unsent notes, and the user kept it open",
|
||||
"a8d2bf8e9e": "No active browser tab to close",
|
||||
"f000b2ff76": "No active worktree",
|
||||
"7a64b31991": "Local terminal creation is unavailable while a remote runtime is active",
|
||||
@@ -4511,7 +4512,9 @@
|
||||
"0d1963f4a6": "This tab is pinned. Are you sure you want to close it?",
|
||||
"dont_ask_again": "Don't ask again for pinned tabs",
|
||||
"0b38ee2f86": "Cancel",
|
||||
"c337c9d75c": "Close"
|
||||
"c337c9d75c": "Close",
|
||||
"unsent_notes_title": "Discard unsent notes?",
|
||||
"unsent_notes_description": "This tab has notes you haven't sent. Closing it discards them."
|
||||
},
|
||||
"TerminalSshReconnectOverlay": {
|
||||
"authFailed": "Authentication failed for {{value0}}. Connect again to continue this terminal session.",
|
||||
@@ -18869,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."
|
||||
},
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { BrowserPage, BrowserWorkspace } from '../../../../../shared/browser-workspace-types'
|
||||
import type { BrowserPageAnnotation } from '../../../../../shared/browser/element-grab/browser-grab-types'
|
||||
import type { WorkspaceSessionState } from '../../../../../shared/workspace-session/workspace-session-state-types'
|
||||
import type { RemoteBrowserPageHandle } from '../../../store/slices/browser/browser-slice-contract'
|
||||
|
||||
@@ -6,7 +7,8 @@ export function buildBrowserSessionData(
|
||||
browserTabsByWorktree: Record<string, BrowserWorkspace[]>,
|
||||
browserPagesByWorkspace: Record<string, BrowserPage[]>,
|
||||
activeBrowserTabIdByWorktree: Record<string, string | null>,
|
||||
remoteBrowserPageHandlesByPageId: Record<string, RemoteBrowserPageHandle>
|
||||
remoteBrowserPageHandlesByPageId: Record<string, RemoteBrowserPageHandle>,
|
||||
browserAnnotationsByPageId: Record<string, BrowserPageAnnotation[]>
|
||||
): Pick<
|
||||
WorkspaceSessionState,
|
||||
'browserTabsByWorktree' | 'browserPagesByWorkspace' | 'activeBrowserTabIdByWorktree'
|
||||
@@ -16,7 +18,8 @@ export function buildBrowserSessionData(
|
||||
browserTabsByWorktree: buildPersistedBrowserTabsByWorktree(browserTabsByWorktree),
|
||||
browserPagesByWorkspace: buildPersistedBrowserPagesByWorkspace(
|
||||
browserPagesByWorkspace,
|
||||
remoteBrowserPageHandlesByPageId
|
||||
remoteBrowserPageHandlesByPageId,
|
||||
browserAnnotationsByPageId
|
||||
),
|
||||
activeBrowserTabIdByWorktree
|
||||
}
|
||||
@@ -35,16 +38,21 @@ export function buildPersistedBrowserTabsByWorktree(
|
||||
|
||||
export function buildPersistedBrowserPagesByWorkspace(
|
||||
browserPagesByWorkspace: Record<string, BrowserPage[]>,
|
||||
remoteBrowserPageHandlesByPageId: Record<string, RemoteBrowserPageHandle>
|
||||
remoteBrowserPageHandlesByPageId: Record<string, RemoteBrowserPageHandle>,
|
||||
browserAnnotationsByPageId: Record<string, BrowserPageAnnotation[]>
|
||||
): WorkspaceSessionState['browserPagesByWorkspace'] {
|
||||
return Object.fromEntries(
|
||||
Object.entries(browserPagesByWorkspace).map(([workspaceId, pages]) => [
|
||||
workspaceId,
|
||||
pages.map((page) => ({
|
||||
...page,
|
||||
loading: false,
|
||||
...persistedRemoteBrowserPageIdentity(remoteBrowserPageHandlesByPageId[page.id])
|
||||
}))
|
||||
pages.map((page) => {
|
||||
const annotations = browserAnnotationsByPageId[page.id]
|
||||
return {
|
||||
...page,
|
||||
loading: false,
|
||||
...persistedRemoteBrowserPageIdentity(remoteBrowserPageHandlesByPageId[page.id]),
|
||||
...(annotations?.length ? { annotations } : {})
|
||||
}
|
||||
})
|
||||
])
|
||||
)
|
||||
}
|
||||
|
||||
@@ -155,10 +155,15 @@ export function buildWorkspaceSessionPatch(
|
||||
snapshot.browserTabsByWorktree
|
||||
)
|
||||
}
|
||||
if (stagedVisibilityChanged || changed.has('browserPagesByWorkspace')) {
|
||||
if (
|
||||
stagedVisibilityChanged ||
|
||||
changed.has('browserPagesByWorkspace') ||
|
||||
changed.has('browserAnnotationsByPageId')
|
||||
) {
|
||||
patch.browserPagesByWorkspace = buildPersistedBrowserPagesByWorkspace(
|
||||
snapshot.browserPagesByWorkspace,
|
||||
snapshot.remoteBrowserPageHandlesByPageId
|
||||
snapshot.remoteBrowserPageHandlesByPageId,
|
||||
snapshot.browserAnnotationsByPageId
|
||||
)
|
||||
}
|
||||
if (stagedVisibilityChanged || changed.has('activeBrowserTabIdByWorktree')) {
|
||||
|
||||
@@ -42,6 +42,7 @@ export type WorkspaceSessionSnapshot = Pick<
|
||||
| 'activeTabTypeByWorktree'
|
||||
| 'browserTabsByWorktree'
|
||||
| 'browserPagesByWorkspace'
|
||||
| 'browserAnnotationsByPageId'
|
||||
| 'activeBrowserTabIdByWorktree'
|
||||
| 'browserUrlHistory'
|
||||
| 'workspaceDocHistory'
|
||||
@@ -84,6 +85,7 @@ export const SESSION_RELEVANT_FIELDS = [
|
||||
'activeTabTypeByWorktree',
|
||||
'browserTabsByWorktree',
|
||||
'browserPagesByWorkspace',
|
||||
'browserAnnotationsByPageId',
|
||||
'activeBrowserTabIdByWorktree',
|
||||
'browserUrlHistory',
|
||||
'workspaceDocHistory',
|
||||
@@ -310,7 +312,8 @@ export function buildWorkspaceSessionPayload(
|
||||
snapshot.browserTabsByWorktree,
|
||||
snapshot.browserPagesByWorkspace,
|
||||
snapshot.activeBrowserTabIdByWorktree,
|
||||
snapshot.remoteBrowserPageHandlesByPageId
|
||||
snapshot.remoteBrowserPageHandlesByPageId,
|
||||
snapshot.browserAnnotationsByPageId
|
||||
),
|
||||
// Why: enforce the history storage cap here so stale renderer state can't make every write stringify an oversized legacy array.
|
||||
browserUrlHistory: normalizeBrowserHistoryEntries(snapshot.browserUrlHistory),
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
resolvePinnedTabLabel
|
||||
} from '@/store/slices/tabs/closing/pinned-tab-close-guard'
|
||||
import { createWorkspaceTabCloseCommands } from '@/components/tab-group/workspace-tab-close-commands'
|
||||
import { hasUnsentBrowserNotes } from '@/store/slices/browser/annotations/browser-page-annotation'
|
||||
import { captureWorkspaceEmptiedReaction } from '@/components/tab-group/workspace-emptied-reaction'
|
||||
import {
|
||||
handleSwitchRecentTab,
|
||||
@@ -174,6 +175,11 @@ export function dispatchWorkspaceTabCommand(command: WorkspaceTabCommand): boole
|
||||
if ((command.bulk || command.skipEmptyCheck) && tab.isPinned) {
|
||||
return true
|
||||
}
|
||||
const unsentNotes = tab.contentType === 'browser' && hasUnsentBrowserNotes(state, tab.entityId)
|
||||
// Bulk closes keep a tab holding unsent notes open, as they keep pinned tabs.
|
||||
if (command.bulk && unsentNotes) {
|
||||
return true
|
||||
}
|
||||
// Why before the pin guard: its prompt takes focus, and the floating panel's reaction reads focus.
|
||||
const whenEmptied =
|
||||
command.bulk || command.skipEmptyCheck
|
||||
@@ -189,7 +195,8 @@ export function dispatchWorkspaceTabCommand(command: WorkspaceTabCommand): boole
|
||||
guardPinnedTabClose({
|
||||
isPinned: tab.isPinned === true,
|
||||
tabLabel: resolvePinnedTabLabel(state, target.worktreeId, tab.id),
|
||||
onClose: close
|
||||
onClose: close,
|
||||
unsentNotes
|
||||
})
|
||||
}
|
||||
return true
|
||||
|
||||
@@ -42,3 +42,16 @@ export function retainBrowserAnnotationMarkerIds(
|
||||
}
|
||||
return nextByPageId
|
||||
}
|
||||
|
||||
/** Closing a browser tab discards the notes its pages hold unsent. */
|
||||
export function hasUnsentBrowserNotes(
|
||||
state: {
|
||||
browserPagesByWorkspace: Record<string, readonly { id: string }[]>
|
||||
browserAnnotationsByPageId: Record<string, readonly BrowserPageAnnotation[]>
|
||||
},
|
||||
browserWorkspaceId: string
|
||||
): boolean {
|
||||
return (state.browserPagesByWorkspace[browserWorkspaceId] ?? []).some(
|
||||
(page) => (state.browserAnnotationsByPageId[page.id]?.length ?? 0) > 0
|
||||
)
|
||||
}
|
||||
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import '../../../../../../shared/constants'
|
||||
import { parseWorkspaceSession } from '../../../../../../shared/workspace-session/workspace-session-schema'
|
||||
import type { WorkspaceSessionState } from '../../../../../../shared/workspace-session/workspace-session-state-types'
|
||||
import { buildWorkspaceSessionPayload } from '@/lib/workspace/persistence/workspace-session'
|
||||
import { createTestStore } from '../../../testing/app-store-test-fixture'
|
||||
import { createStoreSessionMockApi } from '../../../testing/app-store-session-api.test-fixture'
|
||||
import { makeWorktree } from '../../worktrees/worktree.test-fixture'
|
||||
import { makeBrowserTab } from '../browser-tab.test-fixture'
|
||||
import { makeAnnotation } from '../annotations/browser-annotation-test-fixture'
|
||||
|
||||
vi.mock('sonner', () => ({ toast: { info: vi.fn(), success: vi.fn(), error: vi.fn() } }))
|
||||
|
||||
createStoreSessionMockApi()
|
||||
|
||||
const WT = 'repo1::/path/wt1'
|
||||
|
||||
function createHydratedStore(session: WorkspaceSessionState) {
|
||||
const store = createTestStore()
|
||||
store.setState({
|
||||
repos: [{ id: 'repo1', path: '/repo1', displayName: 'Repo 1', badgeColor: '#000', addedAt: 0 }],
|
||||
worktreesByRepo: { repo1: [makeWorktree({ id: WT, repoId: 'repo1', path: '/path/wt1' })] },
|
||||
activeWorktreeId: WT
|
||||
})
|
||||
store.getState().hydrateBrowserSession(session)
|
||||
return store
|
||||
}
|
||||
|
||||
describe('unsent browser notes across a restart', () => {
|
||||
it('restores a page’s unsent notes from the saved session', () => {
|
||||
const before = createHydratedStore({
|
||||
activeRepoId: 'repo1',
|
||||
activeWorktreeId: WT,
|
||||
activeTabId: null,
|
||||
tabsByWorktree: {},
|
||||
terminalLayoutsByTabId: {},
|
||||
browserTabsByWorktree: {
|
||||
[WT]: [makeBrowserTab({ id: 'workspace-1', worktreeId: WT, url: 'https://example.com/' })]
|
||||
},
|
||||
browserPagesByWorkspace: {
|
||||
'workspace-1': [
|
||||
{
|
||||
id: 'page-1',
|
||||
workspaceId: 'workspace-1',
|
||||
worktreeId: WT,
|
||||
url: 'https://example.com/',
|
||||
title: 'Example',
|
||||
loading: false,
|
||||
faviconUrl: null,
|
||||
canGoBack: false,
|
||||
canGoForward: false,
|
||||
loadError: null,
|
||||
createdAt: 1
|
||||
}
|
||||
]
|
||||
},
|
||||
activeBrowserTabIdByWorktree: { [WT]: 'workspace-1' }
|
||||
})
|
||||
before.getState().addBrowserPageAnnotation(makeAnnotation('page-1'))
|
||||
|
||||
const saved = parseWorkspaceSession(
|
||||
JSON.parse(JSON.stringify(buildWorkspaceSessionPayload(before.getState())))
|
||||
)
|
||||
if (!saved.ok) {
|
||||
throw new Error(saved.error)
|
||||
}
|
||||
const after = createHydratedStore(saved.value)
|
||||
|
||||
expect(after.getState().browserAnnotationsByPageId).toEqual({
|
||||
'page-1': [makeAnnotation('page-1')]
|
||||
})
|
||||
expect(after.getState().browserPagesByWorkspace['workspace-1']?.[0]).not.toHaveProperty(
|
||||
'annotations'
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -6,7 +6,11 @@ import { createNonSecureContextUuid as createBrowserUuid } from '../../../../../
|
||||
import { ORCA_LAYOUT_OWNER_IS_MAIN } from '../../../../../../shared/layout-owner-switch'
|
||||
import '../../../../../../shared/constants'
|
||||
import { ORCA_BROWSER_BLANK_URL } from '../../../../../../shared/browser/browser-blank-page'
|
||||
import type { WorkspaceSessionState } from '../../../../../../shared/workspace-session/workspace-session-state-types'
|
||||
import type {
|
||||
PersistedBrowserPage,
|
||||
WorkspaceSessionState
|
||||
} from '../../../../../../shared/workspace-session/workspace-session-state-types'
|
||||
import type { BrowserPageAnnotation } from '../../../../../../shared/browser/element-grab/browser-grab-types'
|
||||
import { normalizeBrowserHistoryEntries } from '../../../../../../shared/workspace-session/workspace-session-browser-history'
|
||||
import { normalizeWorkspaceDocHistoryEntries } from '../../../../../../shared/workspace-session/workspace-doc-history'
|
||||
import type { AppState } from '../../../types'
|
||||
@@ -37,6 +41,7 @@ export function projectHydratedBrowserSession(
|
||||
const persistedActiveTabTypeByWorktree = session.activeTabTypeByWorktree ?? {}
|
||||
const browserTabsByWorktree: Record<string, BrowserWorkspace[]> = {}
|
||||
const browserPagesByWorkspace: Record<string, BrowserPage[]> = {}
|
||||
const browserAnnotationsByPageId: Record<string, BrowserPageAnnotation[]> = {}
|
||||
|
||||
for (const [worktreeId, tabs] of Object.entries(persistedTabsByWorktree)) {
|
||||
if (!validWorktreeIds.has(worktreeId)) {
|
||||
@@ -46,7 +51,7 @@ export function projectHydratedBrowserSession(
|
||||
for (const tab of tabs) {
|
||||
// Salvage can leave an empty page array; hydrate it like a missing array.
|
||||
const storedPages = persistedPagesByWorkspace[tab.id]
|
||||
const persistedPages = storedPages?.length
|
||||
const persistedPages: PersistedBrowserPage[] = storedPages?.length
|
||||
? storedPages
|
||||
: [
|
||||
{
|
||||
@@ -70,10 +75,14 @@ export function projectHydratedBrowserSession(
|
||||
]
|
||||
const nextPages = persistedPages.map((page) => {
|
||||
// Why: in-memory hydration callers can bypass the persistence schema's unknown-key stripping.
|
||||
const { allowWindowClose: _legacyAllowWindowClose, ...persistedPage } =
|
||||
page as typeof page & {
|
||||
allowWindowClose?: boolean
|
||||
}
|
||||
const { allowWindowClose: _legacyAllowWindowClose, ...savedPage } = page as typeof page & {
|
||||
allowWindowClose?: boolean
|
||||
}
|
||||
// The store keeps a page's unsent notes beside its record, not on it.
|
||||
const { annotations, ...persistedPage } = savedPage
|
||||
if (annotations?.length) {
|
||||
browserAnnotationsByPageId[page.id] = annotations
|
||||
}
|
||||
return {
|
||||
...persistedPage,
|
||||
workspaceId: tab.id,
|
||||
@@ -179,7 +188,7 @@ export function projectHydratedBrowserSession(
|
||||
remoteBrowserPageHandlesByPageId:
|
||||
buildRestoredRemoteBrowserPageHandles(browserPagesByWorkspace),
|
||||
browserCertificateFailuresByPageId: {},
|
||||
browserAnnotationsByPageId: {},
|
||||
browserAnnotationsByPageId,
|
||||
browserAnnotationMarkerIdsByPageId: {},
|
||||
browserUrlHistory: normalizeBrowserHistoryEntries(session.browserUrlHistory ?? []),
|
||||
workspaceDocHistory: normalizeWorkspaceDocHistoryEntries(session.workspaceDocHistory ?? []),
|
||||
|
||||
@@ -74,6 +74,7 @@ function persistedSession(
|
||||
state.browserTabsByWorktree,
|
||||
state.browserPagesByWorkspace,
|
||||
state.activeBrowserTabIdByWorktree,
|
||||
{},
|
||||
{}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -28,21 +28,18 @@ export function shouldConfirmPinnedTabClose(state: AppState): boolean {
|
||||
return state.settings?.confirmClosePinnedTab ?? true
|
||||
}
|
||||
|
||||
/** Centralize pin confirmation across keyboard/native/menu paths; unpinned or disabled-confirmation closes proceed immediately. */
|
||||
/** Centralize close confirmation across keyboard/native/menu/CLI paths: unsent browser notes always ask; pins ask unless turned off. */
|
||||
export function guardPinnedTabClose(params: {
|
||||
isPinned: boolean
|
||||
tabLabel: string
|
||||
onClose: () => void
|
||||
onCancel?: () => void
|
||||
/** The tab holds browser notes the user has not sent; closing discards them. */
|
||||
unsentNotes?: boolean
|
||||
}): (() => void) | undefined {
|
||||
const { isPinned, tabLabel, onClose, onCancel } = params
|
||||
if (!isPinned) {
|
||||
onClose()
|
||||
return undefined
|
||||
}
|
||||
|
||||
const { isPinned, tabLabel, onClose, onCancel, unsentNotes } = params
|
||||
const state = useAppStore.getState()
|
||||
if (!shouldConfirmPinnedTabClose(state)) {
|
||||
if (!unsentNotes && (!isPinned || !shouldConfirmPinnedTabClose(state))) {
|
||||
onClose()
|
||||
return undefined
|
||||
}
|
||||
@@ -50,7 +47,8 @@ export function guardPinnedTabClose(params: {
|
||||
const request = {
|
||||
tabLabel,
|
||||
onConfirm: onClose,
|
||||
...(onCancel ? { onCancel } : {})
|
||||
...(onCancel ? { onCancel } : {}),
|
||||
...(unsentNotes ? { unsentNotes: true as const } : {})
|
||||
}
|
||||
state.requestPinnedTabCloseConfirm(request)
|
||||
return () => state.cancelPinnedTabCloseRequest(request)
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import type { StateCreator } from 'zustand'
|
||||
import type { AppState } from '../../types'
|
||||
|
||||
/** A pending request to confirm closing a pinned tab. `onConfirm` runs the
|
||||
* original close once the user accepts; the label is shown in the dialog. */
|
||||
/** A pending request to confirm closing a pinned tab, or a browser tab holding unsent notes.
|
||||
* `onConfirm` runs the original close once the user accepts; the label is shown in the dialog. */
|
||||
export type PinnedTabCloseConfirmRequest = {
|
||||
tabLabel: string
|
||||
/** Set when the prompt warns about unsent browser notes instead of a pin. */
|
||||
unsentNotes?: true
|
||||
onConfirm: () => void
|
||||
onCancel?: () => void
|
||||
}
|
||||
|
||||
@@ -128,7 +128,8 @@ export function layoutViewAndFactsOfStore(
|
||||
localOnlyScrollbackByTabId: terminals.localOnlyScrollbackByTabId,
|
||||
browserPagesByWorkspace: buildPersistedBrowserPagesByWorkspace(
|
||||
pickKeys(state.browserPagesByWorkspace, browserTabIds),
|
||||
state.remoteBrowserPageHandlesByPageId
|
||||
state.remoteBrowserPageHandlesByPageId,
|
||||
{}
|
||||
),
|
||||
tabLabels: {},
|
||||
terminalRows: {},
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
import { z } from 'zod'
|
||||
import type { BrowserPageAnnotation } from '../element-grab/browser-grab-types'
|
||||
|
||||
const rectSchema = z.object({
|
||||
x: z.number(),
|
||||
y: z.number(),
|
||||
width: z.number(),
|
||||
height: z.number()
|
||||
})
|
||||
|
||||
const payloadSchema = z.object({
|
||||
page: z.object({
|
||||
sanitizedUrl: z.string(),
|
||||
title: z.string(),
|
||||
viewportWidth: z.number(),
|
||||
viewportHeight: z.number(),
|
||||
scrollX: z.number(),
|
||||
scrollY: z.number(),
|
||||
devicePixelRatio: z.number(),
|
||||
capturedAt: z.string()
|
||||
}),
|
||||
target: z.object({
|
||||
tagName: z.string(),
|
||||
selector: z.string(),
|
||||
elementPath: z.string().optional(),
|
||||
fullPath: z.string().optional(),
|
||||
cssClasses: z.string().optional(),
|
||||
nearbyElements: z.array(z.string()).optional(),
|
||||
selectedText: z.string().nullable().optional(),
|
||||
isFixed: z.boolean().optional(),
|
||||
reactComponents: z.string().nullable().optional(),
|
||||
sourceFile: z.string().nullable().optional(),
|
||||
textSnippet: z.string(),
|
||||
htmlSnippet: z.string(),
|
||||
attributes: z.record(z.string(), z.string()),
|
||||
accessibility: z.object({
|
||||
role: z.string().nullable(),
|
||||
accessibleName: z.string().nullable(),
|
||||
ariaLabel: z.string().nullable(),
|
||||
ariaLabelledBy: z.string().nullable()
|
||||
}),
|
||||
rectViewport: rectSchema,
|
||||
rectPage: rectSchema,
|
||||
computedStyles: z.object({
|
||||
display: z.string(),
|
||||
position: z.string(),
|
||||
width: z.string(),
|
||||
height: z.string(),
|
||||
margin: z.string(),
|
||||
padding: z.string(),
|
||||
color: z.string(),
|
||||
backgroundColor: z.string(),
|
||||
border: z.string(),
|
||||
borderRadius: z.string(),
|
||||
fontFamily: z.string(),
|
||||
fontSize: z.string(),
|
||||
fontWeight: z.string(),
|
||||
lineHeight: z.string(),
|
||||
textAlign: z.string(),
|
||||
zIndex: z.string()
|
||||
})
|
||||
}),
|
||||
nearbyText: z.array(z.string()),
|
||||
ancestorPath: z.array(z.string()),
|
||||
screenshot: z.null().catch(null)
|
||||
})
|
||||
|
||||
export const browserPageAnnotationSchema: z.ZodType<BrowserPageAnnotation> = z.object({
|
||||
id: z.string(),
|
||||
browserPageId: z.string(),
|
||||
comment: z.string(),
|
||||
intent: z.enum(['fix', 'change', 'question', 'approve']),
|
||||
priority: z.enum(['blocking', 'important', 'suggestion']),
|
||||
createdAt: z.string(),
|
||||
payload: payloadSchema,
|
||||
imagePaths: z.array(z.string()).optional()
|
||||
})
|
||||
@@ -596,6 +596,8 @@
|
||||
"auto.components.terminal.pane.PinnedTabCloseDialog.6c190f295a",
|
||||
"auto.components.terminal.pane.PinnedTabCloseDialog.c337c9d75c",
|
||||
"auto.components.terminal.pane.PinnedTabCloseDialog.dont_ask_again",
|
||||
"auto.components.terminal.pane.PinnedTabCloseDialog.unsent_notes_description",
|
||||
"auto.components.terminal.pane.PinnedTabCloseDialog.unsent_notes_title",
|
||||
"auto.components.workspace.cleanup.WorkspaceCleanupDialog.191f0bc98e",
|
||||
"auto.components.workspace.cleanup.WorkspaceCleanupDialog.1d3503357d",
|
||||
"auto.components.workspace.cleanup.WorkspaceCleanupDialog.38ca0b1400",
|
||||
|
||||
@@ -4,6 +4,7 @@ import { normalizeBrowserHistoryEntries } from './workspace-session-browser-hist
|
||||
import { normalizeWorkspaceDocHistoryEntries } from './workspace-doc-history'
|
||||
import { isDocPreviewUrl } from '../document-preview/doc-preview-scheme'
|
||||
import { salvagingArray } from '../zod-salvage'
|
||||
import { browserPageAnnotationSchema } from '../browser/annotations/browser-page-annotation-schema'
|
||||
|
||||
const browserLoadErrorSchema = z.object({
|
||||
code: z.number(),
|
||||
@@ -88,7 +89,9 @@ export const browserPageSchema = z.object({
|
||||
docLocation: browserPageDocLocationSchema.nullable().optional(),
|
||||
// Persist one-level conversion history; reject preview-scheme URLs at this read boundary as at every URL sink.
|
||||
convertedFrom: browserPageConversionOriginSchema,
|
||||
convertedTo: browserPageConversionOriginSchema
|
||||
convertedTo: browserPageConversionOriginSchema,
|
||||
// Unsent notes ride with their page so a reload or restart keeps them (#39856).
|
||||
annotations: salvagingArray(browserPageAnnotationSchema).optional()
|
||||
})
|
||||
|
||||
const browserHistoryEntrySchema = z.object({
|
||||
|
||||
@@ -4,6 +4,7 @@ import type { WorkspaceKey } from '../workspace-scope'
|
||||
import type { Tab, TabGroup, TabGroupLayoutNode, WorkspaceVisibleTabType } from '../tab-types'
|
||||
import type { TerminalLayoutSnapshot, TerminalTab } from '../workspace-layout/terminal-tab-types'
|
||||
import type { BrowserHistoryEntry, BrowserPage, BrowserWorkspace } from '../browser-workspace-types'
|
||||
import type { BrowserPageAnnotation } from '../browser/element-grab/browser-grab-types'
|
||||
import type { WorkspaceDocHistoryEntry } from './workspace-doc-history'
|
||||
import type { ClientHostedBrowserCloseIntent } from './client-hosted-browser-close-intent'
|
||||
import type { PairedTerminalTabCloseIntent } from '../workspace-layout/paired-terminal-tab-close-intent'
|
||||
@@ -32,6 +33,9 @@ export type PersistedOpenFile = {
|
||||
liveTail?: boolean
|
||||
}
|
||||
|
||||
/** A saved page carries its unsent notes; the store keeps them in browserAnnotationsByPageId. */
|
||||
export type PersistedBrowserPage = BrowserPage & { annotations?: BrowserPageAnnotation[] }
|
||||
|
||||
export type WorkspaceSessionState = {
|
||||
activeRepoId: string | null
|
||||
/** Scope-aware active owner for folder workspaces. Legacy worktree UI still reads activeWorktreeId. */
|
||||
@@ -56,7 +60,7 @@ export type WorkspaceSessionState = {
|
||||
/** Persisted browser workspaces, keyed by worktree ID. */
|
||||
browserTabsByWorktree?: Record<string, BrowserWorkspace[]>
|
||||
/** Persisted browser pages, keyed by workspace ID. */
|
||||
browserPagesByWorkspace?: Record<string, BrowserPage[]>
|
||||
browserPagesByWorkspace?: Record<string, PersistedBrowserPage[]>
|
||||
/** Per-worktree active browser workspace ID at shutdown. */
|
||||
activeBrowserTabIdByWorktree?: Record<string, string | null>
|
||||
/** Runtime-authoritative logical client-hosted pages; desktop browserPagesByWorkspace holds the client half. */
|
||||
|
||||
Reference in New Issue
Block a user