mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-28 04:41:52 +01:00
fix(ui): restore wheel and touch scrolling in task selectors (#15374)
Restore wheel and touch scrolling in nested task selectors and keep mobile picker controls reachable above the keyboard. Stabilize the affected server route test harnesses for Vitest 5. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
88ff98b83d
commit
a7a2ed63a0
9 files changed
+230
-50
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import express from "express";
|
||||
import request from "supertest";
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
|
||||
import { vi } from "vitest";
|
||||
import type { ServerAdapterModule } from "../adapters/index.js";
|
||||
|
||||
@@ -60,6 +60,22 @@ function registerModuleMocks() {
|
||||
vi.doMock("../middleware/index.js", async () => vi.importActual("../middleware/index.js"));
|
||||
}
|
||||
|
||||
function resetAdapterMocks() {
|
||||
vi.resetAllMocks();
|
||||
mockAdapterPluginStore.listAdapterPlugins.mockReturnValue([]);
|
||||
mockAdapterPluginStore.addAdapterPlugin.mockResolvedValue(undefined);
|
||||
mockAdapterPluginStore.removeAdapterPlugin.mockReturnValue(false);
|
||||
mockAdapterPluginStore.getAdapterPluginByType.mockReturnValue(undefined);
|
||||
mockAdapterPluginStore.getAdapterPluginsDir.mockReturnValue("/tmp/paperclip-adapter-routes-test");
|
||||
mockAdapterPluginStore.getDisabledAdapterTypes.mockReturnValue([]);
|
||||
mockAdapterPluginStore.setAdapterDisabled.mockReturnValue(false);
|
||||
mockPluginLoader.buildExternalAdapters.mockResolvedValue([]);
|
||||
mockPluginLoader.loadExternalAdapterPackage.mockResolvedValue(null);
|
||||
mockPluginLoader.getUiParserSource.mockResolvedValue(null);
|
||||
mockPluginLoader.getOrExtractUiParserSource.mockResolvedValue(null);
|
||||
mockPluginLoader.reloadExternalAdapter.mockResolvedValue(null);
|
||||
}
|
||||
|
||||
function createApp(
|
||||
actorOverrides: Partial<Express.Request["actor"]> = {},
|
||||
options: Parameters<typeof adapterRoutes>[0] = {},
|
||||
@@ -83,28 +99,11 @@ function createApp(
|
||||
}
|
||||
|
||||
describe("adapter routes", () => {
|
||||
beforeEach(async () => {
|
||||
vi.resetModules();
|
||||
vi.doUnmock("node:child_process");
|
||||
vi.doUnmock("../adapters/registry.js");
|
||||
vi.doUnmock("../adapters/plugin-loader.js");
|
||||
vi.doUnmock("../services/adapter-plugin-store.js");
|
||||
vi.doUnmock("../routes/adapters.js");
|
||||
vi.doUnmock("../routes/authz.js");
|
||||
vi.doUnmock("../middleware/index.js");
|
||||
// Keep the route and middleware on one module graph so HttpError retains
|
||||
// its identity. Reset mock state and adapter overrides between tests.
|
||||
beforeAll(async () => {
|
||||
registerModuleMocks();
|
||||
mockAdapterPluginStore.listAdapterPlugins.mockReturnValue([]);
|
||||
mockAdapterPluginStore.addAdapterPlugin.mockResolvedValue(undefined);
|
||||
mockAdapterPluginStore.removeAdapterPlugin.mockReturnValue(false);
|
||||
mockAdapterPluginStore.getAdapterPluginByType.mockReturnValue(undefined);
|
||||
mockAdapterPluginStore.getAdapterPluginsDir.mockReturnValue("/tmp/paperclip-adapter-routes-test");
|
||||
mockAdapterPluginStore.getDisabledAdapterTypes.mockReturnValue([]);
|
||||
mockAdapterPluginStore.setAdapterDisabled.mockReturnValue(false);
|
||||
mockPluginLoader.buildExternalAdapters.mockResolvedValue([]);
|
||||
mockPluginLoader.loadExternalAdapterPackage.mockResolvedValue(null);
|
||||
mockPluginLoader.getUiParserSource.mockResolvedValue(null);
|
||||
mockPluginLoader.getOrExtractUiParserSource.mockResolvedValue(null);
|
||||
mockPluginLoader.reloadExternalAdapter.mockResolvedValue(null);
|
||||
resetAdapterMocks();
|
||||
const [registry, routes, middleware] = await Promise.all([
|
||||
vi.importActual<typeof import("../adapters/registry.js")>("../adapters/registry.js"),
|
||||
import("../routes/adapters.js"),
|
||||
@@ -117,6 +116,10 @@ describe("adapter routes", () => {
|
||||
setOverridePaused = registry.setOverridePaused;
|
||||
adapterRoutes = routes.adapterRoutes;
|
||||
errorHandler = middleware.errorHandler;
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
resetAdapterMocks();
|
||||
setOverridePaused("claude_local", false);
|
||||
unregisterServerAdapter("hermes_local");
|
||||
unregisterServerAdapter("claude_local");
|
||||
|
||||
@@ -162,17 +162,14 @@ describe("external object routes", () => {
|
||||
// first import transforms a large module graph. Under the loaded serial shard
|
||||
// (maxWorkers=1) that cold cost crossed the 5s testTimeout of the first test.
|
||||
// The hook has a 30s budget, so it absorbs the transform cost and every later
|
||||
// createApp() call hits the cached modules.
|
||||
// createApp() call hits the cached modules. Install mocks before warming the
|
||||
// graph and reset their state between tests instead of reloading the modules.
|
||||
beforeAll(async () => {
|
||||
registerRouteMocks();
|
||||
await createApp(boardActor());
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
vi.resetModules();
|
||||
vi.doUnmock("../routes/issues.js");
|
||||
vi.doUnmock("../services/index.js");
|
||||
vi.doUnmock("../services/external-objects.js");
|
||||
registerRouteMocks();
|
||||
vi.resetAllMocks();
|
||||
mockIssueService.getById.mockResolvedValue(makeIssue());
|
||||
mockIssueService.assertCheckoutOwner.mockResolvedValue({ adoptedFromRunId: null });
|
||||
|
||||
@@ -6,9 +6,7 @@ async function json(response: APIResponse) {
|
||||
return response.json();
|
||||
}
|
||||
|
||||
async function swipeToLastOption(page: Page, picker: Locator) {
|
||||
const list = picker.getByRole("listbox");
|
||||
const last = list.getByRole("option").last();
|
||||
async function swipeToLastOption(page: Page, picker: Locator, list = picker.getByRole("listbox"), last = list.getByRole("option").last()) {
|
||||
// The shared picker animates its height between views. Native touch
|
||||
// coordinates must use the settled sheet rather than its clipped first frame.
|
||||
await expect.poll(() => picker.evaluate((element) => {
|
||||
@@ -21,6 +19,7 @@ async function swipeToLastOption(page: Page, picker: Locator) {
|
||||
const bounds = (await picker.boundingBox())!;
|
||||
return bounds.y + bounds.height;
|
||||
}).toBeLessThanOrEqual(page.viewportSize()!.height);
|
||||
expect((await picker.boundingBox())!.y).toBeGreaterThanOrEqual(0);
|
||||
const session = await page.context().newCDPSession(page);
|
||||
try {
|
||||
expect(await list.evaluate((element) => element.scrollHeight > element.clientHeight)).toBe(true);
|
||||
@@ -57,7 +56,7 @@ async function swipeToLastOption(page: Page, picker: Locator) {
|
||||
|
||||
test.use({ viewport: { width: 390, height: 844 }, hasTouch: true, isMobile: true });
|
||||
|
||||
test("new-task assignee and model sheets scroll by touch and retain the selected values", async ({ page, request, browserName }, testInfo) => {
|
||||
test("new-task assignee, model, and project sheets scroll by touch and retain the selected values", async ({ page, request, browserName }, testInfo) => {
|
||||
test.skip(browserName !== "chromium", "Native touch drags use Chromium's input protocol.");
|
||||
const company = await json(await request.post("/api/companies", {
|
||||
data: { name: `Touch pickers ${randomUUID()}` },
|
||||
@@ -70,6 +69,9 @@ test("new-task assignee and model sheets scroll by touch and retain the selected
|
||||
runtimeConfig: { heartbeat: { enabled: false } },
|
||||
},
|
||||
}));
|
||||
await json(await request.post(`/api/companies/${company.id}/projects`, {
|
||||
data: { name: `Touch Project ${String(index).padStart(2, "0")}` },
|
||||
}));
|
||||
}
|
||||
// Keep the provider catalog deterministic; task UI, agents, and drafts are real.
|
||||
await page.route(`**/api/companies/${company.id}/adapters/codex_local/models*`, (route) => route.fulfill({
|
||||
@@ -93,11 +95,27 @@ test("new-task assignee and model sheets scroll by touch and retain the selected
|
||||
await expect(assigneeTrigger).toBeFocused();
|
||||
await modelTrigger.tap();
|
||||
const picker = page.getByRole("dialog", { name: "Select model and effort", exact: true });
|
||||
// The settings view must keep its controls stretched across the mobile sheet.
|
||||
await expect.poll(async () => {
|
||||
const sheet = (await picker.boundingBox())!;
|
||||
const control = (await picker.getByRole("button", { name: "Choose exact model" }).boundingBox())!;
|
||||
return control.width / sheet.width;
|
||||
}).toBeGreaterThan(0.8);
|
||||
// Short screens must also let a finger reach the settings below the fold.
|
||||
const effort = picker.getByRole("slider", { name: "Effort" });
|
||||
const effortBeforeScroll = await effort.inputValue();
|
||||
await page.setViewportSize({ width: 390, height: 200 });
|
||||
await swipeToLastOption(page, picker, picker.getByTestId("composer-run-settings-view"), effort);
|
||||
await expect(effort).toHaveValue(effortBeforeScroll);
|
||||
await page.screenshot({ path: testInfo.outputPath("settings-after-touch-scroll.png") });
|
||||
await page.setViewportSize({ width: 390, height: 844 });
|
||||
await page.getByRole("button", { name: "Choose exact model" }).tap();
|
||||
await page.screenshot({ path: testInfo.outputPath("model-before-keyboard.png") });
|
||||
// A reduced viewport exercises the space available when a phone keyboard opens.
|
||||
await page.setViewportSize({ width: 390, height: 430 });
|
||||
const lastModel = await swipeToLastOption(page, picker);
|
||||
await expect(lastModel).toContainText("Touch Model 24");
|
||||
await page.screenshot({ path: testInfo.outputPath("model-after-touch-scroll.png") });
|
||||
await lastModel.tap();
|
||||
await page.getByRole("button", { name: "Close picker" }).tap();
|
||||
await page.setViewportSize({ width: 390, height: 844 });
|
||||
@@ -105,6 +123,19 @@ test("new-task assignee and model sheets scroll by touch and retain the selected
|
||||
await expect(modelTrigger).toContainText("Touch Model 24");
|
||||
await expect(draft).toHaveText("Keep this touch selection draft");
|
||||
|
||||
const projectTrigger = page.getByRole("button", { name: "Project", exact: true });
|
||||
await projectTrigger.tap();
|
||||
const projectPicker = page.getByRole("dialog", { name: "Select project", exact: true });
|
||||
await page.setViewportSize({ width: 390, height: 430 });
|
||||
const projectList = projectPicker.locator("[data-mobile-entity-picker-list]");
|
||||
const lastProject = await swipeToLastOption(page, projectPicker, projectList, projectList.getByRole("button").filter({ hasText: "Touch Project 22" }));
|
||||
await page.screenshot({ path: testInfo.outputPath("project-after-touch-scroll.png") });
|
||||
await lastProject.tap();
|
||||
await expect(projectPicker).toBeHidden();
|
||||
await page.setViewportSize({ width: 390, height: 844 });
|
||||
await expect(page.locator('[data-slot="new-issue-compact-control"]').filter({ hasText: "Touch Project 22" })).toBeVisible();
|
||||
await expect(draft).toHaveText("Keep this touch selection draft");
|
||||
|
||||
// Closing the nested picker preserves the outer composer draft and choices.
|
||||
await modelTrigger.tap();
|
||||
await page.getByRole("button", { name: "Choose exact model" }).tap();
|
||||
@@ -112,7 +143,7 @@ test("new-task assignee and model sheets scroll by touch and retain the selected
|
||||
await expect(picker).toBeHidden();
|
||||
await expect(assigneeTrigger).toBeFocused();
|
||||
await expect(page.getByRole("button", { name: "Create task", exact: true })).toBeEnabled();
|
||||
await page.screenshot({ path: testInfo.outputPath("selected-mobile-assignee-and-model.png") });
|
||||
await page.screenshot({ path: testInfo.outputPath("selected-mobile-picker-values.png") });
|
||||
|
||||
// The desktop picker uses the same selected values and supports model search.
|
||||
await page.setViewportSize({ width: 1280, height: 900 });
|
||||
@@ -123,3 +154,64 @@ test("new-task assignee and model sheets scroll by touch and retain the selected
|
||||
await page.getByRole("button", { name: "Choose exact model" }).press("Escape");
|
||||
await expect(modelTrigger).toContainText("Touch Model 01");
|
||||
});
|
||||
|
||||
test.describe("desktop picker scrolling", () => {
|
||||
test.use({ viewport: { width: 1280, height: 900 }, hasTouch: false, isMobile: false });
|
||||
|
||||
test("mouse wheels scroll nested model, assignee, and project lists without losing the draft", async ({ page, request }) => {
|
||||
const company = await json(await request.post("/api/companies", {
|
||||
data: { name: `Wheel pickers ${randomUUID()}` },
|
||||
}));
|
||||
for (let index = 1; index <= 22; index += 1) {
|
||||
await json(await request.post(`/api/companies/${company.id}/agents`, {
|
||||
data: {
|
||||
name: `Wheel Agent ${String(index).padStart(2, "0")}`, role: "engineer",
|
||||
adapterType: "codex_local", adapterConfig: { model: "gpt-6-sol" },
|
||||
runtimeConfig: { heartbeat: { enabled: false } },
|
||||
},
|
||||
}));
|
||||
await json(await request.post(`/api/companies/${company.id}/projects`, {
|
||||
data: { name: `Wheel Project ${String(index).padStart(2, "0")}` },
|
||||
}));
|
||||
}
|
||||
await page.route(`**/api/companies/${company.id}/adapters/codex_local/models*`, (route) => route.fulfill({
|
||||
json: Array.from({ length: 24 }, (_, index) => ({
|
||||
id: `wheel-model-${String(index + 1).padStart(2, "0")}`,
|
||||
label: `Wheel Model ${String(index + 1).padStart(2, "0")}`,
|
||||
})),
|
||||
}));
|
||||
await page.goto(`/${company.issuePrefix}/dashboard`);
|
||||
await page.getByRole("button", { name: "New Task", exact: true }).click();
|
||||
const draft = page.getByRole("textbox", { name: "editable markdown" });
|
||||
await draft.fill("Keep this mouse wheel selection draft");
|
||||
|
||||
const wheelToBottom = async (list: Locator) => {
|
||||
await expect.poll(() => list.evaluate((element) => element.scrollHeight > element.clientHeight)).toBe(true);
|
||||
const before = await list.evaluate((element) => element.scrollTop);
|
||||
await list.hover();
|
||||
await page.mouse.wheel(0, 2000);
|
||||
await expect.poll(() => list.evaluate((element) => element.scrollTop)).toBeGreaterThan(before);
|
||||
};
|
||||
const assigneeTrigger = page.getByRole("button", { name: "Select assignee", exact: true });
|
||||
const modelTrigger = page.getByRole("button", { name: "Select model and effort", exact: true });
|
||||
await assigneeTrigger.click();
|
||||
await wheelToBottom(page.getByRole("listbox", { name: "Assignees", exact: true }));
|
||||
await page.getByRole("option").filter({ hasText: "Wheel Agent 22" }).click();
|
||||
await expect(assigneeTrigger).toContainText("Wheel Agent 22");
|
||||
|
||||
await modelTrigger.click();
|
||||
await page.getByRole("button", { name: "Choose exact model" }).click();
|
||||
await wheelToBottom(page.getByRole("listbox", { name: "Models", exact: true }));
|
||||
await page.getByRole("option").filter({ hasText: "Wheel Model 24" }).click();
|
||||
await page.getByRole("button", { name: "Choose exact model" }).press("Escape");
|
||||
await expect(modelTrigger).toContainText("Wheel Model 24");
|
||||
|
||||
await page.getByRole("button", { name: "Project", exact: true }).click();
|
||||
const projectPicker = page.getByRole("dialog", { name: "Select project", exact: true });
|
||||
await wheelToBottom(projectPicker.locator("[data-mobile-entity-picker-list]"));
|
||||
await projectPicker.getByRole("button").filter({ hasText: "Wheel Project 22" }).click();
|
||||
await expect(projectPicker).toBeHidden();
|
||||
await expect(page.locator('[data-slot="new-issue-compact-control"]').filter({ hasText: "Wheel Project 22" })).toBeVisible();
|
||||
await expect(draft).toHaveText("Keep this mouse wheel selection draft");
|
||||
});
|
||||
});
|
||||
@@ -33,9 +33,9 @@ describe("InlineEntitySelector", () => {
|
||||
document.body.innerHTML = "";
|
||||
});
|
||||
|
||||
it("allows touch scrolling in a mobile picker portalled outside a parent dialog", async () => {
|
||||
it.each([false, true])("allows wheel and touch scrolling outside a parent dialog (mobile: %s)", async (mobile) => {
|
||||
window.matchMedia = vi.fn().mockImplementation((query: string) => ({
|
||||
matches: query === "(max-width: 40rem)",
|
||||
matches: mobile && query === "(max-width: 40rem)",
|
||||
media: query,
|
||||
addEventListener: vi.fn(),
|
||||
removeEventListener: vi.fn(),
|
||||
@@ -56,7 +56,7 @@ describe("InlineEntitySelector", () => {
|
||||
onChange={vi.fn()}
|
||||
triggerTestId="nested-assignee-picker"
|
||||
openOnFocus={false}
|
||||
disablePortal
|
||||
modal
|
||||
/>
|
||||
</DialogContent>
|
||||
</Dialog>,
|
||||
@@ -78,6 +78,9 @@ describe("InlineEntitySelector", () => {
|
||||
clientHeight: { configurable: true, value: 200 },
|
||||
});
|
||||
const option = list.querySelector("button")!;
|
||||
const wheel = new WheelEvent("wheel", { bubbles: true, cancelable: true, deltaY: 100 });
|
||||
option.dispatchEvent(wheel);
|
||||
expect(wheel.defaultPrevented).toBe(false);
|
||||
const touch = (type: string, y: number) => {
|
||||
const event = new Event(type, { bubbles: true, cancelable: true });
|
||||
Object.defineProperties(event, {
|
||||
|
||||
@@ -40,6 +40,8 @@ interface InlineEntitySelectorProps {
|
||||
contentStyle?: CSSProperties;
|
||||
/** Heading for the large mobile selector modal. Defaults to the placeholder. */
|
||||
mobileTitle?: string;
|
||||
/** Own the scroll lock when this picker portals outside a parent dialog. */
|
||||
modal?: boolean;
|
||||
}
|
||||
|
||||
const EMPTY_RECENT_OPTION_IDS: string[] = [];
|
||||
@@ -86,6 +88,7 @@ export const InlineEntitySelector = forwardRef<HTMLButtonElement, InlineEntitySe
|
||||
triggerDataSlot,
|
||||
contentStyle,
|
||||
mobileTitle,
|
||||
modal = false,
|
||||
},
|
||||
ref,
|
||||
) {
|
||||
@@ -144,9 +147,9 @@ export const InlineEntitySelector = forwardRef<HTMLButtonElement, InlineEntitySe
|
||||
|
||||
return (
|
||||
<Popover
|
||||
// Mobile sheets portal outside their parent dialog. Give the sheet its
|
||||
// own scroll lock so the parent does not cancel touch drags in its list.
|
||||
modal={mobileSelectorModal}
|
||||
// Portalled mobile sheets and modal callers need their own scroll lock
|
||||
// so a parent dialog does not cancel wheel or touch events in the list.
|
||||
modal={mobileSelectorModal || modal}
|
||||
open={open}
|
||||
onOpenChange={(next) => {
|
||||
if (disabled) return;
|
||||
|
||||
@@ -1343,6 +1343,7 @@ export function NewIssueDialog() {
|
||||
recentOptionIds={recentProjectIds}
|
||||
placeholder="Project"
|
||||
mobileTitle="Select project"
|
||||
modal
|
||||
className="h-8 min-w-0 flex-1 gap-1.5 border-0 bg-transparent px-2 text-xs shadow-none hover:bg-accent focus-visible:bg-accent focus-visible:ring-0 sm:max-w-64 sm:flex-none"
|
||||
disabled={createIssue.isPending}
|
||||
triggerDataSlot="new-issue-compact-control"
|
||||
|
||||
@@ -9,6 +9,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { agentsApi } from "@/api/agents";
|
||||
import { ComposerRunSettingsPicker } from "./ComposerRunSettingsPicker";
|
||||
import { getLastComposerEffort, rememberComposerEffort } from "@/lib/recent-composer-effort";
|
||||
import { Dialog, DialogContent, DialogTitle } from "@/components/ui/dialog";
|
||||
|
||||
const agent = {
|
||||
id: "a1", companyId: "company-1", name: "Clippy",
|
||||
@@ -34,17 +35,18 @@ async function click(label: string) {
|
||||
await act(async () => { await new Promise((resolve) => setTimeout(resolve, 0)); });
|
||||
}
|
||||
|
||||
function render(onAssigneeChange: (value: string) => void, onSettingsChange: () => void, useCatalog = false, props: Partial<ComponentProps<typeof ComposerRunSettingsPicker>> = {}) {
|
||||
function render(onAssigneeChange: (value: string) => void, onSettingsChange: () => void, useCatalog = false, props: Partial<ComponentProps<typeof ComposerRunSettingsPicker>> = {}, insideDialog = false) {
|
||||
container = document.createElement("div");
|
||||
document.body.appendChild(container);
|
||||
root = createRoot(container);
|
||||
const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } });
|
||||
flushSync(() => root!.render(<QueryClientProvider client={queryClient}>
|
||||
const picker = <QueryClientProvider client={queryClient}>
|
||||
<ComposerRunSettingsPicker companyId="company-1" assigneeValue="agent:a1" currentAssigneeValue="agent:a1"
|
||||
options={options} agents={agents} settings={{ model: "gpt-6-sol", effort: "high", fast: true }}
|
||||
onAssigneeChange={onAssigneeChange} onSettingsChange={onSettingsChange}
|
||||
modelOptionsOverride={useCatalog ? undefined : []} {...props} />
|
||||
</QueryClientProvider>));
|
||||
</QueryClientProvider>;
|
||||
flushSync(() => root!.render(insideDialog ? <Dialog defaultOpen><DialogContent aria-describedby={undefined}><DialogTitle>New task</DialogTitle>{picker}</DialogContent></Dialog> : picker));
|
||||
}
|
||||
|
||||
beforeEach(() => localStorage.clear());
|
||||
@@ -57,6 +59,45 @@ afterEach(() => {
|
||||
});
|
||||
|
||||
describe("composer assignee picker", () => {
|
||||
it.each([
|
||||
{ mobile: false, view: "settings" as const },
|
||||
{ mobile: false, view: "models" as const },
|
||||
{ mobile: false, view: "agents" as const },
|
||||
{ mobile: true, view: "settings" as const },
|
||||
{ mobile: true, view: "models" as const },
|
||||
{ mobile: true, view: "agents" as const },
|
||||
])("allows wheel and touch scrolling in a nested $view picker (mobile: $mobile)", async ({ mobile, view }) => {
|
||||
render(vi.fn(), vi.fn(), false, { mobile, initialOpen: true, initialView: view }, true);
|
||||
await act(async () => { await new Promise((resolve) => setTimeout(resolve, 0)); });
|
||||
const list = document.querySelector<HTMLElement>(view === "settings"
|
||||
? '[data-testid="composer-run-settings-view"]'
|
||||
: `[role="listbox"][aria-label="${view === "models" ? "Models" : "Assignees"}"]`)!;
|
||||
expect(list).not.toBeNull();
|
||||
list.style.overflowY = "auto";
|
||||
Object.defineProperties(list, {
|
||||
scrollHeight: { configurable: true, value: 1000 },
|
||||
clientHeight: { configurable: true, value: 200 },
|
||||
});
|
||||
const option = list.querySelector("button")!;
|
||||
const wheel = new WheelEvent("wheel", { bubbles: true, cancelable: true, deltaY: 100 });
|
||||
option.dispatchEvent(wheel);
|
||||
expect(wheel.defaultPrevented).toBe(false);
|
||||
const touch = (type: string, y: number) => {
|
||||
const event = new Event(type, { bubbles: true, cancelable: true });
|
||||
Object.defineProperties(event, {
|
||||
touches: { value: [{ clientX: 100, clientY: y }] },
|
||||
changedTouches: { value: [{ clientX: 100, clientY: y }] },
|
||||
});
|
||||
option.dispatchEvent(event);
|
||||
return event;
|
||||
};
|
||||
touch("touchstart", 150);
|
||||
expect(touch("touchmove", 100).defaultPrevented).toBe(false);
|
||||
const outsideWheel = new WheelEvent("wheel", { bubbles: true, cancelable: true, deltaY: 100 });
|
||||
document.body.dispatchEvent(outsideWheel);
|
||||
expect(outsideWheel.defaultPrevented).toBe(true);
|
||||
});
|
||||
|
||||
it.each([
|
||||
{ adapterType: "claude_local", config: {}, label: "Default" },
|
||||
{ adapterType: "claude_local", config: { model: "claude-opus-5" }, label: "Claude Opus 5" },
|
||||
|
||||
@@ -5,6 +5,7 @@ import { aiRuntimeConnectionBindingSchema, type Agent, type IssueAssigneeAdapter
|
||||
import { agentsApi, type AdapterModel } from "@/api/agents";
|
||||
import { queryKeys } from "@/lib/queryKeys";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { useMobileEntityPickerViewportStyle } from "@/hooks/useMobileEntityPickerViewportStyle";
|
||||
import { getLastComposerEffort, rememberComposerEffort } from "@/lib/recent-composer-effort";
|
||||
import type { InlineEntityOption } from "@/components/InlineEntitySelector";
|
||||
import { Dialog, DialogClose, DialogContent, DialogTitle, DialogTrigger } from "@/components/ui/dialog";
|
||||
@@ -98,6 +99,7 @@ export function ComposerRunSettingsPicker({
|
||||
return () => query.removeEventListener("change", update);
|
||||
}, []);
|
||||
const mobile = mobileProp ?? narrow;
|
||||
const mobileViewportStyle = useMobileEntityPickerViewportStyle();
|
||||
const agentId = assigneeValue.startsWith("agent:") ? assigneeValue.slice(6) : "";
|
||||
const agent = agents.get(agentId);
|
||||
const modelSupported = supportsComposerModel(agent);
|
||||
@@ -205,7 +207,7 @@ export function ComposerRunSettingsPicker({
|
||||
</> : null}
|
||||
</div>;
|
||||
|
||||
const body = view === "settings" ? <div className="p-3">
|
||||
const body = view === "settings" ? <div className="min-h-0 overflow-y-auto overscroll-contain touch-pan-y p-3" data-testid="composer-run-settings-view">
|
||||
<div className="flex items-center gap-2">
|
||||
<button type="button" aria-label="Choose assignee" onClick={() => setView("agents")}
|
||||
className="flex min-w-0 flex-1 items-center gap-2 rounded-md px-1 py-1 text-left hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring">
|
||||
@@ -235,20 +237,20 @@ export function ComposerRunSettingsPicker({
|
||||
className="composer-run-effort-range mt-3 w-full" style={{ "--fill": `${effortIndex / choices.length * 100}%` } as CSSProperties} />
|
||||
</div> : null}
|
||||
</> : agent ? <div className="mt-3 rounded-md bg-muted/40 px-3 py-2 text-xs text-muted-foreground" data-testid="model-unavailable">{unavailableModelReason(agent)}</div> : null}
|
||||
</div> : view === "agents" ? <div className="p-2">
|
||||
</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); }
|
||||
}} 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 max-h-60 overflow-y-auto" 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">{filteredAgents.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>
|
||||
</div> : <div className="p-2">
|
||||
</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>
|
||||
<div className="mt-2 max-h-60 overflow-y-auto" role="listbox" aria-label="Models">
|
||||
<div className="mt-2 min-h-0 max-h-60 overflow-y-auto overscroll-contain touch-pan-y" role="listbox" aria-label="Models">
|
||||
{!query ? <button type="button" role="option" aria-selected={selected.model === null} onClick={() => chooseModel(null)} className="flex w-full items-center gap-2 rounded-md px-2.5 py-2 text-left hover:bg-accent"><span className="min-w-0 flex-1"><span className="block text-sm font-medium">Use agent default</span><span className="block truncate text-xs text-muted-foreground">{models.find((item) => item.id === configuredModel)?.label || configuredModel || "Default"}</span></span>{selected.model === null ? <Check className="composer-run-settings-accent size-4" /> : null}</button> : null}
|
||||
{filteredModels.map((item) => <button type="button" role="option" aria-selected={selected.model === item.id} key={item.id} onClick={() => chooseModel(item.id)} className="flex w-full items-center gap-3 rounded-md px-2.5 py-2 text-left text-sm transition-colors hover:bg-accent focus-visible:bg-accent focus-visible:outline-none"><span className="min-w-0 flex-1"><span className="block truncate font-medium">{item.label}</span><span className="block truncate font-mono text-xs text-muted-foreground">{item.id}</span></span>{item.detail || item.id === configuredModel ? <span className="shrink-0 text-xs text-muted-foreground">{item.detail ?? "Agent default"}</span> : null}{selected.model === item.id ? <Check className="composer-run-settings-accent size-4 shrink-0" /> : null}</button>)}
|
||||
{catalogPending ? <p className="px-2.5 py-2 text-xs text-muted-foreground">Loading models…</p> : null}
|
||||
@@ -259,6 +261,7 @@ export function ComposerRunSettingsPicker({
|
||||
</div>;
|
||||
|
||||
const onOpenChange = (next: boolean) => { setOpen(next); if (!next) { setView("settings"); setModelSearch(""); setAssigneeSearch(""); } };
|
||||
return mobile ? <Dialog open={open} onOpenChange={onOpenChange}>{triggers}<DialogContent aria-describedby={undefined} showCloseButton={false} className="composer-mobile-dialog top-(--pct-50) -translate-y-(--pct-50) gap-0 overflow-y-auto p-0" data-testid="composer-mobile-dialog"><DialogTitle className="sr-only">{view === "agents" ? "Select assignee" : "Select model and effort"}</DialogTitle><AnimatedBody>{body}</AnimatedBody></DialogContent></Dialog>
|
||||
: <Popover open={open} onOpenChange={onOpenChange}><PopoverAnchor asChild>{triggers}</PopoverAnchor><PopoverContent side="top" align="end" sideOffset={8} className="w-80 max-w-full p-0 shadow-sm" data-testid="composer-model-popover"><AnimatedBody>{body}</AnimatedBody></PopoverContent></Popover>;
|
||||
// The desktop portal needs its own scroll lock inside the new-task dialog.
|
||||
return mobile ? <Dialog open={open} onOpenChange={onOpenChange}>{triggers}<DialogContent aria-describedby={undefined} showCloseButton={false} style={mobileViewportStyle} className="composer-mobile-dialog gap-0 overflow-hidden p-0" data-testid="composer-mobile-dialog"><DialogTitle className="sr-only">{view === "agents" ? "Select assignee" : "Select model and effort"}</DialogTitle><AnimatedBody>{body}</AnimatedBody></DialogContent></Dialog>
|
||||
: <Popover modal open={open} onOpenChange={onOpenChange}><PopoverAnchor asChild>{triggers}</PopoverAnchor><PopoverContent side="top" align="end" sideOffset={8} className="w-80 max-w-full p-0 shadow-sm" data-testid="composer-model-popover"><AnimatedBody>{body}</AnimatedBody></PopoverContent></Popover>;
|
||||
}
|
||||
@@ -29,7 +29,44 @@
|
||||
.composer-run-effort-range:focus-visible { outline: calc(var(--spacing) * 0.5) solid var(--ring); outline-offset: calc(var(--spacing) * 0.5); }
|
||||
.composer-run-settings-accent { color: var(--tc-mode-ask); }
|
||||
.composer-run-settings-height { overflow: hidden; transition: height var(--motion-duration-base) var(--motion-ease-out); }
|
||||
.composer-mobile-dialog { width: calc(100vw - var(--spacing) * 4); max-width: calc(var(--spacing) * 96); max-height: calc(100dvh - var(--spacing) * 8); }
|
||||
.composer-mobile-dialog {
|
||||
top: max(calc(var(--spacing) * 4), env(safe-area-inset-top));
|
||||
width: calc(100vw - var(--spacing) * 4);
|
||||
max-width: calc(var(--spacing) * 96);
|
||||
max-height: calc(
|
||||
var(--mobile-entity-picker-visual-viewport-height)
|
||||
- max(calc(var(--spacing) * 4), env(safe-area-inset-top))
|
||||
- max(calc(var(--spacing) * 4), env(safe-area-inset-bottom))
|
||||
);
|
||||
animation: none;
|
||||
}
|
||||
|
||||
/* Let the live viewport constrain the list; a measured animation height would
|
||||
keep it clipped when the software keyboard opens or the picker view changes. */
|
||||
.composer-mobile-dialog .composer-run-settings-height {
|
||||
display: flex;
|
||||
height: auto !important;
|
||||
min-height: 0;
|
||||
max-height: inherit;
|
||||
}
|
||||
|
||||
.composer-mobile-dialog .composer-run-settings-height > div {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.composer-mobile-dialog .composer-run-settings-list-view {
|
||||
display: flex;
|
||||
min-height: 0;
|
||||
width: 100%;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.composer-mobile-dialog .composer-run-settings-list-view > :not([role="listbox"]) {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.composer-run-settings-height { transition: none; }
|
||||
|
||||
Reference in new issue
Block a user