diff --git a/src/components/WorkspaceControls.client.test.tsx b/src/components/WorkspaceControls.client.test.tsx new file mode 100644 index 000000000..efd0e10ab --- /dev/null +++ b/src/components/WorkspaceControls.client.test.tsx @@ -0,0 +1,41 @@ +import { render } from 'solid-js/web'; +import { afterEach, beforeEach, expect, it, vi } from 'vitest'; +import { setStore, store } from '../store/core'; +import { WorkspaceControls } from './WorkspaceControls'; + +vi.mock('../lib/ipc', () => ({ invoke: vi.fn(async () => ({})) })); + +let dispose: () => void; + +function boardButton(): HTMLButtonElement { + const button = document.querySelector('[aria-label^="Board:"]'); + if (!button) throw new Error('missing board button'); + return button; +} + +beforeEach(() => { + setStore('boardView', true); + setStore('boardPeek', true); + setStore('showNewTaskPanel', false); + setStore('githubIssuesProjectId', null); + const root = document.createElement('div'); + document.body.append(root); + dispose = render(() => , root); +}); +afterEach(() => { + dispose(); + document.body.replaceChildren(); +}); + +it('closes the task open beside the board, keeping the board', () => { + boardButton().click(); + expect(store.boardPeek).toBe(false); + expect(store.boardView).toBe(true); +}); + +it('leaves a draft beside the board to its own Cancel', () => { + setStore('showNewTaskPanel', true); + boardButton().click(); + expect(store.boardPeek).toBe(true); + expect(store.boardView).toBe(true); +}); diff --git a/src/components/WorkspaceControls.tsx b/src/components/WorkspaceControls.tsx index 2ea8231b4..8b9f2efa2 100644 --- a/src/components/WorkspaceControls.tsx +++ b/src/components/WorkspaceControls.tsx @@ -9,8 +9,10 @@ import { workspaceViewTransitionTypes, type WorkspaceView, } from '../store/store'; +import { boardShown } from '../store/project-pages'; import { mod } from '../lib/platform'; import { withViewTransition } from '../lib/viewTransition'; +import { closeSidePanel } from './BoardSidePanel'; import { ChevronLeftAltIcon, GearIcon } from './icons'; import { FeatureHint } from './FeatureHint'; import { IconButton } from './IconButton'; @@ -82,6 +84,19 @@ function visibleTaskCount(): number { return store.taskOrder.filter((id) => !isHiddenAgentTaskId(id)).length; } +/** + * Shows `view`. The board's own button, pressed while a task is open beside + * the board, closes that side panel instead, as its close button and Escape + * do; a draft stays, left to its own Cancel. + */ +function selectView(view: WorkspaceView): void { + if (view === 'board' && boardShown() && store.boardPeek && !store.showNewTaskPanel) { + closeSidePanel(); + return; + } + withViewTransition(() => setWorkspaceView(view), workspaceViewTransitionTypes(view)); +} + /** Focus, tiles or board: three views of the same tasks, one pressed at a time. */ function WorkspaceViewToggle() { let boardButton: HTMLButtonElement | undefined; @@ -96,12 +111,7 @@ function WorkspaceViewToggle() { title={item.title} label={item.title} pressed={workspaceView() === item.view} - onClick={() => - withViewTransition( - () => setWorkspaceView(item.view), - workspaceViewTransitionTypes(item.view), - ) - } + onClick={() => selectView(item.view)} > {item.icon()}