Skip to content

Commit eb2e228

Browse files
author
Zoo (VP)
committed
fix(history): scope folder pins to the workspace filter and align empty-cwd semantics
- HistoryView: folder pins were exempt from workspace filtering, so a folder whose members all belong to another workspace still rendered as a pinned shortcut in Current Workspace mode. Keep a folder pin only when the folder is visible in the workspace-scoped projection (at least one visible member, or genuinely empty), matching buildGroupedOrganizationProjection. - taskOrganizationModel: filterByWorkspace treated cwd === "" as unfiltered, contradicting the documented "no workspace open" semantics. cwd === undefined is now the only unfiltered mode; "" filters to tasks without a workspace, matching buildGroupedOrganizationProjection.
1 parent cd43469 commit eb2e228

4 files changed

Lines changed: 120 additions & 4 deletions

File tree

‎webview-ui/src/components/history/HistoryView.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,14 +309,14 @@ const HistoryViewInner = memo(({ onDone }: HistoryViewProps) => {
309309
const renderPinnedHeader = () => {
310310
// When workspace filtering is active, exclude pins whose targets
311311
// resolve to tasks that don't exist in the current workspace.
312-
// Folder pins are kept — they are handled by the projection with
313-
// workspace filtering.
312+
// Folder pins follow the projection's workspace scoping: a folder
313+
// whose members all belong to another workspace is not visible here.
314314
const visiblePins = showAllWorkspaces
315315
? organization.pins
316316
: organization.pins.filter((pin) => {
317317
const target = pin.target
318318
if (target.kind === "folder") {
319-
return true
319+
return projection.folderProjections.some((p) => p.folderId === target.folderId)
320320
}
321321
const rootId =
322322
target.kind === "task" ? buildCanonicalTarget(target.taskId, groups) : target.rootTaskId

‎webview-ui/src/components/history/__tests__/HistoryView.taskOrganization.spec.tsx‎

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,106 @@ describe("HistoryView task organization integration", () => {
981981
expect(screen.queryByTestId("pinned-unit-t-other")).not.toBeInTheDocument()
982982
})
983983

984+
it("hides pinned folders whose members all belong to another workspace when showAllWorkspaces is false", () => {
985+
mockUseTaskOrganizationDnd.mockReturnValue({
986+
sensors: [],
987+
activeDrag: null,
988+
targetMeta: { isOverTarget: false },
989+
handleDragStart: vi.fn(),
990+
handleDragOver: vi.fn(),
991+
handleDragEnd: vi.fn(),
992+
handleDragCancel: vi.fn(),
993+
UNFILED_DROP_ZONE_ID,
994+
})
995+
996+
mockUseExtensionState.mockReturnValue({
997+
taskOrganization: {
998+
...createEmptyOrganizationState(),
999+
folders: [
1000+
{
1001+
folderId: "folder-other",
1002+
name: "Other Folder",
1003+
taskIds: ["t-other"],
1004+
createdAt: 1,
1005+
updatedAt: 1,
1006+
},
1007+
],
1008+
pins: [{ target: { kind: "folder", folderId: "folder-other" }, pinnedAt: 100 }],
1009+
},
1010+
mutateTaskOrganization: vi.fn().mockResolvedValue({
1011+
requestId: "",
1012+
success: true,
1013+
committedRevision: 1,
1014+
}),
1015+
cwd: "/test/workspace",
1016+
})
1017+
// The other workspace's task is not part of the current view.
1018+
mockUseTaskSearch.mockReturnValue({
1019+
...defaultSearchResult,
1020+
tasks: [],
1021+
})
1022+
mockUseGroupedTasks.mockReturnValue({
1023+
groups: [],
1024+
flatTasks: null,
1025+
toggleExpand: vi.fn(),
1026+
isSearchMode: false,
1027+
})
1028+
1029+
render(<HistoryView onDone={vi.fn()} />)
1030+
1031+
expect(screen.queryByTestId("pinned-folder-folder-other")).not.toBeInTheDocument()
1032+
})
1033+
1034+
it("shows a pinned folder that has a member in the current workspace", () => {
1035+
mockUseTaskOrganizationDnd.mockReturnValue({
1036+
sensors: [],
1037+
activeDrag: null,
1038+
targetMeta: { isOverTarget: false },
1039+
handleDragStart: vi.fn(),
1040+
handleDragOver: vi.fn(),
1041+
handleDragEnd: vi.fn(),
1042+
handleDragCancel: vi.fn(),
1043+
UNFILED_DROP_ZONE_ID,
1044+
})
1045+
const localTask = makeTask("t-local", { workspace: "/test/workspace" })
1046+
1047+
mockUseExtensionState.mockReturnValue({
1048+
taskOrganization: {
1049+
...createEmptyOrganizationState(),
1050+
folders: [
1051+
{
1052+
folderId: "folder-local",
1053+
name: "Local Folder",
1054+
taskIds: ["t-local"],
1055+
createdAt: 1,
1056+
updatedAt: 1,
1057+
},
1058+
],
1059+
pins: [{ target: { kind: "folder", folderId: "folder-local" }, pinnedAt: 100 }],
1060+
},
1061+
mutateTaskOrganization: vi.fn().mockResolvedValue({
1062+
requestId: "",
1063+
success: true,
1064+
committedRevision: 1,
1065+
}),
1066+
cwd: "/test/workspace",
1067+
})
1068+
mockUseTaskSearch.mockReturnValue({
1069+
...defaultSearchResult,
1070+
tasks: [localTask],
1071+
})
1072+
mockUseGroupedTasks.mockReturnValue({
1073+
groups: [makeGroup(localTask)],
1074+
flatTasks: null,
1075+
toggleExpand: vi.fn(),
1076+
isSearchMode: false,
1077+
})
1078+
1079+
render(<HistoryView onDone={vi.fn()} />)
1080+
1081+
expect(screen.getByTestId("pinned-folder-folder-local")).toBeInTheDocument()
1082+
})
1083+
9841084
it("shows pinned tasks from other workspaces when showAllWorkspaces is true", () => {
9851085
mockUseTaskOrganizationDnd.mockReturnValue({
9861086
sensors: [],

‎webview-ui/src/components/history/__tests__/taskOrganizationModel.spec.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,18 @@ describe("taskOrganizationModel", () => {
302302
expect(filterByWorkspace(entries, [t1], undefined)).toHaveLength(entries.length)
303303
})
304304

305+
it("filters to tasks without a workspace when cwd is an empty string", () => {
306+
const noWorkspace = makeTask({ id: "no-ws", workspace: "" })
307+
const local = makeTask({ id: "local", workspace: "/workspace/project" })
308+
const entries = buildFlattenedVirtualEntries(
309+
createEmptyTaskOrganizationState(),
310+
[makeGroup(noWorkspace), makeGroup(local)],
311+
[noWorkspace, local],
312+
)
313+
const filtered = filterByWorkspace(entries, [noWorkspace, local], "")
314+
expect(filtered.map((e) => e.unit?.rootTaskId)).toEqual(["no-ws"])
315+
})
316+
305317
it("filters unfiled units outside the current workspace", () => {
306318
const local = makeTask({ id: "local", workspace: "/workspace/project" })
307319
const other = makeTask({ id: "other", workspace: "/workspace/other" })

‎webview-ui/src/components/history/taskOrganizationModel.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,13 +308,17 @@ function collectDescendantsWithMaps(
308308
* Filters display entries by workspace. For folders, visible members are kept
309309
* in Current Workspace mode; folders with no visible members are hidden unless
310310
* pinned. Genuinely empty folders remain visible.
311+
*
312+
* cwd === undefined means "show all workspaces" (no filtering);
313+
* cwd === "" means "no workspace open" and filters to tasks without a
314+
* workspace, matching buildGroupedOrganizationProjection.
311315
*/
312316
export function filterByWorkspace(
313317
entries: VirtualDisplayEntry[],
314318
tasks: HistoryItem[],
315319
cwd: string | undefined,
316320
): VirtualDisplayEntry[] {
317-
if (!cwd) {
321+
if (cwd === undefined) {
318322
return entries
319323
}
320324

0 commit comments

Comments
 (0)