Skip to content

Commit 33e70c4

Browse files
fix(web): preserve sidebar drag compatibility and hidden slots
1 parent 5fd708e commit 33e70c4

6 files changed

Lines changed: 144 additions & 74 deletions

File tree

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

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { verticalListSortingStrategy, type SortingStrategy } from "@dnd-kit/sort
44
import { createSidebarCollisionDetection, createSidebarSortingStrategy } from "./Sidebar.drag";
55
import {
66
sidebarListItemId,
7+
sidebarMarkerId,
78
type SidebarListItem,
89
type SidebarListMarker,
910
type SidebarSection,
@@ -95,8 +96,8 @@ describe("sidebar collision detection", () => {
9596
}
9697

9798
it.each([
98-
[false, "marker:settled-header"],
99-
[true, "marker:pinned-divider"],
99+
[false, sidebarMarkerId("settled-header")],
100+
[true, sidebarMarkerId("pinned-divider")],
100101
] as const)(
101102
"rejects unsupported Active instead of selecting %s / %s",
102103
(blockedAboveSource, nearbyTarget) => {
@@ -120,7 +121,7 @@ describe("sidebar collision detection", () => {
120121

121122
function clampedArgs() {
122123
const args = collisionArgs();
123-
const pinned = args.droppableRects.get("marker:pinned-header")!;
124+
const pinned = args.droppableRects.get(sidebarMarkerId("pinned-header"))!;
124125
const source = args.droppableRects.get("source")!;
125126
const collisionRect = {
126127
...source,
@@ -144,9 +145,9 @@ describe("sidebar collision detection", () => {
144145
emptyPins: true,
145146
activationY: args.pointerCoordinates.y + 6,
146147
});
147-
expect(args.droppableRects.get("marker:pinned-header")?.height).toBe(0);
148+
expect(args.droppableRects.get(sidebarMarkerId("pinned-header"))?.height).toBe(0);
148149
expect(closestCenter(args)[0]?.id).toBe("source");
149-
expect(detector(args)[0]?.id).toBe("marker:pinned-header");
150+
expect(detector(args)[0]?.id).toBe(sidebarMarkerId("pinned-header"));
150151
});
151152

152153
it.each([
@@ -179,7 +180,7 @@ describe("sidebar collision detection", () => {
179180
const args = clampedArgs();
180181
expect(detector(args).map((collision) => collision.id)).toEqual(["source"]);
181182
expect(detector(args).map((collision) => collision.id)).toEqual(["source"]);
182-
expect(isValid.mock.calls).toEqual([["marker:pinned-header"]]);
183+
expect(isValid.mock.calls).toEqual([[sidebarMarkerId("pinned-header")]]);
183184
});
184185

185186
it("returns no collision if an unsupported target has no source fallback", () => {
@@ -216,10 +217,10 @@ describe("sidebar collision detection", () => {
216217
expect(
217218
detector({
218219
...args,
219-
collisionRect: args.droppableRects.get("marker:settled-placeholder")!,
220+
collisionRect: args.droppableRects.get(sidebarMarkerId("settled-placeholder"))!,
220221
})[0]?.id,
221-
).toBe("marker:settled-placeholder");
222-
expect(isValid.mock.calls).toEqual([["blocked"], ["marker:settled-placeholder"]]);
222+
).toBe(sidebarMarkerId("settled-placeholder"));
223+
expect(isValid.mock.calls).toEqual([["blocked"], [sidebarMarkerId("settled-placeholder")]]);
223224
});
224225
});
225226

@@ -253,11 +254,11 @@ describe("sidebar drag projection", () => {
253254
const result = preview(
254255
{ items: pinned, settledOrder: [], settledExpanded: true },
255256
"p2",
256-
"marker:pinned-header",
257+
sidebarMarkerId("pinned-header"),
257258
);
258-
expect(result.get("marker:pinned-header")).toEqual(stationary);
259+
expect(result.get(sidebarMarkerId("pinned-header"))).toEqual(stationary);
259260
expect(result.get("p1")).toEqual({ ...stationary, y: 83 });
260-
expect(result.get("marker:pinned-divider")).toEqual(stationary);
261+
expect(result.get(sidebarMarkerId("pinned-divider"))).toEqual(stationary);
261262
expect(result.get("a1")).toEqual(stationary);
262263
});
263264

@@ -303,7 +304,7 @@ describe("sidebar drag projection", () => {
303304
});
304305

305306
it.each([
306-
["marker:pinned-divider", 0, 0],
307+
[sidebarMarkerId("pinned-divider"), 0, 0],
307308
["a1", -83, 0],
308309
["a2", -83, -83],
309310
] as const)(
@@ -319,11 +320,11 @@ describe("sidebar drag projection", () => {
319320
thread("s", "settled"),
320321
];
321322
const result = preview({ items, settledOrder: [], settledExpanded: true }, "p", over);
322-
expect(result.get("marker:pinned-header")).toEqual(stationary);
323-
expect(result.get("marker:pinned-divider")?.y).toBe(-83);
323+
expect(result.get(sidebarMarkerId("pinned-header"))).toEqual(stationary);
324+
expect(result.get(sidebarMarkerId("pinned-divider"))?.y).toBe(-83);
324325
expect(result.get("a1")?.y).toBe(a1Offset);
325326
expect(result.get("a2")?.y).toBe(a2Offset);
326-
expect(result.get("marker:settled-header")?.y).toBe(0);
327+
expect(result.get(sidebarMarkerId("settled-header"))?.y).toBe(0);
327328
},
328329
);
329330

@@ -339,12 +340,12 @@ describe("sidebar drag projection", () => {
339340
const result = preview(
340341
{ items, settledOrder: [], settledExpanded: true },
341342
"a2",
342-
"marker:pinned-header",
343+
sidebarMarkerId("pinned-header"),
343344
);
344-
expect(result.get("marker:pinned-header")).toEqual(stationary);
345-
expect(result.get("marker:pinned-divider")?.y).toBe(83);
345+
expect(result.get(sidebarMarkerId("pinned-header"))).toEqual(stationary);
346+
expect(result.get(sidebarMarkerId("pinned-divider"))?.y).toBe(83);
346347
expect(result.get("a1")?.y).toBe(83);
347-
expect(result.get("marker:settled-header")?.y).toBe(0);
348+
expect(result.get(sidebarMarkerId("settled-header"))?.y).toBe(0);
348349
});
349350

350351
it.each([
@@ -364,11 +365,11 @@ describe("sidebar drag projection", () => {
364365
const result = preview(
365366
{ items, settledOrder: [], settledExpanded: true },
366367
active,
367-
"marker:active-placeholder",
368+
sidebarMarkerId("active-placeholder"),
368369
);
369-
expect(result.get("marker:active-placeholder")?.scaleY).toBe(0);
370-
expect(result.get("marker:pinned-divider")?.y).toBe(dividerOffset);
371-
expect(result.get("marker:settled-header")?.y).toBe(settledOffset);
370+
expect(result.get(sidebarMarkerId("active-placeholder"))?.scaleY).toBe(0);
371+
expect(result.get(sidebarMarkerId("pinned-divider"))?.y).toBe(dividerOffset);
372+
expect(result.get(sidebarMarkerId("settled-header"))?.y).toBe(settledOffset);
372373
},
373374
);
374375

@@ -387,7 +388,7 @@ describe("sidebar drag projection", () => {
387388
"a",
388389
"s2",
389390
);
390-
expect(result.get("marker:settled-header")?.y).toBe(-46);
391+
expect(result.get(sidebarMarkerId("settled-header"))?.y).toBe(-46);
391392
expect(result.get("s1")?.y).toBe(-46);
392393
expect(result.get("s2")?.y).toBe(-9);
393394
});
@@ -410,7 +411,7 @@ describe("sidebar drag projection", () => {
410411
const result = preview({ items, settledOrder: [], settledExpanded: true }, "s", over);
411412
expect(result.get("a1")?.y).toBe(firstOffset);
412413
expect(result.get("a2")?.y).toBe(83);
413-
expect(result.get("marker:settled-header")?.y).toBe(83);
414+
expect(result.get(sidebarMarkerId("settled-header"))?.y).toBe(83);
414415
},
415416
);
416417

@@ -426,8 +427,8 @@ describe("sidebar drag projection", () => {
426427
thread("s", "settled"),
427428
];
428429
const result = preview({ items, settledOrder: [], settledExpanded: true }, "z", "a");
429-
expect(result.get("marker:snoozed-header")?.scaleY).toBe(0);
430-
expect(result.get("marker:settled-header")?.y).toBe(13);
430+
expect(result.get(sidebarMarkerId("snoozed-header"))?.scaleY).toBe(0);
431+
expect(result.get(sidebarMarkerId("settled-header"))?.y).toBe(13);
431432
expect(result.get("s")?.y).toBe(13);
432433
});
433434

@@ -444,10 +445,10 @@ describe("sidebar drag projection", () => {
444445
const result = preview(
445446
{ items, settledOrder: [], settledExpanded: false },
446447
"a2",
447-
"marker:settled-placeholder",
448+
sidebarMarkerId("settled-placeholder"),
448449
);
449-
expect(result.get("marker:settled-header")?.y).toBe(-83);
450-
expect(result.get("marker:settled-placeholder")).toEqual({ ...stationary, y: -83 });
450+
expect(result.get(sidebarMarkerId("settled-header"))?.y).toBe(-83);
451+
expect(result.get(sidebarMarkerId("settled-placeholder"))).toEqual({ ...stationary, y: -83 });
451452
});
452453

453454
it("preserves a collapsed snoozed header while another section changes", () => {
@@ -463,9 +464,9 @@ describe("sidebar drag projection", () => {
463464
const result = preview(
464465
{ items, settledOrder: [], settledExpanded: false },
465466
"a",
466-
"marker:settled-placeholder",
467+
sidebarMarkerId("settled-placeholder"),
467468
);
468-
expect(result.get("marker:snoozed-header")).toEqual({ ...stationary, y: -46 });
469+
expect(result.get(sidebarMarkerId("snoozed-header"))).toEqual({ ...stationary, y: -46 });
469470
});
470471

471472
it("derives missing card geometry from the measured root scale", () => {
@@ -479,12 +480,12 @@ describe("sidebar drag projection", () => {
479480
const result = preview(
480481
{ items, settledOrder: [], settledExpanded: true },
481482
"s",
482-
"marker:pinned-header",
483+
sidebarMarkerId("pinned-header"),
483484
0.75,
484485
);
485-
expect(result.get("marker:pinned-header")).toEqual(stationary);
486-
expect(result.get("marker:pinned-divider")?.y).toBe(62.5);
487-
expect(result.get("marker:active-placeholder")?.y).toBe(62.5);
486+
expect(result.get(sidebarMarkerId("pinned-header"))).toEqual(stationary);
487+
expect(result.get(sidebarMarkerId("pinned-divider"))?.y).toBe(62.5);
488+
expect(result.get(sidebarMarkerId("active-placeholder"))?.y).toBe(62.5);
488489
});
489490

490491
it("updates the projection when the target or measured geometry changes", () => {
@@ -514,7 +515,7 @@ describe("sidebar drag projection", () => {
514515
settledOrder: [],
515516
settledExpanded: false,
516517
});
517-
const args = layout(items, "a", "marker:settled-placeholder", 1, 78);
518+
const args = layout(items, "a", sidebarMarkerId("settled-placeholder"), 1, 78);
518519
expect(strategy({ ...args, index: 4 })?.y).toBe(-42);
519520
});
520521

@@ -560,7 +561,7 @@ describe("sidebar drag projection", () => {
560561
"s1",
561562
"a",
562563
);
563-
expect(result.get("marker:settled-header")?.y).toBe(83);
564+
expect(result.get(sidebarMarkerId("settled-header"))?.y).toBe(83);
564565
expect(result.get("route")?.y).toBe(83);
565566
});
566567

@@ -582,10 +583,10 @@ describe("sidebar drag projection", () => {
582583
routeThreadKey: "a",
583584
},
584585
"a",
585-
"marker:settled-placeholder",
586+
sidebarMarkerId("settled-placeholder"),
586587
);
587-
expect(result.get("marker:settled-placeholder")?.scaleY).toBe(0);
588-
expect(result.get("marker:settled-header")?.y).toBe(-46);
588+
expect(result.get(sidebarMarkerId("settled-placeholder"))?.scaleY).toBe(0);
589+
expect(result.get(sidebarMarkerId("settled-header"))?.y).toBe(-46);
589590
});
590591

591592
it("preserves hidden snoozed membership when the only rendered route row leaves", () => {
@@ -609,7 +610,7 @@ describe("sidebar drag projection", () => {
609610
"z",
610611
"a",
611612
);
612-
expect(result.get("marker:snoozed-header")).toEqual({ ...stationary, y: 83 });
613-
expect(result.get("marker:settled-header")?.y).toBe(46);
613+
expect(result.get(sidebarMarkerId("snoozed-header"))).toEqual({ ...stationary, y: 83 });
614+
expect(result.get(sidebarMarkerId("settled-header"))?.y).toBe(46);
614615
});
615616
});

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

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
planPinnedReorder,
3636
planSidebarThreadDrop,
3737
sidebarMarkerId,
38+
sidebarListItemId,
3839
sortPinnedThreadsForSidebar,
3940
sortThreadsForSidebar,
4041
sortProjectsForSidebar,
@@ -957,6 +958,22 @@ describe("resolveSidebarDropTarget", () => {
957958
const resolve = (activeKey: string, overId: string) =>
958959
resolveSidebarDropTarget(items, activeKey, overId);
959960

961+
it("keeps marker-like scoped thread keys draggable", () => {
962+
const key = "marker:pinned-header";
963+
const list: SidebarListItem[] = [
964+
marker("pinned-header"),
965+
thread(key, "pinned"),
966+
thread("env:other", "pinned"),
967+
marker("pinned-divider"),
968+
];
969+
expect(new Set(list.map(sidebarListItemId)).size).toBe(list.length);
970+
expect(resolveSidebarDropTarget(list, key, "env:other")).toEqual({
971+
section: "pinned",
972+
pinnedOrder: ["env:other", key],
973+
activeOrder: [],
974+
});
975+
});
976+
960977
it("reads the section off the markers above the gap", () => {
961978
expect(resolve("p1", "a2")).toEqual({
962979
section: "active",
@@ -1103,6 +1120,48 @@ describe("planSidebarThreadDrop", () => {
11031120
target: { activeOrder: [], ...overrides.target },
11041121
});
11051122

1123+
it("allows old-server pinned reordering while rejecting settlement", () => {
1124+
expect(
1125+
plan({
1126+
activeKey: "p1",
1127+
activeSection: "pinned",
1128+
supportsSettlement: false,
1129+
target: { section: "pinned", pinnedOrder: ["p2", "p1", "p3"] },
1130+
}).kind,
1131+
).toBe("reorder-pinned");
1132+
expect(
1133+
plan({
1134+
activeKey: "p1",
1135+
activeSection: "pinned",
1136+
supportsSettlement: false,
1137+
target: { section: "settled", pinnedOrder: ["p2", "p3"] },
1138+
}),
1139+
).toEqual({ kind: "none" });
1140+
});
1141+
1142+
it.each(["pinned", "active"] as const)("reserves hidden %s slots during a drop", (section) => {
1143+
const order = section === "pinned" ? ["p2", "p1", "p3"] : ["a2", "a1", "a3"];
1144+
const keys = new Map(section === "pinned" ? pinnedKeysById : activeKeysById);
1145+
const moved = section === "pinned" ? "p1" : "a1";
1146+
const reserved = pinOrderKeyBetween(keys.get(order[0]!)!, keys.get(order[2]!)!)!;
1147+
keys.set("snoozed", reserved);
1148+
const result = plan({
1149+
activeKey: moved,
1150+
activeSection: section,
1151+
pinnedKeysById: section === "pinned" ? keys : pinnedKeysById,
1152+
activeKeysById: section === "active" ? keys : activeKeysById,
1153+
target: {
1154+
section,
1155+
pinnedOrder: section === "pinned" ? order : [],
1156+
activeOrder: section === "active" ? order : [],
1157+
},
1158+
});
1159+
if (result.kind !== "reorder-pinned" && result.kind !== "move-active")
1160+
throw new Error("Expected reorder");
1161+
expect(result.assignments).toHaveLength(1);
1162+
expect(result.assignments[0]!.orderKey).not.toBe(reserved);
1163+
});
1164+
11061165
it.each([
11071166
{ key: "p2", section: "pinned" as const, unpin: true, unsettle: false, unsnooze: false },
11081167
{ key: "s1", section: "settled" as const, unpin: false, unsettle: true, unsnooze: false },

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ export const animateSidebarLayoutChanges: AnimateLayoutChanges = (args) =>
9090
export type SidebarSection = "pinned" | "active" | "snoozed" | "settled";
9191

9292
/** Sortable ids: thread rows use their scoped key; structural items use a
93-
prefix that cannot collide with `<environmentId>:<threadId>`. */
94-
const SIDEBAR_MARKER_PREFIX = "marker:";
93+
colon-free prefix: scoped thread keys always contain a colon. */
94+
const SIDEBAR_MARKER_PREFIX = "sidebar-marker-";
9595

9696
export type SidebarListMarker =
9797
/** The top boundary is also a landing target when there are no pins. */
@@ -120,10 +120,7 @@ export function sidebarListItemId(item: SidebarListItem): string {
120120
the top down, everything before the pinned divider is pinned, then the
121121
inbox until the snoozed header, the shelf until the settled header,
122122
then settled. */
123-
export function sectionAtSidebarSlot(
124-
items: readonly SidebarListItem[],
125-
index: number,
126-
): SidebarSection {
123+
function sectionAtSidebarSlot(items: readonly SidebarListItem[], index: number): SidebarSection {
127124
let section: SidebarSection = "pinned";
128125
for (let i = 0; i < index && i < items.length; i += 1) {
129126
const item = items[i]!;
@@ -201,6 +198,7 @@ export function planSidebarThreadDrop(input: {
201198
/** Snoozed threads can retain pinning and settlement beneath the shelf. */
202199
readonly activePinned?: boolean;
203200
readonly activeSettled?: boolean;
201+
readonly supportsSettlement?: boolean;
204202
readonly target: SidebarDropTarget;
205203
/** All pinned keys in displayed order before the drop. */
206204
readonly pinnedOrder: readonly string[];
@@ -223,6 +221,9 @@ export function planSidebarThreadDrop(input: {
223221
activeKeysById,
224222
activeReorderableKeys,
225223
} = input;
224+
if (input.supportsSettlement === false && (target.section === "settled" || activeSettled)) {
225+
return { kind: "none" };
226+
}
226227
switch (target.section) {
227228
case "active": {
228229
const order = target.activeOrder;

0 commit comments

Comments
 (0)