From 18cb8b75acfa47d4f98bdb13945a2da33f157fe5 Mon Sep 17 00:00:00 2001 From: devinfoley <139239+devinfoley@users.noreply.github.com> Date: Fri, 4 Dec 2026 00:57:50 +0000 Subject: [PATCH] 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 --- ui/src/components/ReportsToPicker.test.ts | 35 +++++++++++++++++++++++ ui/src/components/ReportsToPicker.tsx | 13 ++++++--- 2 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 ui/src/components/ReportsToPicker.test.ts diff --git a/ui/src/components/ReportsToPicker.test.ts b/ui/src/components/ReportsToPicker.test.ts new file mode 100644 index 00000000000..b887e510e35 --- /dev/null +++ b/ui/src/components/ReportsToPicker.test.ts @@ -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"]); + }); +}); diff --git a/ui/src/components/ReportsToPicker.tsx b/ui/src/components/ReportsToPicker.tsx index 6cd4909c8cc..9525ef7eb2f 100644 --- a/ui/src/components/ReportsToPicker.tsx +++ b/ui/src/components/ReportsToPicker.tsx @@ -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);