Skip to content
Closed
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
29 changes: 25 additions & 4 deletions src/features/app/components/PinnedThreadList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ const statusMap = {
};

const baseProps = {
rows: [{ thread, depth: 0, workspaceId: "ws-1" }],
rows: [{ thread, depth: 0, workspaceId: "ws-1", hasChildren: false, isCollapsed: false }],
activeWorkspaceId: "ws-1",
activeThreadId: "thread-1",
threadStatusById: statusMap,
getThreadTime: () => "1h",
isThreadPinned: () => true,
onToggleThreadCollapsed: vi.fn(),
onSelectThread: vi.fn(),
onShowThreadMenu: vi.fn(),
};
Expand Down Expand Up @@ -76,8 +77,8 @@ describe("PinnedThreadList", () => {
<PinnedThreadList
{...baseProps}
rows={[
{ thread, depth: 0, workspaceId: "ws-1" },
{ thread: otherThread, depth: 0, workspaceId: "ws-2" },
{ thread, depth: 0, workspaceId: "ws-1", hasChildren: false, isCollapsed: false },
{ thread: otherThread, depth: 0, workspaceId: "ws-2", hasChildren: false, isCollapsed: false },
]}
onSelectThread={onSelectThread}
onShowThreadMenu={onShowThreadMenu}
Expand Down Expand Up @@ -106,7 +107,7 @@ describe("PinnedThreadList", () => {
const { container } = render(
<PinnedThreadList
{...baseProps}
rows={[{ thread: otherThread, depth: 0, workspaceId: "ws-2" }]}
rows={[{ thread: otherThread, depth: 0, workspaceId: "ws-2", hasChildren: false, isCollapsed: false }]}
threadStatusById={{
"thread-1": { isProcessing: false, hasUnread: false, isReviewing: true },
"thread-2": { isProcessing: true, hasUnread: false, isReviewing: false },
Expand All @@ -121,4 +122,24 @@ describe("PinnedThreadList", () => {
expect(row?.querySelector(".thread-status")?.className).toContain("unread");
expect(row?.querySelector(".thread-status")?.className).not.toContain("processing");
});

it("renders a collapse toggle for pinned threads with children", () => {
const onToggleThreadCollapsed = vi.fn();
const onSelectThread = vi.fn();

render(
<PinnedThreadList
{...baseProps}
rows={[{ thread, depth: 0, workspaceId: "ws-1", hasChildren: true, isCollapsed: true }]}
onToggleThreadCollapsed={onToggleThreadCollapsed}
onSelectThread={onSelectThread}
/>,
);

const toggle = screen.getByRole("button", { name: "Expand subagent threads" });
fireEvent.click(toggle);

expect(onToggleThreadCollapsed).toHaveBeenCalledWith("ws-1", "thread-1");
expect(onSelectThread).not.toHaveBeenCalled();
});
});
9 changes: 8 additions & 1 deletion src/features/app/components/PinnedThreadList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ type PinnedThreadRow = {
thread: ThreadSummary;
depth: number;
workspaceId: string;
hasChildren: boolean;
isCollapsed: boolean;
};

type PinnedThreadListProps = {
Expand All @@ -20,6 +22,7 @@ type PinnedThreadListProps = {
getThreadTime: (thread: ThreadSummary) => string | null;
getThreadArgsBadge?: (workspaceId: string, threadId: string) => string | null;
isThreadPinned: (workspaceId: string, threadId: string) => boolean;
onToggleThreadCollapsed?: (workspaceId: string, threadId: string) => void;
onSelectThread: (workspaceId: string, threadId: string) => void;
onShowThreadMenu: (
event: MouseEvent,
Expand All @@ -39,19 +42,23 @@ export function PinnedThreadList({
getThreadTime,
getThreadArgsBadge,
isThreadPinned,
onToggleThreadCollapsed,
onSelectThread,
onShowThreadMenu,
}: PinnedThreadListProps) {
return (
<div className="thread-list pinned-thread-list">
{rows.map(({ thread, depth, workspaceId }) => {
{rows.map(({ thread, depth, workspaceId, hasChildren, isCollapsed }) => {
return (
<ThreadRow
key={`${workspaceId}:${thread.id}`}
thread={thread}
depth={depth}
workspaceId={workspaceId}
indentUnit={14}
hasChildren={hasChildren}
isCollapsed={isCollapsed}
onToggleThreadCollapsed={onToggleThreadCollapsed}
activeWorkspaceId={activeWorkspaceId}
activeThreadId={activeThreadId}
threadStatusById={threadStatusById}
Expand Down
54 changes: 52 additions & 2 deletions src/features/app/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {
WorkspaceInfo,
} from "../../../types";
import { createPortal } from "react-dom";
import { memo, useCallback, useEffect, useMemo, useState } from "react";
import { memo, useCallback, useEffect, useMemo, useRef, useState } from "react";
import type { MouseEvent, RefObject } from "react";
import { FolderOpen } from "lucide-react";
import Copy from "lucide-react/dist/esm/icons/copy";
Expand Down Expand Up @@ -52,6 +52,8 @@ type WorkspaceGroupSection = {
type FlatThreadRow = {
thread: ThreadSummary;
depth: number;
hasChildren: boolean;
isCollapsed: boolean;
workspaceId: string;
workspaceName: string;
};
Expand Down Expand Up @@ -243,6 +245,26 @@ export const Sidebar = memo(function Sidebar({
),
[userInputRequests],
);
const collapsedThreadTreesRef = useRef(new Set<string>());
const [collapsedThreadTreesVersion, setCollapsedThreadTreesVersion] = useState(0);
const isThreadCollapsed = useCallback(
(workspaceId: string, threadId: string) =>
collapsedThreadTreesRef.current.has(`${workspaceId}:${threadId}`),
[],
);
const toggleThreadCollapsed = useCallback(
(workspaceId: string, threadId: string) => {
const key = `${workspaceId}:${threadId}`;
const collapsed = collapsedThreadTreesRef.current;
if (collapsed.has(key)) {
collapsed.delete(key);
} else {
collapsed.add(key);
}
setCollapsedThreadTreesVersion((prev) => prev + 1);
},
[],
);

const isWorkspaceMatch = useCallback(
(workspace: WorkspaceInfo) => {
Expand Down Expand Up @@ -302,7 +324,12 @@ export const Sidebar = memo(function Sidebar({
);

const pinnedThreadRows = useMemo(() => {
type ThreadRow = { thread: ThreadSummary; depth: number };
type ThreadRow = {
thread: ThreadSummary;
depth: number;
hasChildren: boolean;
isCollapsed: boolean;
};
const groups: Array<{
pinTime: number;
workspaceId: string;
Expand All @@ -323,6 +350,8 @@ export const Sidebar = memo(function Sidebar({
workspace.id,
getPinTimestamp,
pinnedThreadsVersion,
collapsedThreadTreesVersion,
isThreadCollapsed,
);
if (!pinnedRows.length) {
return;
Expand Down Expand Up @@ -369,6 +398,8 @@ export const Sidebar = memo(function Sidebar({
getThreadRows,
getPinTimestamp,
pinnedThreadsVersion,
collapsedThreadTreesVersion,
isThreadCollapsed,
isWorkspaceMatch,
]);

Expand Down Expand Up @@ -531,6 +562,8 @@ export const Sidebar = memo(function Sidebar({
workspace.id,
getPinTimestamp,
pinnedThreadsVersion,
collapsedThreadTreesVersion,
isThreadCollapsed,
);
if (!unpinnedRows.length) {
return;
Expand Down Expand Up @@ -596,6 +629,8 @@ export const Sidebar = memo(function Sidebar({
getSortTimestamp,
getThreadRows,
pinnedThreadsVersion,
collapsedThreadTreesVersion,
isThreadCollapsed,
threadListOrganizeMode,
threadsByWorkspace,
]);
Expand All @@ -604,18 +639,22 @@ export const Sidebar = memo(function Sidebar({
() => [
sortedGroupedWorkspaces,
flatThreadRows,
pinnedThreadRows,
threadsByWorkspace,
expandedWorkspaces,
normalizedQuery,
threadListOrganizeMode,
collapsedThreadTreesVersion,
],
[
sortedGroupedWorkspaces,
flatThreadRows,
pinnedThreadRows,
threadsByWorkspace,
expandedWorkspaces,
normalizedQuery,
threadListOrganizeMode,
collapsedThreadTreesVersion,
],
);
const { sidebarBodyRef, scrollFade, updateScrollFade } =
Expand Down Expand Up @@ -871,6 +910,7 @@ export const Sidebar = memo(function Sidebar({
getThreadTime={getThreadTime}
getThreadArgsBadge={getThreadArgsBadge}
isThreadPinned={isThreadPinned}
onToggleThreadCollapsed={toggleThreadCollapsed}
onSelectThread={onSelectThread}
onShowThreadMenu={showThreadMenu}
getWorkspaceLabel={isThreadsOnlyMode ? getWorkspaceLabel : undefined}
Expand Down Expand Up @@ -904,6 +944,7 @@ export const Sidebar = memo(function Sidebar({
getThreadTime={getThreadTime}
getThreadArgsBadge={getThreadArgsBadge}
isThreadPinned={isThreadPinned}
onToggleThreadCollapsed={toggleThreadCollapsed}
onSelectThread={onSelectThread}
onShowThreadMenu={showThreadMenu}
getWorkspaceLabel={getWorkspaceLabel}
Expand Down Expand Up @@ -970,6 +1011,8 @@ export const Sidebar = memo(function Sidebar({
entry.id,
getPinTimestamp,
pinnedThreadsVersion,
collapsedThreadTreesVersion,
isThreadCollapsed,
);
const nextCursor =
threadListCursorByWorkspace[entry.id] ?? null;
Expand Down Expand Up @@ -1097,6 +1140,8 @@ export const Sidebar = memo(function Sidebar({
isThreadPinned={isThreadPinned}
getPinTimestamp={getPinTimestamp}
pinnedThreadsVersion={pinnedThreadsVersion}
collapsedThreadTreesVersion={collapsedThreadTreesVersion}
isThreadCollapsed={isThreadCollapsed}
onSelectWorkspace={onSelectWorkspace}
onConnectWorkspace={onConnectWorkspace}
onToggleWorkspaceCollapse={onToggleWorkspaceCollapse}
Expand All @@ -1105,6 +1150,7 @@ export const Sidebar = memo(function Sidebar({
onShowWorktreeMenu={showCloneMenu}
onToggleExpanded={handleToggleExpanded}
onLoadOlderThreads={onLoadOlderThreads}
onToggleThreadCollapsed={toggleThreadCollapsed}
sectionLabel="Clone agents"
sectionIcon={
<Copy className="worktree-header-icon" aria-hidden />
Expand All @@ -1131,6 +1177,8 @@ export const Sidebar = memo(function Sidebar({
isThreadPinned={isThreadPinned}
getPinTimestamp={getPinTimestamp}
pinnedThreadsVersion={pinnedThreadsVersion}
collapsedThreadTreesVersion={collapsedThreadTreesVersion}
isThreadCollapsed={isThreadCollapsed}
onSelectWorkspace={onSelectWorkspace}
onConnectWorkspace={onConnectWorkspace}
onToggleWorkspaceCollapse={onToggleWorkspaceCollapse}
Expand All @@ -1139,6 +1187,7 @@ export const Sidebar = memo(function Sidebar({
onShowWorktreeMenu={showWorktreeMenu}
onToggleExpanded={handleToggleExpanded}
onLoadOlderThreads={onLoadOlderThreads}
onToggleThreadCollapsed={toggleThreadCollapsed}
/>
)}
{showThreadList && (
Expand All @@ -1159,6 +1208,7 @@ export const Sidebar = memo(function Sidebar({
isThreadPinned={isThreadPinned}
onToggleExpanded={handleToggleExpanded}
onLoadOlderThreads={onLoadOlderThreads}
onToggleThreadCollapsed={toggleThreadCollapsed}
onSelectThread={onSelectThread}
onShowThreadMenu={showThreadMenu}
/>
Expand Down
27 changes: 24 additions & 3 deletions src/features/app/components/ThreadList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const statusMap = {
const baseProps = {
workspaceId: "ws-1",
pinnedRows: [],
unpinnedRows: [{ thread, depth: 0 }],
unpinnedRows: [{ thread, depth: 0, hasChildren: false, isCollapsed: false }],
totalThreadRoots: 1,
isExpanded: false,
nextCursor: null,
Expand All @@ -37,6 +37,7 @@ const baseProps = {
isThreadPinned: () => false,
onToggleExpanded: vi.fn(),
onLoadOlderThreads: vi.fn(),
onToggleThreadCollapsed: vi.fn(),
onSelectThread: vi.fn(),
onShowThreadMenu: vi.fn(),
};
Expand Down Expand Up @@ -111,8 +112,8 @@ describe("ThreadList", () => {
{...baseProps}
nested
unpinnedRows={[
{ thread, depth: 0 },
{ thread: nestedThread, depth: 1 },
{ thread, depth: 0, hasChildren: false, isCollapsed: false },
{ thread: nestedThread, depth: 1, hasChildren: false, isCollapsed: false },
]}
onShowThreadMenu={onShowThreadMenu}
/>,
Expand All @@ -134,10 +135,30 @@ describe("ThreadList", () => {
);
});

it("renders a collapse toggle for threads with children", () => {
const onToggleThreadCollapsed = vi.fn();
const onSelectThread = vi.fn();
render(
<ThreadList
{...baseProps}
unpinnedRows={[{ thread, depth: 0, hasChildren: true, isCollapsed: true }]}
onToggleThreadCollapsed={onToggleThreadCollapsed}
onSelectThread={onSelectThread}
/>,
);

const toggle = screen.getByRole("button", { name: "Expand subagent threads" });
fireEvent.click(toggle);

expect(onToggleThreadCollapsed).toHaveBeenCalledWith("ws-1", "thread-1");
expect(onSelectThread).not.toHaveBeenCalled();
});

it("shows blue unread-style status when a thread is waiting for user input", () => {
const { container } = render(
<ThreadList
{...baseProps}
onToggleThreadCollapsed={vi.fn()}
threadStatusById={{
"thread-1": { isProcessing: true, hasUnread: false, isReviewing: false },
"thread-2": { isProcessing: false, hasUnread: false, isReviewing: false },
Expand Down
Loading
Loading