Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/components/WorkspaceControls.client.test.tsx
Original file line number Diff line number Diff line change
@@ -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<HTMLButtonElement>('[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(() => <WorkspaceControls />, 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);
});
22 changes: 16 additions & 6 deletions src/components/WorkspaceControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand All @@ -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()}
</ToggleButton>
Expand Down