fix(ui): sort the "Reports to" manager picker alphabetically

The manager picker on agent profiles and in agent configuration listed
candidate managers in directory order, which made it hard to find a
specific agent. Sort the rows by name (case-insensitive, numeric-aware),
matching how the sidebar orders agents.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
devinfoleyandClaude Opus 5.5 committed 2026-12-04 00:57:50 +00:00
1 parent c2a8821809
commit 18cb8b75ac
2 files changed
+44 -4

No files matched your search

+35
View File
@@ -0,0 +1,35 @@
import { describe, expect, it } from "vitest";
import type { Agent } from "@paperclipai/shared";
import { reportsToPickerRows } from "./ReportsToPicker";
function agent(id: string, name: string, status: Agent["status"] = "idle"): Agent {
return { id, name, status } as Agent;
}
describe("reportsToPickerRows", () => {
it("lists candidate managers alphabetically by name, ignoring case", () => {
const rows = reportsToPickerRows([
agent("1", "Mac Coder"),
agent("2", "Bug Bot (Deprecated)"),
agent("3", "nibbler"),
agent("4", "CTO"),
agent("5", "Agent 10"),
agent("6", "Agent 2"),
]);
expect(rows.map((row) => row.name)).toEqual([
"Agent 2",
"Agent 10",
"Bug Bot (Deprecated)",
"CTO",
"Mac Coder",
"nibbler",
]);
});
it("drops terminated and excluded agents without mutating the input", () => {
const agents = [agent("1", "Zed"), agent("2", "Gone", "terminated"), agent("3", "Self"), agent("4", "Amy")];
const rows = reportsToPickerRows(agents, ["3"]);
expect(rows.map((row) => row.id)).toEqual(["4", "1"]);
expect(agents.map((row) => row.id)).toEqual(["1", "2", "3", "4"]);
});
});
+9 -4
View File
@@ -10,6 +10,14 @@ import { FlyoutAppearanceProvider, FlyoutHeader, FlyoutOptions } from "./ui/flyo
import { Check, User } from "lucide-react";
import { cn } from "../lib/utils";
/** Candidate managers in alphabetical order, without terminated or excluded agents. */
export function reportsToPickerRows(agents: Agent[], excludeAgentIds: string[] = []): Agent[] {
const exclude = new Set(excludeAgentIds);
return agents
.filter((a) => a.status !== "terminated" && !exclude.has(a.id))
.sort((left, right) => left.name.localeCompare(right.name, undefined, { sensitivity: "base", numeric: true }));
}
export function ReportsToPicker({
agents,
value,
@@ -32,10 +40,7 @@ export function ReportsToPicker({
disabledAgentIds?: string[];
}) {
const [open, setOpen] = useState(false);
const exclude = new Set(excludeAgentIds);
const rows = agents.filter(
(a) => a.status !== "terminated" && !exclude.has(a.id),
);
const rows = reportsToPickerRows(agents, excludeAgentIds);
const current = value ? agents.find((a) => a.id === value) : null;
const terminatedManager = current?.status === "terminated";
const unknownManager = Boolean(value && !current);