Skip to content

Commit 7e1fc40

Browse files
donjor-agent[bot]rsi-pr-agent
authored andcommitted
feat(web): sidebar thread groups use the section header idiom
## What Changed Thread group headers read like upstream's `Settled (N)` shelf header, and a drag picks group membership by depth, like the dnd-kit sortable-tree example. ### Look - **Header:** `Group name (N)`, hairline, chevron - **Title:** keeps width; rule takes leftovers - **Count:** own span, never truncated - **Actions:** one hover `…` menu, `ui/menu` - **Menu items:** rename, regenerate title, dissolve - **Rename:** double-click still works ### Model - **Header:** sortable marker, like Pinned - **Span:** header, members, zero-height end marker - **Depth 0:** header, plain rows - **Depth 1:** members ### Projection - **Depth:** sideways offset, 15px step, max 1 - **Row above:** allows nesting - **Row below:** may force it ### Drops - **Create:** depth 1 under a plain thread - **Join:** depth 1 under a group - **Leave:** member at depth 0 - **Reorder:** inside the group keeps membership - **Refused:** pinned rows, other projects' groups - **Dissolve:** one member left; header fades ### Cues - **Outline:** `ring-1 ring-primary` on the target - **Landing:** `bg-primary/8` slot, projected depth ### Seam - **Fork-owned:** `SidebarThreadGroup.projection.ts` - **Also:** `.drag.ts`, `.markers.ts`, `.span.ts` - **Removed:** create band, span collision - **Hooks:** `Sidebar.tsx` 30 - **Others:** `.drag.ts` 3, `.logic.ts` 4 - **Net:** upstream files +101 / −505 vs `hyprws` Groups state, contracts, and server are unchanged. ## Why The header was a static droppable while upstream's Pinned and Settled headers are sortable markers, so mid-drag it drew over the `Pinned` label. Round three's middle-band create and span collision were hard to hit and hard to read. Depth projection is the known dnd-kit idiom: one gesture creates, joins, and leaves. ## UI Changes ### Before | Sidebar | Mid-drag | | --- | --- | | ![before-sidebar](https://github.com/user-attachments/assets/4b4a73a0-02f1-4ea7-b208-fd67f760e8fa) | ![before-drag](https://github.com/user-attachments/assets/8506a799-97fe-4d6d-982f-a12d91fe05b7) | ### After | Create | Join | Leave | | --- | --- | --- | | ![mid-drag-create](https://github.com/user-attachments/assets/8fd43a13-d486-4e0c-aec4-6b625eb8bbb8) | ![mid-drag-join](https://github.com/user-attachments/assets/4b9ab273-d9c3-41b8-93c6-aa488952dc3d) | ![mid-drag-leave](https://github.com/user-attachments/assets/9fb85459-3f51-46d1-8966-341a5f848a1a) | At rest, 256px sidebar: ![rest](https://github.com/user-attachments/assets/7a161a76-7ad4-4ea7-9675-9482f03e1887) Title width measured at rest, before and after the header fix: | Sidebar | Before | After | | --- | --- | --- | | 256px | 125px | 149px | | 220px | 105px | 113px | | 180px | 65px | 73px | Hover menu: ![after-menu](https://github.com/user-attachments/assets/28619133-498e-4235-aab2-6c86afe31924) Grounded in T3's built-in Browser panel on a worktree dev server with synthetic pointer events. No near-pinned shot: the panel stopped painting (`preview_snapshot` failed); pinned refusal is covered by tests. ## Close conditions - [x] **Header:** section header idiom - [x] **Actions:** one hover menu - [x] **Drop target:** visible mid-drag - [x] **Create by drag:** depth 1 under a plain thread - [x] **Seam:** no `ui/` restyle - [x] **Seam:** upstream lines hook-marked | Condition | Evidence | | --- | --- | | Header, title width | rest shot, width table | | Actions | after-menu shot | | Drop target | join, leave shots | | Create | create shot | | Depth rules | `SidebarThreadGroup.projection.test.ts` | | Span rules | `SidebarThreadGroup.span.test.ts` | | No restyle | `Button` and `ui/menu` variants only | | Hook-marked | `fork:ci` exit 0 | ## Follow-ups - **Slot lead:** one row ahead, dragging down - **Cause:** upstream divider reveal, rows +50px - **Also:** collision uses the rest frame - **Dead helper:** `getSidebarThreadLayoutOrder` - **Dead store action:** `moveProjectThread` ## Checklist - [x] This PR is small and focused - [x] I explained what changed and why - [x] I included before/after screenshots for any UI changes - [ ] I included a video for animation/interaction changes Closes #1287 Model and harness: Claude Opus 5.5, Claude Code. ## Fork trailers Squashes: - 7ae8321fb1 feat(web): sidebar thread groups use the section header idiom - b7b64c0024 chore(web): drop sidebar helpers unused since thread-group projection Fork-Domain: thread-ordering Fork-Tier: qol
1 parent 25192cc commit 7e1fc40

14 files changed

Lines changed: 1097 additions & 741 deletions

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ import { createSidebarCollisionDetection } from "./Sidebar.drag.ts";
44
import {
55
sidebarListItemId,
66
sidebarMarkerId,
7-
sidebarThreadGroupHeaderId,
87
type SidebarListItem,
98
type SidebarSection,
109
} from "./Sidebar.logic.ts";
10+
import {
11+
sidebarThreadGroupHeaderMarker,
12+
sidebarThreadGroupKey,
13+
} from "./SidebarThreadGroup.markers.ts";
1114

1215
const thread = (key: string, section: SidebarSection): SidebarListItem => ({
1316
kind: "thread",
@@ -24,7 +27,8 @@ const rect = (top: number, height: number) => ({
2427
width: 260,
2528
});
2629

27-
const HEADER_ID = sidebarThreadGroupHeaderId("project", "group");
30+
const HEADER_MARKER = sidebarThreadGroupHeaderMarker(sidebarThreadGroupKey("project", "group"));
31+
const HEADER_ID = sidebarMarkerId(HEADER_MARKER);
2832

2933
/** The divider row renders whether or not Pins holds anything, and its label
3034
spans the sidebar, so the section branch runs at every ordinary pointer x. */
@@ -35,6 +39,7 @@ function collisionArgs(pointerX: number) {
3539
{ kind: "marker", marker: "pinned-divider" },
3640
thread("member", "active"),
3741
thread("source", "active"),
42+
{ kind: "marker", marker: HEADER_MARKER },
3843
{ kind: "marker", marker: "settled-header" },
3944
];
4045
// The header sits nearest the lifted card; the member row is far above it.

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import { closestCenter, type CollisionDetection, type Modifier } from "@dnd-kit/core";
22
import { verticalListSortingStrategy, type SortingStrategy } from "@dnd-kit/sortable";
33
import {
4-
parseSidebarThreadGroupHeaderId,
54
resolveSidebarDropTarget,
65
sidebarListItemId,
76
sidebarMarkerId,
87
type SidebarListItem,
98
type SidebarListMarker,
109
type SidebarSection,
1110
} from "./Sidebar.logic";
11+
import {
12+
projectSidebarThreadGroupSpansFork,
13+
recordSidebarProjectedLayoutFork,
14+
} from "./SidebarThreadGroup.span"; // fork-hook: thread-ordering/group-span-projection-import
1215

1316
const stationary = { x: 0, y: 0, scaleX: 1, scaleY: 1 };
1417
const hidden = { ...stationary, scaleY: 0 };
@@ -67,15 +70,9 @@ export function createSidebarCollisionDetection(
6770
const target = collisions.find((collision) => {
6871
const id = String(collision.id);
6972
if (!sections.has(id)) {
70-
// A group header has no entry in `items`, so the reorder resolver
71-
// declines it. Headers only ever render in the active section, so
72-
// read the id space directly; otherwise this branch would promote
73-
// a member row past every header the pointer is actually over.
7473
sections.set(
7574
id,
76-
parseSidebarThreadGroupHeaderId(id)
77-
? "active"
78-
: (resolveSidebarDropTarget(items, String(args.active.id), id)?.section ?? null),
75+
resolveSidebarDropTarget(items, String(args.active.id), id)?.section ?? null,
7976
);
8077
}
8178
return sections.get(id) === boundarySection;
@@ -197,6 +194,7 @@ export function createSidebarSortingStrategy(input: {
197194
}
198195
marker("settled-header");
199196
section("settled");
197+
projectSidebarThreadGroupSpansFork(projected, { items, activeIndex, overIndex, rects }); // fork-hook: thread-ordering/group-span-projection
200198
const heights = projected.map((item) => {
201199
const index = indices.get(sidebarListItemId(item));
202200
const rect = index === undefined ? undefined : rects[index];
@@ -238,6 +236,7 @@ export function createSidebarSortingStrategy(input: {
238236
if (index !== undefined && rect) result[index] = { ...stationary, y: top - rect.top };
239237
top += heights[projectedIndex]! + 1;
240238
}
239+
recordSidebarProjectedLayoutFork(items, projected, heights, result); // fork-hook: thread-ordering/group-drop-layout
241240
result[activeIndex] = stationary;
242241
return result;
243242
}

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

Lines changed: 8 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ import { deadlineAfter, deadlineStore } from "@t3tools/client-runtime/clock";
3636
import { useDeadlinePassed } from "../hooks/useDeadline";
3737
import type { SidebarThreadGroup } from "../uiStateStore";
3838
import { pushSidebarWorkingShelfFork } from "./Sidebar.workingShelf.fork"; // fork-hook: thread-ordering/working-shelf-rows-import
39+
import {
40+
insertSidebarThreadGroupMarkersFork,
41+
type SidebarThreadGroupMarker,
42+
type SidebarThreadGroupSpan,
43+
} from "./SidebarThreadGroup.markers"; // fork-hook: thread-ordering/group-span-markers-import
3944

4045
export function shouldNavigateAfterThreadPark(input: {
4146
readonly threadKey: string;
@@ -189,6 +194,7 @@ export type SidebarListMarker =
189194
| "pinned-divider"
190195
| "working-header"
191196
| "snoozed-header"
197+
| SidebarThreadGroupMarker // fork-hook: thread-ordering/group-span-marker-type
192198
| "settled-header";
193199

194200
export function sidebarMarkerId(marker: SidebarListMarker): string {
@@ -211,6 +217,7 @@ export function buildSidebarListItems(input: {
211217
readonly hasSnoozedThreads: boolean;
212218
readonly snoozedVisibleKeys: readonly string[];
213219
readonly settledKeys: readonly string[];
220+
readonly activeGroups?: readonly SidebarThreadGroupSpan[]; // fork-hook: thread-ordering/group-span-input
214221
}): readonly SidebarListItem[] {
215222
if (input.hasNoThreads) return [];
216223
const items: SidebarListItem[] = [{ kind: "marker", marker: "pinned-header" }];
@@ -227,6 +234,7 @@ export function buildSidebarListItems(input: {
227234
items.push({ kind: "marker", marker: "settled-header" });
228235
items.push({ kind: "marker", marker: "settled-placeholder" });
229236
for (const key of input.settledKeys) items.push({ kind: "thread", key, section: "settled" });
237+
insertSidebarThreadGroupMarkersFork(items, input.activeGroups); // fork-hook: thread-ordering/group-span-markers
230238
return items;
231239
}
232240

@@ -457,74 +465,6 @@ export type SidebarThreadGroupLayoutItem<T> =
457465
readonly threads: readonly T[];
458466
};
459467

460-
export type SidebarThreadSortableItem =
461-
| { readonly kind: "thread"; readonly id: string }
462-
| {
463-
readonly kind: "group-header";
464-
readonly id: string;
465-
readonly projectKey: string;
466-
readonly groupId: string;
467-
readonly anchorThreadId: string;
468-
};
469-
470-
const SIDEBAR_THREAD_GROUP_HEADER_PREFIX = "sidebar-thread-group\0";
471-
472-
/** Sortable and droppable id of a group header. Colon-free like the marker
473-
ids — scoped thread keys always contain a colon, so the header id space
474-
never collides with a row key. */
475-
export function sidebarThreadGroupHeaderId(projectKey: string, groupId: string): string {
476-
return `${SIDEBAR_THREAD_GROUP_HEADER_PREFIX}${projectKey}\0${groupId}`;
477-
}
478-
479-
/** Inverse of sidebarThreadGroupHeaderId. Null for every other id space:
480-
thread keys, marker ids, and truncated or malformed header ids. */
481-
export function parseSidebarThreadGroupHeaderId(
482-
id: string,
483-
): { readonly projectKey: string; readonly groupId: string } | null {
484-
if (!id.startsWith(SIDEBAR_THREAD_GROUP_HEADER_PREFIX)) return null;
485-
const rest = id.slice(SIDEBAR_THREAD_GROUP_HEADER_PREFIX.length);
486-
const separator = rest.indexOf("\0");
487-
if (separator <= 0 || separator === rest.length - 1) return null;
488-
return { projectKey: rest.slice(0, separator), groupId: rest.slice(separator + 1) };
489-
}
490-
491-
export function buildSidebarThreadSortableItems<T>(input: {
492-
readonly layout: readonly SidebarThreadGroupLayoutItem<T>[];
493-
readonly getId: (thread: T) => string;
494-
}): SidebarThreadSortableItem[] {
495-
return input.layout.flatMap((item): SidebarThreadSortableItem[] => {
496-
if (item.kind === "thread") {
497-
return [{ kind: "thread", id: input.getId(item.thread) }];
498-
}
499-
const anchorThread = item.threads[0];
500-
if (!anchorThread) return [];
501-
const header: SidebarThreadSortableItem = {
502-
kind: "group-header",
503-
id: sidebarThreadGroupHeaderId(item.projectKey, item.group.id),
504-
projectKey: item.projectKey,
505-
groupId: item.group.id,
506-
anchorThreadId: input.getId(anchorThread),
507-
};
508-
if (item.group.collapsed) return [header];
509-
return [
510-
header,
511-
...item.threads.map((thread): SidebarThreadSortableItem => ({
512-
kind: "thread",
513-
id: input.getId(thread),
514-
})),
515-
];
516-
});
517-
}
518-
519-
export function getSidebarThreadLayoutOrder<T>(input: {
520-
readonly layout: readonly SidebarThreadGroupLayoutItem<T>[];
521-
readonly getId: (thread: T) => string;
522-
}): string[] {
523-
return input.layout.flatMap((item) =>
524-
item.kind === "thread" ? [input.getId(item.thread)] : item.threads.map(input.getId),
525-
);
526-
}
527-
528468
export function buildSidebarThreadGroupLayout<T>(input: {
529469
readonly threads: readonly T[];
530470
readonly groupsByProject: Readonly<Record<string, readonly SidebarThreadGroup[]>>;
@@ -562,85 +502,6 @@ export function buildSidebarThreadGroupLayout<T>(input: {
562502
});
563503
}
564504

565-
export function isSidebarThreadGroupDrop(input: {
566-
readonly activeRect: { readonly top: number; readonly bottom: number } | null;
567-
readonly overRect: { readonly top: number; readonly bottom: number } | null;
568-
}): boolean {
569-
if (!input.activeRect || !input.overRect) return false;
570-
const center = (input.activeRect.top + input.activeRect.bottom) / 2;
571-
const height = input.overRect.bottom - input.overRect.top;
572-
return (
573-
center >= input.overRect.top + height * 0.15 && center <= input.overRect.bottom - height * 0.15
574-
);
575-
}
576-
577-
export function isSidebarThreadGroupingTarget(input: {
578-
readonly activeGroupId: string | null;
579-
readonly overGroupId: string | null;
580-
readonly overGroupHeader: boolean;
581-
readonly activeRect: { readonly top: number; readonly bottom: number } | null;
582-
readonly overRect: { readonly top: number; readonly bottom: number } | null;
583-
}): boolean {
584-
if (input.activeGroupId !== null && input.activeGroupId === input.overGroupId) return false;
585-
return input.overGroupHeader || isSidebarThreadGroupDrop(input);
586-
}
587-
588-
export function isSidebarThreadUngroupBeforeTarget(input: {
589-
readonly activeThreadId: string;
590-
readonly activeGroup: SidebarThreadGroup | undefined;
591-
readonly overItem: SidebarThreadSortableItem | undefined;
592-
}): boolean {
593-
return (
594-
input.activeGroup !== undefined &&
595-
input.overItem?.kind === "group-header" &&
596-
input.overItem.groupId === input.activeGroup.id &&
597-
input.overItem.anchorThreadId === input.activeThreadId
598-
);
599-
}
600-
601-
export function getSidebarThreadGroupDissolvingKey(input: {
602-
readonly projectKey: string;
603-
readonly activeGroup: SidebarThreadGroup | undefined;
604-
readonly overGroupId: string | null;
605-
}): string | null {
606-
if (!input.activeGroup || input.activeGroup.threadIds.length !== 2) return null;
607-
if (input.activeGroup.id === input.overGroupId) return null;
608-
return `${input.projectKey}\0${input.activeGroup.id}`;
609-
}
610-
611-
/** Whether a drag onto a group header can group the dragged thread into that
612-
group: the header must belong to the dragged row's project, the group must
613-
still exist, and the dragged row must be an active-section thread that is
614-
not already a member. Pinned, snoozed, and settled rows never group, and
615-
dropping a member on its own group's header stays a no-op. */
616-
export function isSidebarGroupHeaderGroupingTarget(input: {
617-
readonly activeKey: string;
618-
readonly activeSection: SidebarSection | null | undefined;
619-
readonly activeProjectKey: string | null;
620-
readonly header: { readonly projectKey: string; readonly groupId: string };
621-
readonly groups: readonly Pick<SidebarThreadGroup, "id" | "threadIds">[];
622-
}): boolean {
623-
if (input.activeSection !== "active") return false;
624-
if (input.activeProjectKey !== input.header.projectKey) return false;
625-
return input.groups.some(
626-
(group) => group.id === input.header.groupId && !group.threadIds.includes(input.activeKey),
627-
);
628-
}
629-
630-
/** The member a header drop lands on: the header group's first member the
631-
visible active list still shows. The drop then takes the same write path
632-
as a row-centre group drop. Null when the group is gone or hides every
633-
member mid-drag — the drop must fail rather than resolve to something
634-
adjacent. */
635-
export function resolveSidebarGroupHeaderDropAnchor(input: {
636-
readonly header: { readonly projectKey: string; readonly groupId: string };
637-
readonly groups: readonly Pick<SidebarThreadGroup, "id" | "threadIds">[];
638-
readonly visibleMemberKeys: readonly string[];
639-
}): string | null {
640-
const group = input.groups.find((candidate) => candidate.id === input.header.groupId);
641-
return group?.threadIds.find((threadId) => input.visibleMemberKeys.includes(threadId)) ?? null;
642-
}
643-
644505
export function applySidebarThreadDrop<
645506
T extends Pick<
646507
SidebarThreadSummary,

0 commit comments

Comments
 (0)