Skip to content

Commit 781dc6f

Browse files
BarretoDiegoclaude
andcommitted
feat(web): let the sidebar's sections be arranged by hand
Section order was whatever the grouping produced: sections with live work first, then history-only ones, then the quiet seeded projects, first appearance breaking ties inside each rank. That is a reasonable default and a poor permanent arrangement — the one project you check every morning drifts down the list the moment nothing is running in it, and environments had no ordering control at all. Order becomes a second pass over the built tree rather than a variant of the grouping. Which sections exist is one question; where they sit is another, and splitting them is what lets an arrangement survive threads arriving, settling, and being filtered out. Three modes, in the same menu that already sorts threads: Busiest first (the old behavior), Name (A–Z), and Custom. Custom is reachable two ways, because a sidebar is a list you point at and also a list you drive from the keyboard. Drag a header to move it, or right-click and choose Move up / Move down; either switches to Custom and records the whole level, so the result stops depending on activity. Requiring the mode to be picked first would have made the first drag a silent no-op. Sections move only within their own level. A drop is refused outright when it lands outside the dragged section's siblings, and while a drag is in flight every other level disables its droppables, so a project level never animates a swap it would then discard. Reparenting is not a thing sections can express. Header rows now carry their parent, their siblings and their index. The alternative was recovering the level by splitting keys on "/", which happens to work today and would break the first time an id contains one. The manual list is one flat array across levels — child keys are already parent-prefixed, so ranks are unambiguous — and keys of sections that are not currently rendered are kept rather than pruned: grouping axes and the provider filter hide sections temporarily, and dropping their order would quietly throw away an arrangement. Switching to Custom from the menu seeds every unplaced section where it currently sits, so it freezes what you are looking at instead of leaving untouched levels free to reshuffle. A project added later joins the end of its level; Reset section order goes back to Busiest first. Written by Claude Opus 5 in Claude Code. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
1 parent 49dc821 commit 781dc6f

7 files changed

Lines changed: 1252 additions & 601 deletions

File tree

‎apps/desktop/src/settings/DesktopClientSettings.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ const clientSettings: ClientSettings = {
5151
sidebarThreadSecondaryGrouping: "project",
5252
sidebarThreadProviderFilter: "codex",
5353
sidebarThreadCollapsedGroups: ["environment:environment-1"],
54+
sidebarSectionOrderMode: "manual",
55+
sidebarSectionOrder: ["environment:environment-2", "environment:environment-1"],
5456
legacySidebarEnabled: false,
5557
timestampFormat: "24-hour",
5658
wordWrap: true,

‎apps/web/src/components/Sidebar.tsx‎

Lines changed: 821 additions & 595 deletions
Large diffs are not rendered by default.

‎apps/web/src/components/sidebar/SidebarGroupingBar.tsx‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { ArrowUpDownIcon, CheckIcon, FunnelIcon, GroupIcon } from "lucide-react"
22
import { memo, useCallback } from "react";
33
import type {
44
SidebarProjectGroupingMode,
5+
SidebarSectionOrderMode,
56
SidebarThreadGroupingAxis,
67
SidebarThreadSortOrder,
78
} from "@t3tools/contracts";
@@ -11,6 +12,7 @@ import type { SidebarThreadProviderIdentity } from "../sidebarThreadGrouping";
1112
import {
1213
Menu,
1314
MenuGroup,
15+
MenuItem,
1416
MenuPopup,
1517
MenuRadioGroup,
1618
MenuRadioItem,
@@ -47,6 +49,15 @@ const THREAD_SORT_ORDER_LABELS: Record<SidebarThreadSortOrder, string> = {
4749
created_at: "Date created",
4850
};
4951

52+
// Sections and threads are ordered by two different questions, so the menu
53+
// spells the section one out rather than reusing "Last activity": what moves a
54+
// section up is work arriving anywhere inside it.
55+
const SECTION_ORDER_MODE_LABELS: Record<SidebarSectionOrderMode, string> = {
56+
activity: "Busiest first",
57+
alphabetical: "Name (A–Z)",
58+
manual: "Custom (drag to arrange)",
59+
};
60+
5061
/** Trigger readouts: one word each — the bar is ~350px wide with three of them. */
5162
const GROUPING_AXIS_SHORT: Record<SidebarThreadGroupingAxis, string> = {
5263
none: "Group",
@@ -131,6 +142,9 @@ export interface SidebarGroupingBarProps {
131142
onProjectGroupingModeChange: (mode: SidebarProjectGroupingMode) => void;
132143
onThreadSortOrderChange: (sortOrder: SidebarThreadSortOrder) => void;
133144
onProviderFilterChange: (providerFilter: string | null) => void;
145+
sectionOrderMode: SidebarSectionOrderMode;
146+
onSectionOrderModeChange: (mode: SidebarSectionOrderMode) => void;
147+
onSectionOrderReset: () => void;
134148
}
135149

136150
export const SidebarGroupingBar = memo(function SidebarGroupingBar(props: SidebarGroupingBarProps) {
@@ -139,6 +153,7 @@ export const SidebarGroupingBar = memo(function SidebarGroupingBar(props: Sideba
139153
onProjectGroupingModeChange,
140154
onProviderFilterChange,
141155
onSecondaryAxisChange,
156+
onSectionOrderModeChange,
142157
onThreadSortOrderChange,
143158
} = props;
144159

@@ -162,6 +177,10 @@ export const SidebarGroupingBar = memo(function SidebarGroupingBar(props: Sideba
162177
(value: string) => onProviderFilterChange(value === "all" ? null : value),
163178
[onProviderFilterChange],
164179
);
180+
const handleSectionOrderModeChange = useCallback(
181+
(value: string) => onSectionOrderModeChange(value as SidebarSectionOrderMode),
182+
[onSectionOrderModeChange],
183+
);
165184

166185
const groupingActive = props.primaryAxis !== "none";
167186
const providerFilterActive = props.providerFilter !== null;
@@ -323,6 +342,36 @@ export const SidebarGroupingBar = memo(function SidebarGroupingBar(props: Sideba
323342
)}
324343
</MenuRadioGroup>
325344
</MenuGroup>
345+
{/* Sections and the rows inside them are two orders, and this is the
346+
menu about order — so both live here rather than the section one
347+
hiding under a grouping menu that is about which sections exist. */}
348+
{groupingActive ? (
349+
<>
350+
<MenuSeparator />
351+
<MenuGroup>
352+
<div className={MENU_LABEL_CLASS}>Order sections</div>
353+
<MenuRadioGroup
354+
value={props.sectionOrderMode}
355+
onValueChange={handleSectionOrderModeChange}
356+
>
357+
{(
358+
Object.keys(SECTION_ORDER_MODE_LABELS) as ReadonlyArray<SidebarSectionOrderMode>
359+
).map((mode) => (
360+
<MenuRadioItem key={mode} value={mode} className={MENU_ITEM_CLASS}>
361+
<Choice>{SECTION_ORDER_MODE_LABELS[mode]}</Choice>
362+
</MenuRadioItem>
363+
))}
364+
</MenuRadioGroup>
365+
{/* Only offered once there is an arrangement to undo: with
366+
Busiest first selected there is nothing stored to reset. */}
367+
{props.sectionOrderMode === "activity" ? null : (
368+
<MenuItem className={MENU_ITEM_CLASS} onClick={props.onSectionOrderReset}>
369+
Reset section order
370+
</MenuItem>
371+
)}
372+
</MenuGroup>
373+
</>
374+
) : null}
326375
</MenuPopup>
327376
</Menu>
328377
</div>

‎apps/web/src/components/sidebarThreadGrouping.test.ts‎

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ import type { EnvironmentId, ProjectId } from "@t3tools/contracts";
55
import type { ProviderInstanceEntry } from "../providerInstances";
66
import {
77
buildSidebarThreadGroups,
8+
collectSidebarSectionKeys,
89
deriveSidebarProviderOptions,
910
flattenSidebarThreadGroups,
11+
orderSidebarThreadGroups,
12+
planSidebarSectionOrder,
1013
resolveThreadProviderIdentity,
1114
settledShelfKey,
1215
type GroupableThread,
@@ -534,3 +537,203 @@ describe("history inside a section", () => {
534537
expect(groups[0]?.threadCount).toBe(0);
535538
});
536539
});
540+
541+
describe("orderSidebarThreadGroups", () => {
542+
/** Three environment sections, deliberately not in alphabetical order. */
543+
const environmentSections = () =>
544+
buildSidebarThreadGroups({
545+
threads: [
546+
thread({ id: "a", environmentId: "remote" }),
547+
thread({ id: "b", environmentId: "local" }),
548+
],
549+
primaryAxis: "environment",
550+
secondaryAxis: "none",
551+
context: CONTEXT,
552+
});
553+
554+
it("passes the built order through untouched when sorting by activity", () => {
555+
const groups = environmentSections();
556+
expect(
557+
orderSidebarThreadGroups(groups, { mode: "activity", manualKeys: ["environment:local"] }),
558+
).toBe(groups);
559+
});
560+
561+
it("sorts by label when alphabetical", () => {
562+
expect(
563+
orderSidebarThreadGroups(environmentSections(), {
564+
mode: "alphabetical",
565+
manualKeys: [],
566+
}).map((group) => group.label),
567+
).toEqual(["Remote box", "This computer"]);
568+
});
569+
570+
it("follows the manual order", () => {
571+
expect(
572+
orderSidebarThreadGroups(environmentSections(), {
573+
mode: "manual",
574+
manualKeys: ["environment:local", "environment:remote"],
575+
}).map((group) => group.label),
576+
).toEqual(["This computer", "Remote box"]);
577+
});
578+
579+
it("keeps a section the user never placed after the ones they did", () => {
580+
expect(
581+
orderSidebarThreadGroups(environmentSections(), {
582+
mode: "manual",
583+
manualKeys: ["environment:local"],
584+
}).map((group) => group.label),
585+
).toEqual(["This computer", "Remote box"]);
586+
});
587+
588+
it("orders nested sections by their parent-prefixed keys", () => {
589+
const groups = buildSidebarThreadGroups({
590+
threads: [
591+
thread({ id: "a", environmentId: "local", projectId: "api" }),
592+
thread({ id: "b", environmentId: "local", projectId: "app" }),
593+
],
594+
primaryAxis: "environment",
595+
secondaryAxis: "project",
596+
context: CONTEXT,
597+
});
598+
const ordered = orderSidebarThreadGroups(groups, {
599+
mode: "manual",
600+
manualKeys: ["environment:local/project:local:app"],
601+
});
602+
expect(ordered[0]?.children.map((child) => child.label)).toEqual(["local/app", "local/api"]);
603+
// Reordering a level must not disturb what is inside those sections.
604+
expect(ordered[0]?.children[0]?.threads.map((t) => t.id)).toEqual(["b"]);
605+
});
606+
607+
it("leaves thread order and counts alone", () => {
608+
const groups = environmentSections();
609+
const ordered = orderSidebarThreadGroups(groups, { mode: "alphabetical", manualKeys: [] });
610+
expect(ordered.map((group) => group.threadCount)).toEqual([1, 1]);
611+
expect(ordered.flatMap((group) => group.threads.map((t) => t.id)).sort()).toEqual(["a", "b"]);
612+
});
613+
});
614+
615+
describe("collectSidebarSectionKeys", () => {
616+
it("lists every key, parents before their children", () => {
617+
const groups = buildSidebarThreadGroups({
618+
threads: [thread({ id: "a", environmentId: "local", projectId: "app" })],
619+
primaryAxis: "environment",
620+
secondaryAxis: "project",
621+
context: CONTEXT,
622+
});
623+
expect(collectSidebarSectionKeys(groups)).toEqual([
624+
"environment:local",
625+
"environment:local/project:local:app",
626+
]);
627+
});
628+
});
629+
630+
describe("planSidebarSectionOrder", () => {
631+
it("records the whole level so the result no longer depends on activity", () => {
632+
expect(
633+
planSidebarSectionOrder({
634+
siblingKeys: ["a", "b", "c"],
635+
fromIndex: 2,
636+
toIndex: 0,
637+
manualKeys: [],
638+
}),
639+
).toEqual(["c", "a", "b"]);
640+
});
641+
642+
it("leaves other levels' keys in place", () => {
643+
expect(
644+
planSidebarSectionOrder({
645+
siblingKeys: ["a", "b"],
646+
fromIndex: 1,
647+
toIndex: 0,
648+
manualKeys: ["x", "a", "y", "b"],
649+
}),
650+
).toEqual(["x", "y", "b", "a"]);
651+
});
652+
653+
it("returns the same list for a move that changes nothing", () => {
654+
const manualKeys = ["a", "b"];
655+
expect(
656+
planSidebarSectionOrder({ siblingKeys: ["a", "b"], fromIndex: 1, toIndex: 1, manualKeys }),
657+
).toBe(manualKeys);
658+
expect(
659+
planSidebarSectionOrder({ siblingKeys: ["a", "b"], fromIndex: 0, toIndex: -1, manualKeys }),
660+
).toBe(manualKeys);
661+
expect(
662+
planSidebarSectionOrder({ siblingKeys: ["a", "b"], fromIndex: 1, toIndex: 2, manualKeys }),
663+
).toBe(manualKeys);
664+
});
665+
666+
it("round-trips through the order it plans", () => {
667+
const groups = buildSidebarThreadGroups({
668+
threads: [
669+
thread({ id: "a", environmentId: "remote" }),
670+
thread({ id: "b", environmentId: "local" }),
671+
],
672+
primaryAxis: "environment",
673+
secondaryAxis: "none",
674+
context: CONTEXT,
675+
});
676+
const siblingKeys = groups.map((group) => group.key);
677+
const manualKeys = planSidebarSectionOrder({
678+
siblingKeys,
679+
fromIndex: 1,
680+
toIndex: 0,
681+
manualKeys: [],
682+
});
683+
expect(
684+
orderSidebarThreadGroups(groups, { mode: "manual", manualKeys }).map((group) => group.label),
685+
).toEqual(["This computer", "Remote box"]);
686+
});
687+
});
688+
689+
describe("header rows carry their level", () => {
690+
it("gives each header its siblings and position, per level", () => {
691+
const groups = buildSidebarThreadGroups({
692+
threads: [
693+
thread({ id: "a", environmentId: "local", projectId: "app" }),
694+
thread({ id: "b", environmentId: "local", projectId: "api" }),
695+
thread({ id: "c", environmentId: "remote", projectId: "app" }),
696+
],
697+
primaryAxis: "environment",
698+
secondaryAxis: "project",
699+
context: CONTEXT,
700+
});
701+
const headers = flattenSidebarThreadGroups(groups, new Set()).flatMap((row) =>
702+
row.kind === "header"
703+
? [
704+
{
705+
key: row.group.key,
706+
parentKey: row.parentKey,
707+
index: row.index,
708+
siblingKeys: row.siblingKeys,
709+
},
710+
]
711+
: [],
712+
);
713+
expect(headers.map((header) => [header.key, header.parentKey, header.index])).toEqual([
714+
["environment:local", null, 0],
715+
["environment:local/project:local:app", "environment:local", 0],
716+
["environment:local/project:local:api", "environment:local", 1],
717+
["environment:remote", null, 1],
718+
["environment:remote/project:remote:app", "environment:remote", 0],
719+
]);
720+
expect(headers[1]?.siblingKeys).toEqual([
721+
"environment:local/project:local:app",
722+
"environment:local/project:local:api",
723+
]);
724+
});
725+
726+
it("hides a collapsed section's children from reordering, as it hides them from the eye", () => {
727+
const groups = buildSidebarThreadGroups({
728+
threads: [thread({ id: "a", environmentId: "local", projectId: "app" })],
729+
primaryAxis: "environment",
730+
secondaryAxis: "project",
731+
context: CONTEXT,
732+
});
733+
expect(
734+
flattenSidebarThreadGroups(groups, new Set(["environment:local"])).filter(
735+
(row) => row.kind === "header",
736+
),
737+
).toHaveLength(1);
738+
});
739+
});

0 commit comments

Comments
 (0)