From ee3c728b956817af34a480f7d7cca115250c6c65 Mon Sep 17 00:00:00 2001 From: Dotta <34892728+cryppadotta@users.noreply.github.com> Date: Tue, 6 Oct 2026 16:04:08 -0500 Subject: [PATCH] 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 --- .../components/InlineEntitySelector.test.tsx | 61 +++++++++++++++++++ ui/src/components/InlineEntitySelector.tsx | 18 ++++-- ui/src/components/NewIssueDialog.test.tsx | 22 ++++++- ui/src/components/NewIssueDialog.tsx | 2 +- 4 files changed, 96 insertions(+), 7 deletions(-) diff --git a/ui/src/components/InlineEntitySelector.test.tsx b/ui/src/components/InlineEntitySelector.test.tsx index 674a138d98d..c831fc1d43d 100644 --- a/ui/src/components/InlineEntitySelector.test.tsx +++ b/ui/src/components/InlineEntitySelector.test.tsx @@ -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( + , + ); + }); + + const trigger = container.querySelector("button") as HTMLButtonElement; + await act(() => trigger.click()); + + const options = Array.from( + document.querySelectorAll("[data-mobile-entity-picker-list] > button"), + ); + expect(options.map((option) => option.textContent)).toEqual([ + "No project", + "Project One", + "Project Two", + ]); + + const searchInput = document.querySelector('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("[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(); diff --git a/ui/src/components/InlineEntitySelector.tsx b/ui/src/components/InlineEntitySelector.tsx index c4f03356e03..8fccd9c3272 100644 --- a/ui/src/components/InlineEntitySelector.tsx +++ b/ui/src/components/InlineEntitySelector.tsx @@ -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(() => { 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 { 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]; diff --git a/ui/src/components/NewIssueDialog.test.tsx b/ui/src/components/NewIssueDialog.test.tsx index b92e834bf30..a203a293e84 100644 --- a/ui/src/components/NewIssueDialog.test.tsx +++ b/ui/src/components/NewIssueDialog.test.tsx @@ -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 ( - ); @@ -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('[data-slot="new-issue-compact-control"]')!; + expect(projectPicker.dataset.noneAtTop).toBe("true"); + act(() => projectPicker.click()); + + await typeTextareaValue(container.querySelector('textarea[aria-label="Describe a task…"]')!, "Create without a project"); + act(() => container.querySelector('[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)); diff --git a/ui/src/components/NewIssueDialog.tsx b/ui/src/components/NewIssueDialog.tsx index 0a18a570121..9967daeea83 100644 --- a/ui/src/components/NewIssueDialog.tsx +++ b/ui/src/components/NewIssueDialog.tsx @@ -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}