TypeScript
feat(web): boring sidebar hides projects with no active threads (#26387)
Theo Browne001d16e9699a
diff --git a/apps/web/src/components/Sidebar.logic.test.ts b/apps/web/src/components/Sidebar.logic.test.tsindex 93f3fb342fb..e4fa68a6520 100644--- a/apps/web/src/components/Sidebar.logic.test.ts+++ b/apps/web/src/components/Sidebar.logic.test.ts@@ -1368,7 +1368,7 @@ describe("sidebarFolderExpansionKeys", () => {});describe("groupSidebarThreadsByProject", () => {- it("puts each thread in its project's folder and keeps empty projects", () => {+ it("puts each thread in its project's folder and drops empty projects unless kept", () => {const remoteEnvironmentId = EnvironmentId.make("environment-remote");const t3code = ProjectId.make("t3code");const t3codeRemote = ProjectId.make("t3code-remote");@@ -1392,21 +1392,22 @@ describe("groupSidebarThreadsByProject", () => {},];- const folders = groupSidebarThreadsByProject(groups, [+ const threads = [thread("a", localEnvironmentId, t3code),thread("orphan", localEnvironmentId, ProjectId.make("deleted")),thread("b", remoteEnvironmentId, t3codeRemote),- ]);-- expect(- folders.map((folder) => ({+ ];+ const summarize = (keepEmpty: boolean) =>+ groupSidebarThreadsByProject(groups, threads, keepEmpty).map((folder) => ({projectKey: folder.group.projectKey,threads: folder.threads.map((entry) => entry.id),- })),- ).toEqual([+ }));++ expect(summarize(true)).toEqual([{ projectKey: "t3code", threads: ["a", "b"] },{ projectKey: "fleet", threads: [] },]);+ expect(summarize(false)).toEqual([{ projectKey: "t3code", threads: ["a", "b"] }]);});});diff --git a/apps/web/src/components/Sidebar.logic.ts b/apps/web/src/components/Sidebar.logic.tsindex 7f770557367..efd8244f8c2 100644--- a/apps/web/src/components/Sidebar.logic.ts+++ b/apps/web/src/components/Sidebar.logic.ts@@ -918,8 +918,8 @@ export function sidebarFolderExpansionKeys(group: {}/**- * Boring sidebar folders. Folders follow `groups` order and include empty- * projects so each one can start a thread. Threads keep their input order.+ * Boring sidebar folders. Folders follow `groups` order and threads keep their+ * input order. A project with no threads gets a folder only with `keepEmpty`.* A thread whose project is in no group has no folder and is left out.*/export function groupSidebarThreadsByProject<@@ -933,6 +933,7 @@ export function groupSidebarThreadsByProject<>(groups: readonly TGroup[],threads: readonly TThread[],+ keepEmpty: boolean,): Array<{ group: TGroup; threads: TThread[] }> {const folders = groups.map((group) => ({ group, threads: [] as TThread[] }));const folderByProject = new Map<string, (typeof folders)[number]>();@@ -944,7 +945,7 @@ export function groupSidebarThreadsByProject<for (const thread of threads) {folderByProject.get(`${thread.environmentId}:${thread.projectId}`)?.threads.push(thread);}- return folders;+ return keepEmpty ? folders : folders.filter((folder) => folder.threads.length > 0);}export type SidebarV2TopStatusKind =diff --git a/apps/web/src/components/Sidebar.tsx b/apps/web/src/components/Sidebar.tsxindex 6bda36fc859..ddc7ad1e7bd 100644--- a/apps/web/src/components/Sidebar.tsx+++ b/apps/web/src/components/Sidebar.tsx@@ -399,6 +399,8 @@ function useSidebarThreads(input: {readonly routeRowThreadKey: string | null;// Set in boring mode: the project groups to fold active threads into, in order.readonly folderGroups: readonly SidebarProjectSnapshot[] | null;+ // Keeps folders with no active threads, so a project the user filtered to can start one.+ readonly keepEmptyFolders: boolean;}) {const {projectScopeKey,@@ -409,6 +411,7 @@ function useSidebarThreads(input: {delegatedUnderParent,routeRowThreadKey,folderGroups,+ keepEmptyFolders: keepEmpty,} = input;// Folders already separate the work, so boring mode has no Working shelf.const workingShelfEnabled =@@ -495,7 +498,7 @@ function useSidebarThreads(input: {const projectFolders =folderGroups === null? null- : groupSidebarThreadsByProject(folderGroups, activeThreads).map((folder) => {+ : groupSidebarThreadsByProject(folderGroups, activeThreads, keepEmpty).map((folder) => {const collapsed = !resolveProjectExpanded(projectExpandedById,sidebarFolderExpansionKeys(folder.group),@@ -1271,6 +1274,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve? projectGroups: scopedProjectGroups: null,+ keepEmptyFolders: scopedProjectGroups.length > 0,});// Ranked across environments as the palette ranks them, so one@@ -1841,7 +1845,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReveconst key = scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id));return { kind: "thread", key, section };});- // Boring mode keeps empty project folders, so each can start a thread.+ // Boring mode keeps a project the user filtered to, so it can start a thread.if (!hasProjectFolders &&pinnedThreads.length +diff --git a/docs/user/thread-sidebar.md b/docs/user/thread-sidebar.mdindex b5373749a49..ce16b9df037 100644--- a/docs/user/thread-sidebar.md+++ b/docs/user/thread-sidebar.md@@ -142,7 +142,8 @@ cannot drag or move threads within it. Your saved order returns when you turn it### Group threads by project (beta)Turn on **Settings → Labs → Boring sidebar (group by project)** on web and desktop to put active-threads in a folder for each project. Click a folder to open or close it. A closed folder shows how+threads in a folder for each project. A project with no active threads has no folder until you+pick it in the project filter. Click a folder to open or close it. A closed folder shows howmany threads it holds, and a dot when one of them needs you. Use the pen button on a folder, orright-click it, to start a thread in that project. Pinned threads stay above the folders, andSnoozed and Settled stay below them. In this mode you cannot drag threads, and the Working section