mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-05 06:03:51 +01:00
fix(ui): prioritize recent composer assignees (#23744)
## Thinking Path > - Paperclip helps people manage work with agents. > - People pick a recipient in the new-task and task reply composers. > - The picker puts people before agents. Frequently used recipients can be far down the list. > - The composer can use its saved assignee history to put recent recipients at the top. > - This change shows up to five recent choices, then puts the other agents before the other people. ## Linked Issues or Issue Description **What existing behavior does this improve?** The assignee list in the task composer. **Subsystem affected** UI board. **Current behavior** Open the assignee picker in a task composer. The list can show people before all agents. It has no top list of mixed agent and human selections. **Proposed behavior** Show the five most recent available choices first in newest-first order. Show the other agents, then the other people. Put No assignee at the end of the list and include it in search. **Reason and benefit** People can find recipients they use often and reach other agents sooner. Related composer UI changes are #15050 and #14250. ## What Changed - Read company-specific assignee history in the shared composer picker. - Record each explicit picker selection, including reselection of the current assignee. Reset run settings only when the assignee changes. - Keep the saved recent-agent fallback for older browser history. - Test recency order, the five-choice limit, company boundaries, search, reselection, and reopening with 268 choices in the new-task and reply composers. Bound option reads in each step. ## Verification - The new regression test failed on the old order and passed with the fix. - Ran the composer, run settings, assignee, and recent selection test files with Vitest. All 205 tests passed. - Ran `pnpm --filter @paperclipai/ui typecheck`. It passed. - Ran `pnpm test:e2e tests/e2e/new-task-picker-touch.spec.ts --workers=1`. All three Chromium tests passed. ## Risks Low risk. This changes the order of existing options. The history uses the browser's existing storage. The regression test checks that a missing assignee does not reduce the five-choice limit. ## Model Used OpenAI Codex, GPT-6, with shell and GitHub tooling. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
70d780107d
commit
a3719da3ca
8 files changed
+166
-34
No files matched your search
@@ -193,6 +193,10 @@ the latest agent that assigned it to them. If no assignment is available, it use
|
||||
the latest other commenter, or leaves the recipient empty. A manual recipient
|
||||
choice stays selected while task data refreshes.
|
||||
|
||||
The composer assignee picker shows up to five recent choices for the company,
|
||||
most recent first. Remaining agents appear before the remaining people. Use
|
||||
**No assignee** at the end of the list or find it with search.
|
||||
|
||||
Task reply and new-task composers submit with Enter by default; Shift+Enter
|
||||
adds a new line. Settings → Experimental → **Command/Ctrl+Enter to Submit**
|
||||
restores the previous behavior, where Enter adds a new line and Command/Ctrl+Enter
|
||||
|
||||
@@ -124,9 +124,11 @@ test("new-task assignee, model, and project sheets scroll by touch and retain th
|
||||
const modelTrigger = page.getByRole("button", { name: "Select model and effort", exact: true });
|
||||
await assigneeTrigger.tap();
|
||||
const assigneePicker = page.getByRole("dialog", { name: "Select assignee", exact: true });
|
||||
const lastAssignee = await swipeToLastOption(page, assigneePicker);
|
||||
await expect(lastAssignee).toContainText("Touch Agent 22");
|
||||
await lastAssignee.tap();
|
||||
const assigneeList = assigneePicker.getByRole("listbox", { name: "Assignees" });
|
||||
const targetAssignee = assigneeList.getByRole("option", { name: /Touch Agent 22/ });
|
||||
await expect(assigneeList.getByRole("option").last()).toHaveText("No assignee");
|
||||
await swipeToLastOption(page, assigneePicker, assigneeList, targetAssignee);
|
||||
await targetAssignee.tap();
|
||||
await expect(assigneePicker).toBeHidden();
|
||||
await expect(assigneeTrigger).toBeFocused();
|
||||
await modelTrigger.tap();
|
||||
|
||||
@@ -25,7 +25,7 @@ import {
|
||||
import { useProjectOrder } from "../hooks/useProjectOrder";
|
||||
import { useStreamlinedUiEnabled } from "../hooks/useStreamlinedUiEnabled";
|
||||
import { useCoordinatorWorkspaceEnabled } from "../hooks/useCoordinatorWorkspaceEnabled";
|
||||
import { getRecentAssigneeIds, getRecentAssigneeSelectionIds, sortAgentsByRecency, trackRecentAssignee, trackRecentAssigneeUser } from "../lib/recent-assignees";
|
||||
import { getCompanyRecentAssigneeSelectionIds, trackRecentAssignee, trackRecentAssigneeUser } from "../lib/recent-assignees";
|
||||
import { getLastProjectId, getRecentProjectIds, trackRecentProject } from "../lib/recent-projects";
|
||||
import { recordRecentTask } from "../lib/recent-tasks";
|
||||
import { buildExecutionPolicy } from "../lib/issue-execution-policy";
|
||||
@@ -1352,19 +1352,18 @@ function AccountNewIssueDialog({ ignoreDefaults }: { ignoreDefaults: boolean })
|
||||
const selectedReusableWorktree = selectableReusableWorkspaces.find((workspace) => workspace.id === selectedExecutionWorkspaceId);
|
||||
const worktreeSelectionIncomplete = canChooseWorktrees && executionWorkspaceMode === "reuse_existing"
|
||||
&& (worktreesLoading || worktreesError || !selectedReusableWorktree);
|
||||
const recentAssigneeIds = useMemo(() => getRecentAssigneeIds(), [newIssueOpen]);
|
||||
const recentProjectIds = useMemo(() => getRecentProjectIds(), [newIssueOpen]);
|
||||
const assigneeOptions = useMemo<InlineEntityOption[]>(
|
||||
() => [
|
||||
...currentUserAssigneeOption(currentUserId),
|
||||
...buildCompanyUserInlineOptions(companyMembers?.users, { excludeUserIds: [currentUserId] }),
|
||||
...sortAgentsByRecency((agents ?? []).filter(isAgentTaskTarget), recentAssigneeIds).map((agent) => ({
|
||||
...(agents ?? []).filter(isAgentTaskTarget).sort((a, b) => a.name.localeCompare(b.name)).map((agent) => ({
|
||||
id: assigneeValueFromSelection({ assigneeAgentId: agent.id }),
|
||||
label: agent.name,
|
||||
searchText: `${agent.name} ${agent.role} ${agent.title ?? ""}`,
|
||||
})),
|
||||
],
|
||||
[agents, companyMembers?.users, currentUserId, recentAssigneeIds],
|
||||
[agents, companyMembers?.users, currentUserId],
|
||||
);
|
||||
// Resolve once after the directory loads, without resetting text typed while
|
||||
// the queries were in flight or replacing an explicit/restored assignee.
|
||||
@@ -1373,12 +1372,7 @@ function AccountNewIssueDialog({ ignoreDefaults }: { ignoreDefaults: boolean })
|
||||
|| !agents || !sessionFetched || !membersFetched || primaryAgent?.loading) return;
|
||||
defaultAssigneePendingRef.current = false;
|
||||
const available = new Set(assigneeOptions.map((option) => option.id));
|
||||
const scopedRecents = getRecentAssigneeSelectionIds(effectiveCompanyId);
|
||||
// Older history has no company key. Agent IDs identify their company;
|
||||
// human IDs can belong to several companies and cannot be migrated safely.
|
||||
const recents = scopedRecents.length ? scopedRecents
|
||||
: getRecentAssigneeSelectionIds().filter((value) => value.startsWith("agent:"));
|
||||
const recent = recents.find((value) => available.has(value));
|
||||
const recent = getCompanyRecentAssigneeSelectionIds(effectiveCompanyId).find((value) => available.has(value));
|
||||
const targets = agents.filter(isAgentTaskTarget);
|
||||
const fallback = targets.find((agent) => agent.id === primaryAgent?.primaryAgentId)
|
||||
?? targets.find((agent) => agent.role === "ceo") ?? targets[0];
|
||||
@@ -1556,9 +1550,6 @@ function AccountNewIssueDialog({ ignoreDefaults }: { ignoreDefaults: boolean })
|
||||
onPendingAssigneeChange={(value) => {
|
||||
if (value === null) return;
|
||||
defaultAssigneePendingRef.current = false;
|
||||
const next = parseAssigneeValue(value);
|
||||
if (next.assigneeAgentId) trackRecentAssignee(next.assigneeAgentId, effectiveCompanyId ?? undefined);
|
||||
if (next.assigneeUserId) trackRecentAssigneeUser(next.assigneeUserId, effectiveCompanyId ?? undefined);
|
||||
setAssigneeValue(value);
|
||||
setComposerSettings(null);
|
||||
setAssigneeModelLane("primary");
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useEffect, useLayoutEffect, useRef, useState, type CSSProperties, type ReactNode, type Ref } from "react";
|
||||
import { useEffect, useLayoutEffect, useMemo, useRef, useState, type CSSProperties, type ReactNode, type Ref } from "react";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { ArrowLeft, Check, ChevronDown, Plus, RotateCcw, Search, X, Zap } from "lucide-react";
|
||||
import { aiRuntimeConnectionBindingSchema, agentHarnessType, type Agent, type IssueAssigneeAdapterOverrides } from "@paperclipai/shared";
|
||||
@@ -10,6 +10,8 @@ import { ACCOUNT_BOUND_MODEL_DISCOVERY_QUERY_OPTIONS, nativeTaskModelCatalogOpti
|
||||
import { cn } from "@/lib/utils";
|
||||
import { useMobileEntityPickerViewportStyle } from "@/hooks/useMobileEntityPickerViewportStyle";
|
||||
import { getLastComposerEffort, rememberComposerEffort } from "@/lib/recent-composer-effort";
|
||||
import { getCompanyRecentAssigneeSelectionIds, trackRecentAssigneeSelection } from "@/lib/recent-assignees";
|
||||
import { orderItemsBySelectedAndRecent } from "@/lib/recent-selections";
|
||||
import type { InlineEntityOption } from "@/components/InlineEntitySelector";
|
||||
import { Dialog, DialogClose, DialogContent, DialogTitle, DialogTrigger } from "@/components/ui/dialog";
|
||||
import { Popover, PopoverAnchor, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
||||
@@ -54,6 +56,9 @@ const HARNESS_LABELS: Record<string, string> = {
|
||||
hermes_gateway: "Hermes Gateway",
|
||||
};
|
||||
|
||||
const NO_ASSIGNEE_OPTION: InlineEntityOption = { id: "", label: "No assignee", searchText: "Unassigned" };
|
||||
const RECENT_ASSIGNEE_LIMIT = 5;
|
||||
|
||||
function harnessLabel(agent: Agent | undefined): string {
|
||||
if (!agent) return "Choose an agent";
|
||||
const harness = HARNESS_LABELS[agentHarnessType(agent.adapterType, agent.adapterConfig)] ?? agent.adapterType;
|
||||
@@ -165,11 +170,29 @@ export function ComposerRunSettingsPicker({
|
||||
}
|
||||
}, [companyId, agentId, model, modelSupported, settings, base.model, base.effort, base.fast, effortChoicesKey, onSettingsChange]);
|
||||
const changed = Boolean(selected.model || selected.effort || selected.fast);
|
||||
const assigneeOptions = [{ id: "", label: "No assignee", searchText: "Unassigned" }, ...options.filter((item) => item.id !== "")];
|
||||
const filteredAgents = assigneeOptions.filter((item) => {
|
||||
const assigneeOptions = useMemo(() => {
|
||||
if (!open || view !== "agents") return [];
|
||||
const agentOptions: InlineEntityOption[] = [];
|
||||
const peopleOptions: InlineEntityOption[] = [];
|
||||
const available = new Set<string>();
|
||||
for (const item of options) {
|
||||
const { id } = item;
|
||||
if (!id) continue;
|
||||
available.add(id);
|
||||
if (id.startsWith("agent:")) agentOptions.push(item);
|
||||
else peopleOptions.push(item);
|
||||
}
|
||||
const recentIds = [...new Set(getCompanyRecentAssigneeSelectionIds(companyId))]
|
||||
.filter((id) => available.has(id));
|
||||
return orderItemsBySelectedAndRecent(
|
||||
[...agentOptions, ...peopleOptions, NO_ASSIGNEE_OPTION], null, recentIds, RECENT_ASSIGNEE_LIMIT,
|
||||
);
|
||||
}, [open, view, options, companyId]);
|
||||
const assigneeQuery = assigneeSearch.trim().toLowerCase();
|
||||
const filteredAssignees = !assigneeQuery ? assigneeOptions : assigneeOptions.filter((item) => {
|
||||
const optionAgent = agents.get(item.id.startsWith("agent:") ? item.id.slice(6) : "");
|
||||
return `${item.label} ${item.searchText ?? ""} ${optionAgent?.role ?? ""} ${harnessLabel(optionAgent)}`
|
||||
.toLowerCase().includes(assigneeSearch.trim().toLowerCase());
|
||||
.toLowerCase().includes(assigneeQuery);
|
||||
});
|
||||
const query = modelSearch.trim();
|
||||
const filteredModels = models.filter((item) =>
|
||||
@@ -190,6 +213,7 @@ export function ComposerRunSettingsPicker({
|
||||
}, [agentId]);
|
||||
|
||||
const chooseAssignee = (value: string) => {
|
||||
if (value) trackRecentAssigneeSelection(value, companyId);
|
||||
if (value !== assigneeValue) {
|
||||
onAssigneeChange(value);
|
||||
onSettingsChange(null);
|
||||
@@ -223,7 +247,7 @@ export function ComposerRunSettingsPicker({
|
||||
onClick={() => { setView("agents"); setHighlightedAssignee(0); }}
|
||||
className="flex h-8 min-w-0 max-w-full items-center gap-1.5 rounded-full px-2.5 hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50">
|
||||
{renderAssigneeIdentity?.(assigneeValue, agent?.name ?? "Unassigned", "trigger")}
|
||||
<span data-testid="task-chat-composer-assignee-label" className="min-w-0 truncate">{assigneeOptions.find((item) => item.id === assigneeValue)?.label ?? "Unassigned"}</span>
|
||||
<span data-testid="task-chat-composer-assignee-label" className="min-w-0 truncate">{assigneeValue ? options.find((item) => item.id === assigneeValue)?.label ?? "Unassigned" : NO_ASSIGNEE_OPTION.label}</span>
|
||||
{!modelSupported ? <ChevronDown className="size-3 shrink-0 text-muted-foreground" aria-hidden /> : null}
|
||||
</button></Trigger> : null}
|
||||
{modelSupported ? <>
|
||||
@@ -264,13 +288,13 @@ export function ComposerRunSettingsPicker({
|
||||
</div> : view === "agents" ? <div className="composer-run-settings-list-view p-2">
|
||||
<div className="flex items-center gap-2 px-1 py-1.5"><span className="min-w-0 flex-1 text-xs font-semibold">Choose assignee</span>{closeButton}</div>
|
||||
<div className="relative mt-2"><Search className="pointer-events-none absolute left-2.5 top-2.5 size-4 text-muted-foreground" aria-hidden /><input autoFocus type="search" aria-label="Search assignees" placeholder="Search assignees…" value={assigneeSearch} onChange={(event) => { setAssigneeSearch(event.target.value); setHighlightedAssignee(0); }} onKeyDown={(event) => {
|
||||
if (event.key === "ArrowDown" || event.key === "ArrowUp") { event.preventDefault(); setHighlightedAssignee((current) => filteredAgents.length ? (current + (event.key === "ArrowDown" ? 1 : -1) + filteredAgents.length) % filteredAgents.length : 0); }
|
||||
if (event.key === "Enter" && filteredAgents.length) { event.preventDefault(); chooseAssignee(filteredAgents[Math.min(highlightedAssignee, filteredAgents.length - 1)]!.id); }
|
||||
if (event.key === "ArrowDown" || event.key === "ArrowUp") { event.preventDefault(); setHighlightedAssignee((current) => filteredAssignees.length ? (current + (event.key === "ArrowDown" ? 1 : -1) + filteredAssignees.length) % filteredAssignees.length : 0); }
|
||||
if (event.key === "Enter" && filteredAssignees.length) { event.preventDefault(); chooseAssignee(filteredAssignees[Math.min(highlightedAssignee, filteredAssignees.length - 1)]!.id); }
|
||||
}} className="h-9 w-full rounded-md border border-border bg-background pl-8 pr-2 text-sm outline-none placeholder:text-muted-foreground focus-visible:ring-2 focus-visible:ring-ring" /></div>
|
||||
<div className="mt-2 min-h-0 max-h-60 overflow-y-auto overscroll-contain touch-pan-y" role="listbox" aria-label="Assignees">{filteredAgents.map((item, index) => {
|
||||
<div className="mt-2 min-h-0 max-h-60 overflow-y-auto overscroll-contain touch-pan-y" role="listbox" aria-label="Assignees">{filteredAssignees.map((item, index) => {
|
||||
const optionAgent = agents.get(item.id.startsWith("agent:") ? item.id.slice(6) : "");
|
||||
return <button key={item.id} type="button" role="option" aria-selected={item.id === assigneeValue} onMouseEnter={() => setHighlightedAssignee(index)} onClick={() => chooseAssignee(item.id)} className={cn("flex w-full items-center gap-2 rounded-md px-2 py-2 text-left focus-visible:outline-none", highlightedAssignee === index ? "bg-accent" : "hover:bg-accent")}>{renderAssigneeIdentity?.(item.id, item.label, "option")}<span className="min-w-0 flex-1"><span className="block truncate text-sm font-medium">{item.label}</span>{optionAgent ? <span className="block truncate text-xs text-muted-foreground">{optionAgent.role}</span> : null}</span>{optionAgent ? <span className="truncate text-xs text-muted-foreground">{harnessLabel(optionAgent)}</span> : null}{item.id === assigneeValue ? <Check className="composer-run-settings-accent size-4" /> : null}</button>;
|
||||
})}{!filteredAgents.length ? <p className="px-2 py-2 text-xs text-muted-foreground">No matches.</p> : null}</div>
|
||||
})}{!filteredAssignees.length ? <p className="px-2 py-2 text-xs text-muted-foreground">No matches.</p> : null}</div>
|
||||
</div> : <div className="composer-run-settings-list-view p-2">
|
||||
<div className="flex items-center gap-2 px-1 py-1.5"><button type="button" aria-label="Back to selection" onClick={() => setView("settings")} className="grid size-7 place-items-center rounded-md hover:bg-accent"><ArrowLeft className="size-4" /></button><span className="min-w-0 flex-1"><span className="block text-xs font-semibold">Choose model</span><span className="block truncate text-xs text-muted-foreground">{harnessLabel(agent)}</span></span>{closeButton}</div>
|
||||
<div className="relative mt-2"><Search className="pointer-events-none absolute left-2.5 top-2.5 size-4 text-muted-foreground" aria-hidden /><input autoFocus type="search" aria-label="Search or paste a model ID" placeholder="Search or paste a model ID" value={modelSearch} onChange={(event) => setModelSearch(event.target.value)} onKeyDown={(event) => { if (event.key === "Enter" && manualValid && !exactMatch) chooseModel(query); }} className="h-9 w-full rounded-md border border-border bg-background pl-8 pr-2 text-sm outline-none placeholder:text-muted-foreground focus-visible:ring-2 focus-visible:ring-ring" /></div>
|
||||
|
||||
@@ -20,6 +20,7 @@ import { instanceSettingsApi } from "@/api/instanceSettings";
|
||||
import { CoordinatorPresentation } from "@/components/coordinator/CoordinatorPresentation";
|
||||
import { ThemeProvider } from "@/context/ThemeContext";
|
||||
import { DRAFT_DEBOUNCE_MS } from "../../lib/composer-draft";
|
||||
import { getRecentAssigneeSelectionIds, trackRecentAssignee, trackRecentAssigneeUser } from "../../lib/recent-assignees";
|
||||
import {
|
||||
loadDraftAttachments,
|
||||
loadDraftSubmission,
|
||||
@@ -2506,6 +2507,97 @@ describe("TaskChatComposer", () => {
|
||||
expect(trigger().textContent).toContain("Me");
|
||||
});
|
||||
|
||||
it.each(["reply", "creation"])("keeps recent assignees first on a large roster in %s mode", async (mode) => {
|
||||
vi.stubGlobal("ResizeObserver", class { observe() {} disconnect() {} });
|
||||
const client = new QueryClient({ defaultOptions: { queries: { retry: false } } });
|
||||
const companyId = "company-1";
|
||||
trackRecentAssigneeUser("older", companyId);
|
||||
trackRecentAssignee("alpha", companyId);
|
||||
trackRecentAssigneeUser("sam", companyId);
|
||||
trackRecentAssignee("beta", companyId);
|
||||
trackRecentAssignee("gamma", companyId);
|
||||
trackRecentAssigneeUser("me", companyId);
|
||||
trackRecentAssignee("removed", companyId);
|
||||
trackRecentAssigneeUser("lee", "company-2");
|
||||
|
||||
const otherAgents = Array.from({ length: 200 }, (_, index) => ({ id: `agent:team-${index}`, label: `Team agent ${index}` }));
|
||||
const otherPeople = Array.from({ length: 60 }, (_, index) => ({ id: `user:team-${index}`, label: `Team member ${index}` }));
|
||||
const roster = [
|
||||
{ id: "user:me", label: "Me" },
|
||||
{ id: "user:lee", label: "Lee" },
|
||||
{ id: "user:older", label: "Pat" },
|
||||
{ id: "user:sam", label: "Sam" },
|
||||
{ id: "agent:alpha", label: "Alpha" },
|
||||
{ id: "agent:beta", label: "Beta" },
|
||||
{ id: "agent:delta", label: "Delta" },
|
||||
{ id: "agent:gamma", label: "Gamma" },
|
||||
...otherPeople,
|
||||
...otherAgents,
|
||||
];
|
||||
const readBudget = 20 * roster.length;
|
||||
let idReads = 0;
|
||||
const options = roster.map(({ id, label }) => ({
|
||||
label,
|
||||
get id() {
|
||||
if (++idReads > readBudget) throw new Error("Assignee picker exceeded its linear roster read budget");
|
||||
return id;
|
||||
},
|
||||
}));
|
||||
const creation = mode === "creation" ? {
|
||||
value: "", onChange: vi.fn(), onSubmit: vi.fn(), submitLabel: "Create task",
|
||||
onSelectFiles: vi.fn(), runSettings: null, onRunSettingsChange: vi.fn(),
|
||||
} : undefined;
|
||||
const modelAgents = new Map<string, Agent>();
|
||||
function Composer() {
|
||||
const [assignee, setAssignee] = useState("agent:delta");
|
||||
return <TaskChatComposer onAdd={vi.fn()} workMode="standard" enableReassign companyId={companyId}
|
||||
creation={creation} currentAssigneeValue={assignee} reassignOptions={options} modelAgents={modelAgents}
|
||||
onPendingAssigneeChange={creation ? (value) => setAssignee(value ?? "") : undefined} />;
|
||||
}
|
||||
try {
|
||||
render(<QueryClientProvider client={client}><Composer /></QueryClientProvider>);
|
||||
const trigger = container.querySelector<HTMLButtonElement>('[aria-label="Select assignee"]')!;
|
||||
const rows = () => Array.from(document.querySelectorAll<HTMLButtonElement>('[aria-label="Assignees"] [role="option"]'));
|
||||
const order = () => rows().map((row) => row.querySelector<HTMLElement>("[data-assignee-identity]")?.dataset.assigneeIdentity ?? row.textContent);
|
||||
|
||||
idReads = 0;
|
||||
await act(async () => trigger.click());
|
||||
expect(order()).toEqual([
|
||||
"user:me", "agent:gamma", "agent:beta", "user:sam", "agent:alpha", "agent:delta",
|
||||
...otherAgents.map(({ id }) => id), "user:lee", "user:older", ...otherPeople.map(({ id }) => id), "No assignee",
|
||||
]);
|
||||
|
||||
idReads = 0;
|
||||
const current = rows().find((row) => row.getAttribute("aria-selected") === "true")!;
|
||||
await act(async () => current.click());
|
||||
expect(getRecentAssigneeSelectionIds(companyId)[0]).toBe("agent:delta");
|
||||
if (creation) expect(creation.onRunSettingsChange).not.toHaveBeenCalled();
|
||||
|
||||
idReads = 0;
|
||||
await act(async () => trigger.click());
|
||||
expect(order()[0]).toBe("agent:delta");
|
||||
|
||||
idReads = 0;
|
||||
const search = document.querySelector<HTMLInputElement>('[aria-label="Search assignees"]')!;
|
||||
await act(async () => {
|
||||
Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")!.set!.call(search, "Lee");
|
||||
search.dispatchEvent(new Event("input", { bubbles: true }));
|
||||
});
|
||||
expect(order()).toEqual(["user:lee"]);
|
||||
|
||||
idReads = 0;
|
||||
await act(async () => rows()[0]!.click());
|
||||
expect(getRecentAssigneeSelectionIds(companyId)[0]).toBe("user:lee");
|
||||
idReads = 0;
|
||||
await act(async () => trigger.click());
|
||||
expect(order().slice(0, 6)).toEqual(["user:lee", "agent:delta", "user:me", "agent:gamma", "agent:beta", "agent:alpha"]);
|
||||
} finally {
|
||||
render(<></>);
|
||||
client.clear();
|
||||
vi.unstubAllGlobals();
|
||||
}
|
||||
});
|
||||
|
||||
it("shows human avatars in assignee options and after selection", async () => {
|
||||
renderComposer({
|
||||
onAdd: vi.fn(),
|
||||
|
||||
@@ -66,7 +66,7 @@ import {
|
||||
type MarkdownEditorRef,
|
||||
} from "@/components/MarkdownEditor";
|
||||
import { nextWorkMode } from "@/lib/work-mode-meta";
|
||||
import { trackRecentAssignee, trackRecentAssigneeUser } from "@/lib/recent-assignees";
|
||||
import { trackRecentAssigneeSelection } from "@/lib/recent-assignees";
|
||||
import {
|
||||
InlineEntitySelector,
|
||||
type InlineEntityOption,
|
||||
@@ -663,11 +663,6 @@ export function TaskChatComposer({
|
||||
};
|
||||
|
||||
function updatePendingAssignee(value: string | null) {
|
||||
if (!creation && value && companyId) {
|
||||
const selection = parseAssigneeValue(value);
|
||||
if (selection?.assigneeAgentId) trackRecentAssignee(selection.assigneeAgentId, companyId);
|
||||
if (selection?.assigneeUserId) trackRecentAssigneeUser(selection.assigneeUserId, companyId);
|
||||
}
|
||||
setPendingAssignee(value);
|
||||
onPendingAssigneeChange?.(value);
|
||||
}
|
||||
@@ -1666,7 +1661,10 @@ export function TaskChatComposer({
|
||||
noneLabel="No assignee"
|
||||
searchPlaceholder="Search assignees…"
|
||||
emptyMessage="No matches."
|
||||
onChange={updatePendingAssignee}
|
||||
onChange={(value) => {
|
||||
if (value && companyId) trackRecentAssigneeSelection(value, companyId);
|
||||
updatePendingAssignee(value);
|
||||
}}
|
||||
disabled={disabled}
|
||||
triggerTestId="task-chat-composer-assignee"
|
||||
className="h-8 gap-1.5 border-0 bg-transparent px-2.5 text-xs shadow-none hover:bg-accent focus-visible:bg-accent focus-visible:ring-0"
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { parseAssigneeValue } from "./assignees";
|
||||
import {
|
||||
RECENT_SELECTION_DISPLAY_LIMIT,
|
||||
readRecentSelectionIds,
|
||||
@@ -33,6 +34,14 @@ export function getRecentAssigneeSelectionIds(companyId?: string): string[] {
|
||||
});
|
||||
}
|
||||
|
||||
export function getCompanyRecentAssigneeSelectionIds(companyId: string): string[] {
|
||||
const scopedRecents = getRecentAssigneeSelectionIds(companyId);
|
||||
// Older history has no company key. Agent IDs identify their company;
|
||||
// human IDs can belong to several companies and cannot be migrated safely.
|
||||
return scopedRecents.length ? scopedRecents
|
||||
: getRecentAssigneeSelectionIds().filter((value) => value.startsWith("agent:"));
|
||||
}
|
||||
|
||||
export function trackRecentAssignee(agentId: string, companyId?: string): void {
|
||||
trackRecentSelectionId(STORAGE_KEY, agentSelectionId(agentId));
|
||||
if (companyId) trackRecentSelectionId(`${STORAGE_KEY}:${companyId}`, agentSelectionId(agentId));
|
||||
@@ -43,6 +52,12 @@ export function trackRecentAssigneeUser(userId: string, companyId?: string): voi
|
||||
if (companyId) trackRecentSelectionId(`${STORAGE_KEY}:${companyId}`, userSelectionId(userId));
|
||||
}
|
||||
|
||||
export function trackRecentAssigneeSelection(value: string, companyId: string): void {
|
||||
const { assigneeAgentId, assigneeUserId } = parseAssigneeValue(value);
|
||||
if (assigneeAgentId) trackRecentAssignee(assigneeAgentId, companyId);
|
||||
if (assigneeUserId) trackRecentAssigneeUser(assigneeUserId, companyId);
|
||||
}
|
||||
|
||||
export function sortAgentsByRecency<T extends { id: string; name: string }>(
|
||||
agents: T[],
|
||||
recentIds: string[],
|
||||
|
||||
@@ -14,10 +14,16 @@ export function readRecentSelectionIds(storageKey: string): string[] {
|
||||
|
||||
export function trackRecentSelectionId(storageKey: string, id: string): void {
|
||||
if (!id) return;
|
||||
const recent = readRecentSelectionIds(storageKey).filter((candidate) => candidate !== id);
|
||||
const previous = readRecentSelectionIds(storageKey);
|
||||
if (previous[0] === id) return;
|
||||
const recent = previous.filter((candidate) => candidate !== id);
|
||||
recent.unshift(id);
|
||||
if (recent.length > MAX_STORED_RECENT_SELECTIONS) recent.length = MAX_STORED_RECENT_SELECTIONS;
|
||||
localStorage.setItem(storageKey, JSON.stringify(recent));
|
||||
try {
|
||||
localStorage.setItem(storageKey, JSON.stringify(recent));
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
export function orderItemsBySelectedAndRecent<T extends { id: string }>(
|
||||
|
||||
Reference in new issue
Block a user