Skip to content

Commit ffe001b

Browse files
donjor-agent[bot]rsi-pr-agent
authored andcommitted
feat(web): thread groups span projects and can mark a parent thread (#1829)
Squashes: - 2c59e70 feat(web): thread groups span projects and can mark a parent thread (#1829) (#1829) - ad5610a fixup! feat(web): thread groups span projects and can mark a parent thread (#1829) (#1829) Fork-Domain: thread-ordering Fork-Tier: qol
1 parent de66979 commit ffe001b

20 files changed

Lines changed: 734 additions & 613 deletions

‎apps/web/src/components/Sidebar.drag.fork.test.ts‎

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
import { describe, expect, it } from "vite-plus/test";
22

3-
import { createSidebarCollisionDetection } from "./Sidebar.drag.ts";
3+
import { createSidebarCollisionDetection, createSidebarSortingStrategy } from "./Sidebar.drag.ts";
44
import {
55
sidebarListItemId,
66
sidebarMarkerId,
77
type SidebarListItem,
88
type SidebarSection,
99
} from "./Sidebar.logic.ts";
10-
import {
11-
sidebarThreadGroupHeaderMarker,
12-
sidebarThreadGroupKey,
13-
} from "./SidebarThreadGroup.markers.ts";
10+
import { sidebarThreadGroupHeaderMarker } from "./SidebarThreadGroup.markers.ts";
1411

1512
const thread = (key: string, section: SidebarSection): SidebarListItem => ({
1613
kind: "thread",
@@ -27,7 +24,7 @@ const rect = (top: number, height: number) => ({
2724
width: 260,
2825
});
2926

30-
const HEADER_MARKER = sidebarThreadGroupHeaderMarker(sidebarThreadGroupKey("project", "group"));
27+
const HEADER_MARKER = sidebarThreadGroupHeaderMarker("group");
3128
const HEADER_ID = sidebarMarkerId(HEADER_MARKER);
3229

3330
/** The divider row renders whether or not Pins holds anything, and its label
@@ -118,3 +115,32 @@ describe("createSidebarCollisionDetection group headers", () => {
118115
expect(detector(withoutHeader)[0]?.id).toBe("member");
119116
});
120117
});
118+
119+
describe("createSidebarSortingStrategy folded group parent", () => {
120+
it("opens a gap the height of a taller lifted card", () => {
121+
// A collapsed group's parent carries its fold strip, so it outgrows a card.
122+
const items: SidebarListItem[] = [
123+
{ kind: "marker", marker: "pinned-header" },
124+
{ kind: "marker", marker: "pinned-divider" },
125+
thread("above", "active"),
126+
thread("parent", "active"),
127+
{ kind: "marker", marker: "settled-header" },
128+
{ kind: "marker", marker: "settled-placeholder" },
129+
];
130+
const rects = [
131+
rect(100, 0),
132+
rect(101, 0),
133+
rect(102, 82),
134+
rect(185, 110),
135+
rect(296, 32),
136+
rect(329, 0),
137+
];
138+
const strategy = createSidebarSortingStrategy({
139+
items,
140+
settledOrder: [],
141+
settledExpanded: false,
142+
});
143+
const args = { activeIndex: 3, overIndex: 2, activeNodeRect: rects[3]!, rects };
144+
expect(strategy({ ...args, index: 2 })?.y).toBe(111);
145+
});
146+
});

‎apps/web/src/components/Sidebar.drag.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,9 @@ export function createSidebarSortingStrategy(input: {
209209
? labelHeight
210210
: item.kind === "marker" && item.marker.endsWith("placeholder")
211211
? slimHeight
212-
: moved
212+
: moved && target.section !== active.section
213213
? fallback
214-
: (rect?.height ?? fallback);
214+
: (rect?.height ?? fallback); // fork-hook: thread-ordering/group-fold-drag-height
215215
});
216216
const firstShelf = items.findIndex(isShelfHeader);
217217
const shelfRect = rects[firstShelf];

‎apps/web/src/components/Sidebar.logic.fork.test.ts‎

Lines changed: 63 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,28 @@ describe("sidebar thread groups", () => {
1010
const threads = [
1111
{ id: "thread-a", projectKey: "project-a" },
1212
{ id: "thread-b", projectKey: "project-a" },
13-
{ id: "thread-c", projectKey: "project-a" },
13+
{ id: "thread-c", projectKey: "project-b" },
1414
];
1515

16-
it("renders each visible group once at its first member", () => {
16+
it("renders each visible group once at its first member, across projects", () => {
1717
expect(
1818
buildSidebarThreadGroupLayout({
1919
threads,
20-
groupsByProject: {
21-
"project-a": [
22-
{
23-
id: "group-1",
24-
title: "Related work",
25-
threadIds: ["thread-b", "thread-c"],
26-
collapsed: false,
27-
},
28-
],
29-
},
20+
groups: [
21+
{
22+
id: "group-1",
23+
title: "Related work",
24+
threadIds: ["thread-b", "thread-c"],
25+
collapsed: false,
26+
},
27+
],
3028
getId: (thread) => thread.id,
31-
getProjectKey: (thread) => thread.projectKey,
3229
}),
3330
).toEqual([
3431
{ kind: "thread", thread: threads[0] },
3532
{
3633
kind: "group",
37-
projectKey: "project-a",
34+
hasParent: false,
3835
group: {
3936
id: "group-1",
4037
title: "Related work",
@@ -52,23 +49,20 @@ describe("sidebar thread groups", () => {
5249
expect(
5350
buildSidebarThreadGroupLayout({
5451
threads: automaticThreads,
55-
groupsByProject: {
56-
"project-a": [
57-
{
58-
id: "group-1",
59-
title: "Related work",
60-
threadIds: ["thread-b", "thread-c"],
61-
collapsed: false,
62-
},
63-
],
64-
},
52+
groups: [
53+
{
54+
id: "group-1",
55+
title: "Related work",
56+
threadIds: ["thread-b", "thread-c"],
57+
collapsed: false,
58+
},
59+
],
6560
getId: (thread) => thread.id,
66-
getProjectKey: (thread) => thread.projectKey,
6761
}),
6862
).toEqual([
6963
{
7064
kind: "group",
71-
projectKey: "project-a",
65+
hasParent: false,
7266
group: {
7367
id: "group-1",
7468
title: "Related work",
@@ -81,6 +75,31 @@ describe("sidebar thread groups", () => {
8175
]);
8276
});
8377

78+
it("leads a group with its parent wherever the parent sorts", () => {
79+
const groups = [
80+
{
81+
id: "group-1",
82+
title: "Related work",
83+
threadIds: ["thread-a", "thread-b", "thread-c"],
84+
collapsed: false,
85+
parentThreadId: "thread-c",
86+
},
87+
];
88+
const layout = buildSidebarThreadGroupLayout({ threads, groups, getId: (thread) => thread.id });
89+
expect(layout).toHaveLength(1);
90+
expect(layout[0]).toMatchObject({
91+
hasParent: true,
92+
threads: [threads[2], threads[0], threads[1]],
93+
});
94+
// A filtered-out parent leads nothing, so no row indents as its child.
95+
const filtered = buildSidebarThreadGroupLayout({
96+
threads: threads.slice(0, 2),
97+
groups,
98+
getId: (thread) => thread.id,
99+
});
100+
expect(filtered[0]).toMatchObject({ hasParent: false });
101+
});
102+
84103
it("offers group creation only for an eligible multi-selection", () => {
85104
expect(buildCreateThreadGroupContextMenuItem({ count: 2, eligible: true })).toMatchObject({
86105
id: "create-thread-group",
@@ -99,6 +118,7 @@ describe("sidebar thread groups", () => {
99118
{ id: "group-2", title: "Destination" },
100119
],
101120
currentGroupId: "group-1",
121+
isGroupParent: false,
102122
}),
103123
).toEqual([
104124
{
@@ -114,6 +134,7 @@ describe("sidebar thread groups", () => {
114134
icon: "folder",
115135
separatorBefore: false,
116136
},
137+
{ id: "set-group-parent", label: "Set as group parent" },
117138
]);
118139
});
119140
});
@@ -140,18 +161,15 @@ describe("buildSidebarListItems", () => {
140161
it("emits only a collapsed group's anchor as an active row", () => {
141162
const layout = buildSidebarThreadGroupLayout({
142163
threads: groupThreads,
143-
groupsByProject: {
144-
"project-a": [
145-
{
146-
id: "group-1",
147-
title: "Related work",
148-
threadIds: ["thread-b", "thread-c"],
149-
collapsed: true,
150-
},
151-
],
152-
},
164+
groups: [
165+
{
166+
id: "group-1",
167+
title: "Related work",
168+
threadIds: ["thread-b", "thread-c"],
169+
collapsed: true,
170+
},
171+
],
153172
getId: (thread) => thread.id,
154-
getProjectKey: (thread) => thread.projectKey,
155173
});
156174
const keys = visibleKeys(layout);
157175
expect(keys).toEqual(["thread-a", "thread-b"]);
@@ -180,18 +198,15 @@ describe("buildSidebarListItems", () => {
180198
it("keeps an expanded group's rows contiguous in layout order", () => {
181199
const layout = buildSidebarThreadGroupLayout({
182200
threads: groupThreads,
183-
groupsByProject: {
184-
"project-a": [
185-
{
186-
id: "group-1",
187-
title: "Related work",
188-
threadIds: ["thread-b", "thread-c"],
189-
collapsed: false,
190-
},
191-
],
192-
},
201+
groups: [
202+
{
203+
id: "group-1",
204+
title: "Related work",
205+
threadIds: ["thread-b", "thread-c"],
206+
collapsed: false,
207+
},
208+
],
193209
getId: (thread) => thread.id,
194-
getProjectKey: (thread) => thread.projectKey,
195210
});
196211

197212
expect(

‎apps/web/src/components/Sidebar.logic.ts‎

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -460,47 +460,40 @@ export type SidebarThreadGroupLayoutItem<T> =
460460
| { readonly kind: "thread"; readonly thread: T }
461461
| {
462462
readonly kind: "group";
463-
readonly projectKey: string;
464463
readonly group: SidebarThreadGroup;
464+
/** Visible members in list order, the group's parent first. */
465465
readonly threads: readonly T[];
466-
};
466+
/** The parent is among the visible members; a filtered-out one leads nothing. */
467+
readonly hasParent: boolean;
468+
}; // fork-hook: thread-ordering/group-layout-item
467469

468470
export function buildSidebarThreadGroupLayout<T>(input: {
469471
readonly threads: readonly T[];
470-
readonly groupsByProject: Readonly<Record<string, readonly SidebarThreadGroup[]>>;
472+
readonly groups: readonly SidebarThreadGroup[];
471473
readonly getId: (thread: T) => string;
472-
readonly getProjectKey: (thread: T) => string;
473474
}): SidebarThreadGroupLayoutItem<T>[] {
474-
const visibleById = new Map(input.threads.map((thread) => [input.getId(thread), thread]));
475475
const groupByThreadId = new Map<
476476
string,
477-
{ readonly projectKey: string; readonly group: SidebarThreadGroup; readonly threads: T[] }
477+
{ readonly group: SidebarThreadGroup; readonly threads: T[]; readonly hasParent: boolean }
478478
>();
479-
for (const [projectKey, groups] of Object.entries(input.groupsByProject)) {
480-
for (const group of groups) {
481-
const threads = input.threads.filter(
482-
(thread) =>
483-
input.getProjectKey(thread) === projectKey &&
484-
group.threadIds.includes(input.getId(thread)),
485-
);
486-
if (threads.length < 2) continue;
487-
const entry = { projectKey, group, threads };
488-
for (const threadId of group.threadIds) {
489-
if (visibleById.has(threadId)) groupByThreadId.set(threadId, entry);
490-
}
491-
}
479+
for (const group of input.groups) {
480+
const threads = input.threads.filter((thread) => group.threadIds.includes(input.getId(thread)));
481+
if (threads.length < 2) continue;
482+
const parentIndex = threads.findIndex((thread) => input.getId(thread) === group.parentThreadId);
483+
if (parentIndex > 0) threads.unshift(...threads.splice(parentIndex, 1));
484+
const entry = { group, threads, hasParent: parentIndex >= 0 };
485+
for (const thread of threads) groupByThreadId.set(input.getId(thread), entry);
492486
}
493487

494488
const emittedGroups = new Set<string>();
495489
return input.threads.flatMap((thread): SidebarThreadGroupLayoutItem<T>[] => {
496490
const entry = groupByThreadId.get(input.getId(thread));
497491
if (!entry) return [{ kind: "thread", thread }];
498-
const groupKey = `${entry.projectKey}\0${entry.group.id}`;
499-
if (emittedGroups.has(groupKey)) return [];
500-
emittedGroups.add(groupKey);
492+
if (emittedGroups.has(entry.group.id)) return [];
493+
emittedGroups.add(entry.group.id);
501494
return [{ kind: "group", ...entry }];
502495
});
503-
}
496+
} // fork-hook: thread-ordering/group-layout
504497

505498
export function applySidebarThreadDrop<
506499
T extends Pick<
@@ -719,7 +712,9 @@ export type SidebarThreadGroupContextMenuId =
719712
| "create-thread-group"
720713
| "move-to-group"
721714
| `move-to-group:${string}`
722-
| "move-out-of-group";
715+
| "move-out-of-group"
716+
| "set-group-parent"
717+
| "clear-group-parent"; // fork-hook: thread-ordering/group-menu-id
723718

724719
export function isSidebarThreadGroupContextMenuId(
725720
id: string,
@@ -728,6 +723,8 @@ export function isSidebarThreadGroupContextMenuId(
728723
id === "create-thread-group" ||
729724
id === "move-to-group" ||
730725
id === "move-out-of-group" ||
726+
id === "set-group-parent" ||
727+
id === "clear-group-parent" ||
731728
id.startsWith("move-to-group:")
732729
);
733730
} // fork-hook: upstream-fixes/split-session-permissions
@@ -747,6 +744,7 @@ export function buildCreateThreadGroupContextMenuItem(input: {
747744
export function buildThreadGroupMembershipContextMenuItems(input: {
748745
readonly groups: readonly Pick<SidebarThreadGroup, "id" | "title">[];
749746
readonly currentGroupId: string | null;
747+
readonly isGroupParent: boolean;
750748
}): readonly ContextMenuItem<SidebarThreadGroupContextMenuId>[] {
751749
const availableGroups = input.groups.filter((group) => group.id !== input.currentGroupId);
752750
return [
@@ -774,9 +772,12 @@ export function buildThreadGroupMembershipContextMenuItems(input: {
774772
icon: "folder",
775773
separatorBefore: availableGroups.length === 0,
776774
},
775+
input.isGroupParent
776+
? { id: "clear-group-parent" as const, label: "Clear group parent" }
777+
: { id: "set-group-parent" as const, label: "Set as group parent" },
777778
]),
778779
];
779-
}
780+
} // fork-hook: thread-ordering/group-menu-items
780781

781782
export interface ThreadStatusPill {
782783
label:

0 commit comments

Comments
 (0)