Keep workspace controls visible while creating worktrees (#5437)
Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
+45
-21
@@ -24,6 +24,8 @@ import { SYNC_FIT_PANES_EVENT, TOGGLE_TERMINAL_PANE_EXPAND_EVENT } from '@/const
|
||||
import { syncZoomCSSVar } from '@/lib/ui-zoom'
|
||||
import { resolveLeftSidebarStyleVariables } from '@/lib/left-sidebar-appearance'
|
||||
import { canShowRightSidebarForView } from '@/lib/right-sidebar-visibility'
|
||||
import { resolveLeftTitlebarChromeLayout } from '@/lib/titlebar-left-chrome'
|
||||
import { shouldShowWorktreeCreationSurface } from '@/lib/worktree-creation-surface'
|
||||
import { buildAppFontFamily } from '@/lib/app-font-family'
|
||||
import { toast } from 'sonner'
|
||||
import { Toaster } from '@/components/ui/sonner'
|
||||
@@ -390,14 +392,12 @@ function App(): React.JSX.Element {
|
||||
const contextualToursAutoEligible = useAppStore((s) => s.contextualToursAutoEligible)
|
||||
const activeWorktreeId = useAppStore((s) => s.activeWorktreeId)
|
||||
const activePendingCreationId = useAppStore((s) => s.activePendingCreationId)
|
||||
// Why: the creation loader is debounced — a fast create resolves before its
|
||||
// entry's loaderVisible flips, so the content area keeps showing the prior
|
||||
// workspace (or Landing) and never flashes a loader. Only a create still
|
||||
// pending past the debounce gates the loader and hides the terminal.
|
||||
const activeCreationLoaderVisible = useAppStore(
|
||||
// Why: the creation surface owns the tab strip from the first pending frame.
|
||||
// Gating it on the delayed loader flag made the tab bar swap in mid-create.
|
||||
const activePendingCreationExists = useAppStore(
|
||||
(s) =>
|
||||
s.activePendingCreationId != null &&
|
||||
s.pendingWorktreeCreations[s.activePendingCreationId]?.loaderVisible === true
|
||||
s.activePendingCreationId !== null &&
|
||||
s.pendingWorktreeCreations[s.activePendingCreationId] !== undefined
|
||||
)
|
||||
// Why: App swaps the sidebar between workspace and landing layouts when the
|
||||
// active workspace is slept/deleted. Keep virtualized scroll memory above
|
||||
@@ -434,9 +434,14 @@ function App(): React.JSX.Element {
|
||||
// and shutdown transitions where activeWorktreeId can briefly become null.
|
||||
const shouldMountTerminalWorkbench =
|
||||
activeWorktreeId !== null || hasMountedTerminalWorkbenchRef.current
|
||||
// Why: visible worktree creation owns its faux tab strip; the previous
|
||||
// workspace must stay mounted for retention without rendering real chrome.
|
||||
const creationLayoutActive = activeView === 'terminal' && activeCreationLoaderVisible
|
||||
// Why: visible worktree creation owns its faux tab strip from start to finish;
|
||||
// the previous workspace must stay mounted for retention without rendering
|
||||
// real chrome.
|
||||
const creationLayoutActive = shouldShowWorktreeCreationSurface({
|
||||
activeView,
|
||||
activePendingCreationId,
|
||||
hasActivePendingCreation: activePendingCreationExists
|
||||
})
|
||||
const workspaceChromeActive =
|
||||
activeView === 'terminal' && activeWorktreeId !== null && !creationLayoutActive
|
||||
const terminalWorkbenchVisible =
|
||||
@@ -1314,9 +1319,17 @@ function App(): React.JSX.Element {
|
||||
activeView !== 'skills'
|
||||
// Why: Tasks/Landing keep the full titlebar only when the sidebar is
|
||||
// collapsed; with it open, mirror workspace view so titlebar-left sits flush
|
||||
// above nav. Creation layout suppresses both titlebar forms.
|
||||
// above nav. Creation layout suppresses the full-width titlebar.
|
||||
const stackedSidebarOpen =
|
||||
!workspaceChromeActive && !creationLayoutActive && showSidebar && sidebarOpen
|
||||
// Why: visible creation keeps only the top-left window chrome; workspace tabs
|
||||
// and right-sidebar chrome remain gated by workspaceChromeActive.
|
||||
const leftTitlebarChromeLayout = resolveLeftTitlebarChromeLayout({
|
||||
workspaceChromeActive,
|
||||
stackedSidebarOpen,
|
||||
creationLayoutActive,
|
||||
sidebarOpen
|
||||
})
|
||||
// Why: suppress right sidebar controls on full-page navigation surfaces
|
||||
// since those surfaces intentionally own the full content area.
|
||||
const showRightSidebarControls = !creationLayoutActive && canShowRightSidebarForView(activeView)
|
||||
@@ -1630,7 +1643,13 @@ function App(): React.JSX.Element {
|
||||
})
|
||||
observer.observe(controls)
|
||||
return () => observer.disconnect()
|
||||
}, [isFullScreen, settings?.showTitlebarAppName, showSidebar, workspaceChromeActive, sidebarOpen])
|
||||
}, [
|
||||
isFullScreen,
|
||||
settings?.showTitlebarAppName,
|
||||
showSidebar,
|
||||
leftTitlebarChromeLayout.isFloating,
|
||||
sidebarOpen
|
||||
])
|
||||
|
||||
const resolvedMountedLazyModalIds = resolveMountedLazyModalIds(activeModal, mountedLazyModalIds)
|
||||
if (resolvedMountedLazyModalIds !== mountedLazyModalIds) {
|
||||
@@ -1654,7 +1673,7 @@ function App(): React.JSX.Element {
|
||||
<div
|
||||
ref={titlebarLeftControlsRef}
|
||||
className={`flex h-full shrink-0 items-center${
|
||||
workspaceChromeActive && !sidebarOpen ? ' w-max' : ' w-full'
|
||||
leftTitlebarChromeLayout.isFloating ? ' w-max' : ' w-full'
|
||||
}`}
|
||||
>
|
||||
<div className="flex h-full items-center">
|
||||
@@ -1881,7 +1900,7 @@ function App(): React.JSX.Element {
|
||||
to the top of the window. Left titlebar controls move to a
|
||||
header above the sidebar. Settings, landing, and the tasks
|
||||
page keep the titlebar. */}
|
||||
{!workspaceChromeActive && !stackedSidebarOpen && !creationLayoutActive ? (
|
||||
{!leftTitlebarChromeLayout.shouldMount ? (
|
||||
<div className="titlebar">
|
||||
<div className="flex items-center shrink-0 mr-2">{titlebarLeftControls}</div>
|
||||
{titlebarMainStrip}
|
||||
@@ -1889,7 +1908,7 @@ function App(): React.JSX.Element {
|
||||
) : null}
|
||||
<div className="flex flex-row flex-1 min-h-0 overflow-hidden">
|
||||
{showSidebar ? (
|
||||
workspaceChromeActive || stackedSidebarOpen ? (
|
||||
leftTitlebarChromeLayout.shouldMount ? (
|
||||
/* Why: left column wraps the sidebar with a titlebar-height
|
||||
header above it. The header holds the same controls
|
||||
(traffic lights, sidebar toggle, "Orca" title, agent badge)
|
||||
@@ -1911,9 +1930,9 @@ function App(): React.JSX.Element {
|
||||
// header sized to its own controls instead of the w-0
|
||||
// sidebar wrapper.
|
||||
className={`titlebar-left${
|
||||
sidebarOpen
|
||||
? ''
|
||||
: ' titlebar-left-floating absolute top-0 left-0 z-10 w-max border-r border-border'
|
||||
leftTitlebarChromeLayout.isFloating
|
||||
? ' titlebar-left-floating absolute top-0 left-0 z-10 w-max border-r border-border'
|
||||
: ''
|
||||
}`}
|
||||
style={{
|
||||
// Why: custom sidebar appearances are scoped to the sidebar
|
||||
@@ -2055,13 +2074,18 @@ function App(): React.JSX.Element {
|
||||
{activeView === 'space' ? <WorkspaceSpacePage /> : null}
|
||||
{activeView === 'mobile' ? <MobilePage /> : null}
|
||||
{activeView === 'terminal' &&
|
||||
activeCreationLoaderVisible &&
|
||||
creationLayoutActive &&
|
||||
activePendingCreationId ? (
|
||||
<WorktreeCreationPanel creationId={activePendingCreationId} />
|
||||
<WorktreeCreationPanel
|
||||
creationId={activePendingCreationId}
|
||||
reserveCollapsedSidebarHeaderSpace={
|
||||
leftTitlebarChromeLayout.isFloating
|
||||
}
|
||||
/>
|
||||
) : null}
|
||||
{activeView === 'terminal' &&
|
||||
!activeWorktreeId &&
|
||||
!activeCreationLoaderVisible ? (
|
||||
!creationLayoutActive ? (
|
||||
<Landing />
|
||||
) : null}
|
||||
</RecoverableRenderErrorBoundary>
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
// @vitest-environment happy-dom
|
||||
|
||||
import { act } from 'react'
|
||||
import { createRoot, type Root } from 'react-dom/client'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import WorktreeCreationPanel from './WorktreeCreationPanel'
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
state: {
|
||||
pendingWorktreeCreations: {
|
||||
'create-1': {
|
||||
creationId: 'create-1',
|
||||
phase: 'creating',
|
||||
status: 'creating',
|
||||
indeterminate: false,
|
||||
loaderVisible: true,
|
||||
request: {
|
||||
repoId: 'repo-1',
|
||||
name: 'new-workspace',
|
||||
displayName: 'New workspace',
|
||||
setupDecision: 'skip',
|
||||
agent: null,
|
||||
pendingFirstAgentMessageRename: false,
|
||||
note: '',
|
||||
startupPlan: null,
|
||||
quickPrompt: '',
|
||||
quickTelemetry: null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}))
|
||||
|
||||
vi.mock('@/store', () => ({
|
||||
useAppStore: (selector: (state: typeof mocks.state) => unknown) => selector(mocks.state)
|
||||
}))
|
||||
|
||||
vi.mock('@/lib/worktree-creation-flow', () => ({
|
||||
retryBackgroundWorktreeCreation: vi.fn()
|
||||
}))
|
||||
|
||||
const roots: Root[] = []
|
||||
|
||||
async function renderPanel(reserveCollapsedSidebarHeaderSpace: boolean): Promise<HTMLDivElement> {
|
||||
const container = document.createElement('div')
|
||||
document.body.appendChild(container)
|
||||
const root = createRoot(container)
|
||||
roots.push(root)
|
||||
|
||||
await act(async () => {
|
||||
root.render(
|
||||
<WorktreeCreationPanel
|
||||
creationId="create-1"
|
||||
reserveCollapsedSidebarHeaderSpace={reserveCollapsedSidebarHeaderSpace}
|
||||
/>
|
||||
)
|
||||
})
|
||||
|
||||
return container
|
||||
}
|
||||
|
||||
describe('WorktreeCreationPanel', () => {
|
||||
beforeEach(() => {
|
||||
globalThis.IS_REACT_ACT_ENVIRONMENT = true
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
roots.splice(0).forEach((root) => {
|
||||
act(() => root.unmount())
|
||||
})
|
||||
document.body.replaceChildren()
|
||||
})
|
||||
|
||||
it('keeps the faux creation tab visible', async () => {
|
||||
const container = await renderPanel(false)
|
||||
|
||||
expect(container.textContent).toContain('New workspace')
|
||||
expect(container.textContent).toContain('Creating worktree…')
|
||||
const title = [...container.querySelectorAll('span')].find(
|
||||
(node) => node.textContent === 'New workspace'
|
||||
)
|
||||
expect(title?.closest('div')?.className).toContain('border-r')
|
||||
})
|
||||
|
||||
it('reserves collapsed left-titlebar space before the faux tab', async () => {
|
||||
const container = await renderPanel(true)
|
||||
const title = [...container.querySelectorAll('span')].find(
|
||||
(node) => node.textContent === 'New workspace'
|
||||
)
|
||||
const spacer = title?.closest('div')?.previousElementSibling as HTMLElement | null
|
||||
|
||||
expect(spacer?.style.width).toBe('var(--collapsed-sidebar-header-width)')
|
||||
})
|
||||
|
||||
it('does not reserve left-titlebar space when the header is not floating', async () => {
|
||||
const container = await renderPanel(false)
|
||||
const title = [...container.querySelectorAll('span')].find(
|
||||
(node) => node.textContent === 'New workspace'
|
||||
)
|
||||
|
||||
expect(title?.closest('div')?.previousElementSibling).toBeNull()
|
||||
})
|
||||
})
|
||||
@@ -15,9 +15,11 @@ import { translate } from '@/i18n/i18n'
|
||||
* debounced upstream so fast creates never paint it.
|
||||
*/
|
||||
export default function WorktreeCreationPanel({
|
||||
creationId
|
||||
creationId,
|
||||
reserveCollapsedSidebarHeaderSpace = false
|
||||
}: {
|
||||
creationId: string
|
||||
reserveCollapsedSidebarHeaderSpace?: boolean
|
||||
}): React.JSX.Element | null {
|
||||
const entry = useAppStore((s) => s.pendingWorktreeCreations[creationId])
|
||||
if (!entry) {
|
||||
@@ -34,6 +36,19 @@ export default function WorktreeCreationPanel({
|
||||
create reads as a workspace tab. Carries only the worktree name + a
|
||||
cancel control — the live status lives in the body below. */}
|
||||
<div className="flex h-[36px] shrink-0 items-stretch border-b border-border bg-card">
|
||||
{reserveCollapsedSidebarHeaderSpace ? (
|
||||
// Why: collapsed sidebar chrome floats above this strip, so reserve
|
||||
// the same measured width real tabs use to keep title/cancel clear.
|
||||
<div
|
||||
className="shrink-0"
|
||||
style={
|
||||
{
|
||||
width: 'var(--collapsed-sidebar-header-width)',
|
||||
WebkitAppRegion: 'no-drag'
|
||||
} as React.CSSProperties
|
||||
}
|
||||
/>
|
||||
) : null}
|
||||
<div className="flex h-full max-w-[240px] items-center gap-1.5 border-r border-border px-2.5 text-xs">
|
||||
{isError ? (
|
||||
<AlertTriangle className="size-3.5 shrink-0 text-destructive" />
|
||||
|
||||
@@ -81,10 +81,9 @@ export type PendingWorktreeCreation = {
|
||||
* progress — the panel shows a single indeterminate spinner rather than a
|
||||
* stepped checklist that would freeze on the first step. */
|
||||
indeterminate: boolean
|
||||
/** Gates the in-frame loader so fast creates never flash it: false until the
|
||||
* create has been pending past the debounce delay (or it errors). Until then
|
||||
* the prior workspace content stays visible and a fast create swaps straight
|
||||
* to its terminal. */
|
||||
/** Whether older callers have explicitly revealed the in-frame loader. New
|
||||
* background creates set this immediately so the faux tab strip stays stable
|
||||
* from create start through terminal handoff. */
|
||||
loaderVisible: boolean
|
||||
error?: string
|
||||
request: WorktreeCreationRequest
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { resolveLeftTitlebarChromeLayout } from './titlebar-left-chrome'
|
||||
|
||||
describe('resolveLeftTitlebarChromeLayout', () => {
|
||||
it('mounts in normal workspace chrome', () => {
|
||||
expect(
|
||||
resolveLeftTitlebarChromeLayout({
|
||||
workspaceChromeActive: true,
|
||||
stackedSidebarOpen: false,
|
||||
creationLayoutActive: false,
|
||||
sidebarOpen: true
|
||||
})
|
||||
).toEqual({ shouldMount: true, isFloating: false })
|
||||
})
|
||||
|
||||
it('mounts for stacked sidebar pages without floating', () => {
|
||||
expect(
|
||||
resolveLeftTitlebarChromeLayout({
|
||||
workspaceChromeActive: false,
|
||||
stackedSidebarOpen: true,
|
||||
creationLayoutActive: false,
|
||||
sidebarOpen: true
|
||||
})
|
||||
).toEqual({ shouldMount: true, isFloating: false })
|
||||
})
|
||||
|
||||
it('preserves the left titlebar chrome during visible worktree creation', () => {
|
||||
expect(
|
||||
resolveLeftTitlebarChromeLayout({
|
||||
workspaceChromeActive: false,
|
||||
stackedSidebarOpen: false,
|
||||
creationLayoutActive: true,
|
||||
sidebarOpen: true
|
||||
})
|
||||
).toEqual({ shouldMount: true, isFloating: false })
|
||||
})
|
||||
|
||||
it('floats during creation when the sidebar is collapsed', () => {
|
||||
expect(
|
||||
resolveLeftTitlebarChromeLayout({
|
||||
workspaceChromeActive: false,
|
||||
stackedSidebarOpen: false,
|
||||
creationLayoutActive: true,
|
||||
sidebarOpen: false
|
||||
})
|
||||
).toEqual({ shouldMount: true, isFloating: true })
|
||||
})
|
||||
|
||||
it('stays unmounted on full-width titlebar pages', () => {
|
||||
expect(
|
||||
resolveLeftTitlebarChromeLayout({
|
||||
workspaceChromeActive: false,
|
||||
stackedSidebarOpen: false,
|
||||
creationLayoutActive: false,
|
||||
sidebarOpen: false
|
||||
})
|
||||
).toEqual({ shouldMount: false, isFloating: false })
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,24 @@
|
||||
export type LeftTitlebarChromeLayoutInput = {
|
||||
workspaceChromeActive: boolean
|
||||
stackedSidebarOpen: boolean
|
||||
creationLayoutActive: boolean
|
||||
sidebarOpen: boolean
|
||||
}
|
||||
|
||||
export type LeftTitlebarChromeLayout = {
|
||||
shouldMount: boolean
|
||||
isFloating: boolean
|
||||
}
|
||||
|
||||
export function resolveLeftTitlebarChromeLayout({
|
||||
workspaceChromeActive,
|
||||
stackedSidebarOpen,
|
||||
creationLayoutActive,
|
||||
sidebarOpen
|
||||
}: LeftTitlebarChromeLayoutInput): LeftTitlebarChromeLayout {
|
||||
const shouldMount = workspaceChromeActive || stackedSidebarOpen || creationLayoutActive
|
||||
return {
|
||||
shouldMount,
|
||||
isFloating: shouldMount && !sidebarOpen && !stackedSidebarOpen
|
||||
}
|
||||
}
|
||||
@@ -17,11 +17,6 @@ import {
|
||||
import type { CreateWorktreeResult } from '../../../shared/types'
|
||||
import type { WorktreeCreationRequest } from '@/lib/pending-worktree-creation'
|
||||
|
||||
// Why: most local creates finish in well under this window; holding the loader
|
||||
// back this long means a fast create swaps prior content → terminal with no
|
||||
// loader flash, while a genuinely slow create still surfaces one promptly.
|
||||
const CREATION_LOADER_DEBOUNCE_MS = 280
|
||||
|
||||
// Why: mirrors the startup-opt the composer used to build inline. The renderer
|
||||
// only seeds the first terminal when the backend did not already spawn it.
|
||||
function buildStartupOpt(
|
||||
@@ -104,12 +99,11 @@ async function executeWorktreeCreation(
|
||||
return
|
||||
}
|
||||
const message = getWorkspaceCreateErrorToastMessage(formatWorkspaceCreateError(error))
|
||||
// Why: an error must surface immediately even if it lands before the loader
|
||||
// debounce fired, so force the loader visible alongside the error.
|
||||
// Why: an error must stay on the same creation surface that owns the faux
|
||||
// tab strip, rather than falling back to stale previous-workspace tabs.
|
||||
useAppStore.getState().updatePendingWorktreeCreation(creationId, {
|
||||
status: 'error',
|
||||
error: message,
|
||||
loaderVisible: true
|
||||
error: message
|
||||
})
|
||||
// Why: only toast when the panel isn't already showing this error (the user
|
||||
// navigated away), so a visible failure isn't announced twice.
|
||||
@@ -207,19 +201,15 @@ export function runBackgroundWorktreeCreation(request: WorktreeCreationRequest):
|
||||
phase: 'fetching',
|
||||
status: 'creating',
|
||||
indeterminate,
|
||||
loaderVisible: false,
|
||||
// Why: the creation surface owns the tab strip immediately. Delaying this
|
||||
// caused the real workspace tab bar to flash out when the debounce elapsed.
|
||||
loaderVisible: true,
|
||||
request
|
||||
})
|
||||
// Why: the creation panel only renders under the terminal view (App content
|
||||
// router), so force it active so the panel is what fills the content area.
|
||||
store.setActiveView('terminal')
|
||||
store.setSidebarOpen(true)
|
||||
// Why: debounce the loader so a fast create never flashes it. The prior
|
||||
// workspace stays visible until the delay elapses; if the create resolves
|
||||
// first, removePendingWorktreeCreation clears the entry and this update no-ops.
|
||||
setTimeout(() => {
|
||||
useAppStore.getState().updatePendingWorktreeCreation(creationId, { loaderVisible: true })
|
||||
}, CREATION_LOADER_DEBOUNCE_MS)
|
||||
void executeWorktreeCreation(creationId, request)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { shouldShowWorktreeCreationSurface } from './worktree-creation-surface'
|
||||
|
||||
describe('shouldShowWorktreeCreationSurface', () => {
|
||||
it('shows the creation surface as soon as an active pending creation exists', () => {
|
||||
expect(
|
||||
shouldShowWorktreeCreationSurface({
|
||||
activeView: 'terminal',
|
||||
activePendingCreationId: 'creation-1',
|
||||
hasActivePendingCreation: true
|
||||
})
|
||||
).toBe(true)
|
||||
})
|
||||
|
||||
it('stays hidden when the active pending id no longer has an entry', () => {
|
||||
expect(
|
||||
shouldShowWorktreeCreationSurface({
|
||||
activeView: 'terminal',
|
||||
activePendingCreationId: 'creation-1',
|
||||
hasActivePendingCreation: false
|
||||
})
|
||||
).toBe(false)
|
||||
})
|
||||
|
||||
it('stays hidden outside the terminal surface', () => {
|
||||
expect(
|
||||
shouldShowWorktreeCreationSurface({
|
||||
activeView: 'settings',
|
||||
activePendingCreationId: 'creation-1',
|
||||
hasActivePendingCreation: true
|
||||
})
|
||||
).toBe(false)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,15 @@
|
||||
import type { UISlice } from '@/store/slices/ui'
|
||||
|
||||
export type WorktreeCreationSurfaceInput = {
|
||||
activeView: UISlice['activeView']
|
||||
activePendingCreationId: string | null
|
||||
hasActivePendingCreation: boolean
|
||||
}
|
||||
|
||||
export function shouldShowWorktreeCreationSurface({
|
||||
activeView,
|
||||
activePendingCreationId,
|
||||
hasActivePendingCreation
|
||||
}: WorktreeCreationSurfaceInput): boolean {
|
||||
return activeView === 'terminal' && activePendingCreationId !== null && hasActivePendingCreation
|
||||
}
|
||||
Reference in New Issue
Block a user