TypeScript
feat(web): unpin threads from the sidebar multi-select menu (#9651)
Gianmarcoc7bf3115f222
diff --git a/apps/web/src/components/Sidebar.logic.test.ts b/apps/web/src/components/Sidebar.logic.test.tsindex dbf8fcf7853..62204d9d4a3 100644--- a/apps/web/src/components/Sidebar.logic.test.ts+++ b/apps/web/src/components/Sidebar.logic.test.ts@@ -4,6 +4,7 @@ import {animatePinnedLayoutChanges,archiveSelectedThreadEntries,buildBulkTitleRegenerationContextMenuItem,+ buildBulkUnpinContextMenuItem,buildMultiSelectThreadContextMenuItems,createThreadJumpHintVisibilityController,filterSidebarProjectScopeItems,@@ -185,6 +186,19 @@ describe("archiveSelectedThreadEntries", () => {});});+describe("buildBulkUnpinContextMenuItem", () => {+ it("counts only the pinned rows of a mixed selection", () => {+ expect(buildBulkUnpinContextMenuItem({ pinnedCount: 2 })).toEqual({+ id: "unpin",+ label: "Unpin (2)",+ });+ });++ it("omits the action when nothing selected is pinned", () => {+ expect(buildBulkUnpinContextMenuItem({ pinnedCount: 0 })).toBeNull();+ });+});+describe("buildBulkTitleRegenerationContextMenuItem", () => {it("counts only threads that can start a new regeneration", () => {expect(diff --git a/apps/web/src/components/Sidebar.logic.ts b/apps/web/src/components/Sidebar.logic.tsindex b5bb7bc77cc..6a2d44da1a7 100644--- a/apps/web/src/components/Sidebar.logic.ts+++ b/apps/web/src/components/Sidebar.logic.ts@@ -177,6 +177,18 @@ export function buildBulkTitleRegenerationContextMenuItem(input: {};}+/**+ * Bulk unpin follows the same "count only what the action will touch" rule+ * as title regeneration: on a mixed selection the label counts the pinned+ * rows alone, and the item disappears when nothing selected is pinned.+ */+export function buildBulkUnpinContextMenuItem(input: {+ pinnedCount: number;+}): ContextMenuItem<"unpin"> | null {+ if (input.pinnedCount === 0) return null;+ return { id: "unpin", label: `Unpin (${input.pinnedCount})` };+}+export interface ThreadStatusPill {label:| "Working"diff --git a/apps/web/src/components/Sidebar.tsx b/apps/web/src/components/Sidebar.tsxindex 03672d155a3..0719f873e6a 100644--- a/apps/web/src/components/Sidebar.tsx+++ b/apps/web/src/components/Sidebar.tsx@@ -130,6 +130,7 @@ import { buildThreadActionMenuItems } from "./threadActionMenu.logic";import {animatePinnedLayoutChanges,buildBulkTitleRegenerationContextMenuItem,+ buildBulkUnpinContextMenuItem,filterSidebarProjectScopeItems,formatWorkingDurationLabel,firstValidTimestampMs,@@ -3025,10 +3026,22 @@ export default function Sidebar() {supportedCount: titleRegenerationThreads.length,actionableCount: regeneratableTitleThreads.length,});+ // Unpin (k) counts only the pinned rows in pin-capable environments —+ // on a mixed selection the unpinned rows are untouched, and the item+ // is omitted entirely when nothing selected is pinned.+ const pinnedSelectedThreads = selectedThreads.filter(+ (thread) =>+ serverConfigs.get(thread.environmentId)?.environment.capabilities.threadPinning ===+ true && thread.pinnedAt != null,+ );+ const unpinMenuItem = buildBulkUnpinContextMenuItem({+ pinnedCount: pinnedSelectedThreads.length,+ });const snoozePresets = resolveSnoozePresets(new Date(), timestampFormat);const clicked = await settlePromise(() =>api.contextMenu.show([+ ...(unpinMenuItem ? [unpinMenuItem] : []),{ id: "settle", label: `Settle (${count})` },...(canSnoozeSelection? [@@ -3110,6 +3123,14 @@ export default function Sidebar() {}return;}+ if (clicked.value === "unpin") {+ // Each unpin reports its own failure, like the single-row action.+ for (const thread of pinnedSelectedThreads) {+ attemptUnpin(scopeThreadRef(thread.environmentId, thread.id));+ }+ clearSelection();+ return;+ }if (clicked.value === "regenerate-title") {for (const thread of regeneratableTitleThreads) {const result = await updateThreadMetadata({@@ -3199,6 +3220,7 @@ export default function Sidebar() {[attemptSettle,attemptSnooze,+ attemptUnpin,clearSelection,confirmThreadDelete,deleteThread,