fix(ui): keep No project available in new composer (#15382)

Keep the no-project action first and available during project search, while preserving matching-project keyboard selection. Add focused regression coverage for ordering, projectless submission, and filtered Enter behavior.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
DottaandPaperclip authored and GitHub committed 2026-10-06 16:04:08 -05:00
1 parent 582911ba74
commit ee3c728b95
4 files changed
+96 -7

No files matched your search

@@ -352,6 +352,67 @@ describe("InlineEntitySelector", () => {
});
});
it("keeps the no-selection action first when requested", async () => {
const root = createRoot(container);
const onChange = vi.fn();
act(() => {
root.render(
<InlineEntitySelector
value="project-1"
options={[
{ id: "project-1", label: "Project One" },
{ id: "project-2", label: "Project Two" },
]}
recentOptionIds={["project-2"]}
placeholder="Project"
noneLabel="No project"
noneAtTop
searchPlaceholder="Search projects..."
emptyMessage="No projects found."
onChange={onChange}
/>,
);
});
const trigger = container.querySelector("button") as HTMLButtonElement;
await act(() => trigger.click());
const options = Array.from(
document.querySelectorAll<HTMLButtonElement>("[data-mobile-entity-picker-list] > button"),
);
expect(options.map((option) => option.textContent)).toEqual([
"No project",
"Project One",
"Project Two",
]);
const searchInput = document.querySelector<HTMLInputElement>('input[placeholder="Search projects..."]');
const nativeInputValue = Object.getOwnPropertyDescriptor(
window.HTMLInputElement.prototype,
"value",
)?.set;
await act(() => {
nativeInputValue?.call(searchInput, "Two");
searchInput?.dispatchEvent(new Event("input", { bubbles: true }));
});
const filteredOptions = Array.from(
document.querySelectorAll<HTMLButtonElement>("[data-mobile-entity-picker-list] > button"),
);
expect(filteredOptions.map((option) => option.textContent)).toEqual([
"No project",
"Project Two",
]);
await act(() => {
searchInput?.dispatchEvent(new KeyboardEvent("keydown", { bubbles: true, key: "Enter" }));
});
expect(onChange).toHaveBeenCalledWith("project-2");
act(() => root.unmount());
});
it("does not open the popover when disabled", async () => {
const root = createRoot(container);
const onChange = vi.fn();
+14 -4
View File
@@ -16,6 +16,8 @@ interface InlineEntitySelectorProps {
options: InlineEntityOption[];
placeholder: string;
noneLabel: string;
/** Keep the no-selection action before the selected and recent choices. */
noneAtTop?: boolean;
/** Keep the no-selection action after the project choices. */
noneAtEnd?: boolean;
searchPlaceholder: string;
@@ -72,6 +74,7 @@ export const InlineEntitySelector = forwardRef<HTMLButtonElement, InlineEntitySe
options,
placeholder,
noneLabel,
noneAtTop = false,
noneAtEnd = false,
searchPlaceholder,
emptyMessage,
@@ -106,17 +109,19 @@ export const InlineEntitySelector = forwardRef<HTMLButtonElement, InlineEntitySe
const allOptions = useMemo<InlineEntityOption[]>(() => {
const baseOptions = [{ id: "", label: noneLabel, searchText: noneLabel }, ...options];
const ordered = orderItemsBySelectedAndRecent(baseOptions, value, recentOptionIds);
if (noneAtTop) return [baseOptions[0]!, ...ordered.filter((option) => option.id)];
return noneAtEnd ? [...ordered.filter((option) => option.id), baseOptions[0]!] : ordered;
}, [noneAtEnd, noneLabel, options, recentOptionIds, value]);
}, [noneAtEnd, noneAtTop, noneLabel, options, recentOptionIds, value]);
const filteredOptions = useMemo(() => {
const term = query.trim().toLowerCase();
if (!term) return allOptions;
return allOptions.filter((option) => {
if (noneAtTop && !option.id) return true;
const haystack = `${option.label} ${option.searchText ?? ""}`.toLowerCase();
return haystack.includes(term);
});
}, [allOptions, query]);
}, [allOptions, noneAtTop, query]);
const currentOption = options.find((option) => option.id === value) ?? null;
@@ -128,9 +133,14 @@ export const InlineEntitySelector = forwardRef<HTMLButtonElement, InlineEntitySe
useEffect(() => {
if (!open) return;
const firstSearchResultIndex = noneAtTop && query.trim()
? filteredOptions.findIndex((option) => option.id)
: -1;
const selectedIndex = filteredOptions.findIndex((option) => option.id === value);
setHighlightedIndexValue(selectedIndex >= 0 ? selectedIndex : 0);
}, [filteredOptions, open, setHighlightedIndexValue, value]);
setHighlightedIndexValue(
firstSearchResultIndex >= 0 ? firstSearchResultIndex : selectedIndex >= 0 ? selectedIndex : 0,
);
}, [filteredOptions, noneAtTop, open, query, setHighlightedIndexValue, value]);
const commitSelection = (index: number, moveNext: boolean) => {
const option = filteredOptions[index] ?? filteredOptions[0];
+20 -2
View File
@@ -199,13 +199,14 @@ vi.mock("./InlineEntitySelector", async () => {
placeholder?: string;
className?: string;
triggerDataSlot?: string;
noneAtTop?: boolean;
options?: { id: string; label: string }[];
onChange?: (id: string) => void;
renderTriggerValue?: (option: { id: string; label: string } | null) => ReactNode;
}
>(function InlineEntitySelectorMock({ value, placeholder, className, triggerDataSlot, renderTriggerValue, options = [], onChange }, ref) {
>(function InlineEntitySelectorMock({ value, placeholder, className, triggerDataSlot, noneAtTop, renderTriggerValue, options = [], onChange }, ref) {
return (
<button ref={ref} type="button" className={className} data-slot={triggerDataSlot} onClick={() => onChange?.(options[options.findIndex((option) => option.id === value) + 1]?.id ?? "")}>
<button ref={ref} type="button" className={className} data-slot={triggerDataSlot} data-none-at-top={noneAtTop || undefined} onClick={() => onChange?.(options[options.findIndex((option) => option.id === value) + 1]?.id ?? "")}>
{(renderTriggerValue?.(value ? { id: value, label: value } : null) ?? value) || placeholder}
</button>
);
@@ -453,6 +454,23 @@ describe("NewIssueDialog", () => {
act(() => next.root.unmount());
});
it("shows No project first and lets a selected project be cleared", async () => {
dialogState.newIssueDefaults = { projectId: "project-1" };
const { root } = renderDialog(container);
await waitForAssertion(() => expect(container.querySelector('[data-slot="new-issue-compact-control"]')?.textContent).toContain("project-1"));
const projectPicker = container.querySelector<HTMLButtonElement>('[data-slot="new-issue-compact-control"]')!;
expect(projectPicker.dataset.noneAtTop).toBe("true");
act(() => projectPicker.click());
await typeTextareaValue(container.querySelector<HTMLTextAreaElement>('textarea[aria-label="Describe a task…"]')!, "Create without a project");
act(() => container.querySelector<HTMLButtonElement>('[aria-label="Create task"]')!.click());
await waitForAssertion(() => expect(mockIssuesApi.create).toHaveBeenCalled());
expect(mockIssuesApi.create.mock.calls[0][1].projectId).toBeUndefined();
expect(getLastProjectId("company-1")).toBe("");
act(() => root.unmount());
});
it("submits remembered effort with the agent's default model", async () => {
mockAgentsApi.list.mockResolvedValue(defaultAgents.map((agent) => agent.id === "ceo"
? { ...agent, adapterConfig: { model: "claude-opus-5" } } : agent));
+1 -1
View File
@@ -1349,7 +1349,7 @@ export function NewIssueDialog() {
triggerDataSlot="new-issue-compact-control"
contentStyle={entityPickerViewportStyle}
noneLabel="No project"
noneAtEnd
noneAtTop
searchPlaceholder="Search projects..."
emptyMessage="No projects found."
onChange={handleProjectChange}