feat: rename task inline from the top bar via double-click (#1702)
* feat: rename task inline from the top bar via double-click Double-clicking the task title in the desktop top bar swaps it for an inline input; Enter commits the rename through the existing task update path, Escape or blur cancels. Archived tasks stay read-only. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * test: fix vi.fn generics in agent usage test for vitest 4 vi.fn dropped the two-type-argument form in the Vitest 4 upgrade; the old signature made mockResolvedValue infer never and fail typecheck. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * fix: ignore Enter during IME composition in topbar rename input Review follow-up: without the guard, the Enter that confirms an IME candidate committed the rename mid-typing. Mirrors the quick-chat tab rename input and the dialog default-action convention. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * fix: harden topbar rename commit path against IME 229 and mid-edit archive Independent-review follow-up: - also treat keyCode 229 as IME composition, matching the documented convention in dialog-default-action (some IMEs report the accepting Enter after isComposing flips false) - re-check isArchived on Enter so a task archived while the inline editor is open cannot be renamed from it Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * fix: make topbar rename title keyboard-operable Addresses PR #1702 review: the renameable title exposed role="link" with aria-disabled="false" but only a double-click handler. Add tabIndex, Enter to open the rename input, and focus restoration on keyboard exits. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> --------- Co-authored-by: Kandev Agent <agent@kandev.dev> Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -5,7 +5,7 @@ import { AgentUsageSection } from "@/components/settings/agent-usage-section";
|
||||
import type { AgentSubscriptionUsageResponse } from "@/lib/types/http";
|
||||
|
||||
const listAgentSubscriptionUsage = vi.hoisted(() =>
|
||||
vi.fn<[], Promise<AgentSubscriptionUsageResponse>>(),
|
||||
vi.fn<() => Promise<AgentSubscriptionUsageResponse>>(),
|
||||
);
|
||||
|
||||
vi.mock("@/lib/api", () => ({
|
||||
|
||||
@@ -0,0 +1,198 @@
|
||||
import { cleanup, fireEvent, render, screen } from "@testing-library/react";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { TaskTopBarTitle } from "./task-top-bar-title";
|
||||
|
||||
const mockRename = vi.hoisted(() => vi.fn(() => Promise.resolve()));
|
||||
|
||||
vi.mock("@kandev/ui/tooltip", () => ({
|
||||
Tooltip: ({ children }: { children: React.ReactNode }) => <>{children}</>,
|
||||
TooltipTrigger: ({ children }: { children: React.ReactNode }) => <>{children}</>,
|
||||
TooltipContent: ({ children }: { children: React.ReactNode }) => <>{children}</>,
|
||||
}));
|
||||
|
||||
vi.mock("@/hooks/use-task-actions", () => ({
|
||||
useTaskActions: () => ({ renameTaskById: mockRename }),
|
||||
}));
|
||||
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
mockRename.mockClear();
|
||||
});
|
||||
|
||||
function getTitle() {
|
||||
return screen.getByText("My task", { selector: '[aria-current="page"]' });
|
||||
}
|
||||
|
||||
function queryInput() {
|
||||
return screen.queryByTestId("task-title-rename-input");
|
||||
}
|
||||
|
||||
function startEditing() {
|
||||
fireEvent.doubleClick(getTitle());
|
||||
return screen.getByTestId("task-title-rename-input") as HTMLInputElement;
|
||||
}
|
||||
|
||||
describe("TaskTopBarTitle — idle state", () => {
|
||||
it("renders the title as the breadcrumb page when idle", () => {
|
||||
render(<TaskTopBarTitle taskId="task-1" taskTitle="My task" />);
|
||||
|
||||
expect(getTitle()).toBeTruthy();
|
||||
expect(queryInput()).toBeNull();
|
||||
// Not aria-disabled, so pointer-actionability checks treat it as interactive.
|
||||
expect(getTitle().getAttribute("aria-disabled")).toBe("false");
|
||||
// Keyboard-operable: reachable via Tab.
|
||||
expect(getTitle().getAttribute("tabindex")).toBe("0");
|
||||
});
|
||||
|
||||
it("keeps the breadcrumb aria-disabled and unfocusable when the task is archived", () => {
|
||||
render(<TaskTopBarTitle taskId="task-1" taskTitle="My task" isArchived />);
|
||||
|
||||
expect(getTitle().getAttribute("aria-disabled")).toBe("true");
|
||||
expect(getTitle().getAttribute("tabindex")).toBeNull();
|
||||
});
|
||||
|
||||
it("does not enter edit mode when the task is archived", () => {
|
||||
render(<TaskTopBarTitle taskId="task-1" taskTitle="My task" isArchived />);
|
||||
|
||||
fireEvent.doubleClick(getTitle());
|
||||
|
||||
expect(queryInput()).toBeNull();
|
||||
});
|
||||
|
||||
it("does not enter edit mode without a task id", () => {
|
||||
render(<TaskTopBarTitle taskTitle="My task" />);
|
||||
|
||||
fireEvent.doubleClick(getTitle());
|
||||
|
||||
expect(queryInput()).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("TaskTopBarTitle — entering edit mode", () => {
|
||||
it("swaps to an input pre-filled with the current title on double-click", () => {
|
||||
render(<TaskTopBarTitle taskId="task-1" taskTitle="My task" />);
|
||||
|
||||
const input = startEditing();
|
||||
|
||||
expect(input.value).toBe("My task");
|
||||
});
|
||||
|
||||
it("enters edit mode on Enter when the title is focused", () => {
|
||||
render(<TaskTopBarTitle taskId="task-1" taskTitle="My task" />);
|
||||
|
||||
fireEvent.keyDown(getTitle(), { key: "Enter" });
|
||||
|
||||
const input = screen.getByTestId("task-title-rename-input") as HTMLInputElement;
|
||||
expect(input.value).toBe("My task");
|
||||
});
|
||||
|
||||
it("does not enter edit mode on title Enter when the task is archived", () => {
|
||||
render(<TaskTopBarTitle taskId="task-1" taskTitle="My task" isArchived />);
|
||||
|
||||
fireEvent.keyDown(getTitle(), { key: "Enter" });
|
||||
|
||||
expect(queryInput()).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("TaskTopBarTitle — committing a rename", () => {
|
||||
it("renames on Enter with a changed value, trimming whitespace", () => {
|
||||
render(<TaskTopBarTitle taskId="task-1" taskTitle="My task" />);
|
||||
|
||||
const input = startEditing();
|
||||
fireEvent.change(input, { target: { value: " New title " } });
|
||||
fireEvent.keyDown(input, { key: "Enter" });
|
||||
|
||||
expect(mockRename).toHaveBeenCalledWith("task-1", "New title");
|
||||
expect(queryInput()).toBeNull();
|
||||
});
|
||||
|
||||
it("does not rename on Enter when the value is unchanged", () => {
|
||||
render(<TaskTopBarTitle taskId="task-1" taskTitle="My task" />);
|
||||
|
||||
const input = startEditing();
|
||||
fireEvent.keyDown(input, { key: "Enter" });
|
||||
|
||||
expect(mockRename).not.toHaveBeenCalled();
|
||||
expect(queryInput()).toBeNull();
|
||||
});
|
||||
|
||||
it("does not rename on Enter when the value is whitespace-only", () => {
|
||||
render(<TaskTopBarTitle taskId="task-1" taskTitle="My task" />);
|
||||
|
||||
const input = startEditing();
|
||||
fireEvent.change(input, { target: { value: " " } });
|
||||
fireEvent.keyDown(input, { key: "Enter" });
|
||||
|
||||
expect(mockRename).not.toHaveBeenCalled();
|
||||
expect(queryInput()).toBeNull();
|
||||
});
|
||||
|
||||
it("ignores Enter fired during IME composition", () => {
|
||||
render(<TaskTopBarTitle taskId="task-1" taskTitle="My task" />);
|
||||
|
||||
const input = startEditing();
|
||||
fireEvent.change(input, { target: { value: "New title" } });
|
||||
fireEvent.keyDown(input, { key: "Enter", isComposing: true });
|
||||
|
||||
expect(mockRename).not.toHaveBeenCalled();
|
||||
expect(queryInput()).not.toBeNull();
|
||||
});
|
||||
|
||||
it("ignores the IME-accepting Enter reported as keyCode 229", () => {
|
||||
render(<TaskTopBarTitle taskId="task-1" taskTitle="My task" />);
|
||||
|
||||
const input = startEditing();
|
||||
fireEvent.change(input, { target: { value: "New title" } });
|
||||
fireEvent.keyDown(input, { key: "Enter", keyCode: 229 });
|
||||
|
||||
expect(mockRename).not.toHaveBeenCalled();
|
||||
expect(queryInput()).not.toBeNull();
|
||||
});
|
||||
|
||||
it("does not rename on Enter when the task was archived mid-edit", () => {
|
||||
const { rerender } = render(<TaskTopBarTitle taskId="task-1" taskTitle="My task" />);
|
||||
|
||||
const input = startEditing();
|
||||
fireEvent.change(input, { target: { value: "New title" } });
|
||||
rerender(<TaskTopBarTitle taskId="task-1" taskTitle="My task" isArchived />);
|
||||
fireEvent.keyDown(input, { key: "Enter" });
|
||||
|
||||
expect(mockRename).not.toHaveBeenCalled();
|
||||
expect(queryInput()).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("TaskTopBarTitle — cancelling a rename", () => {
|
||||
it("cancels on Escape without renaming", () => {
|
||||
render(<TaskTopBarTitle taskId="task-1" taskTitle="My task" />);
|
||||
|
||||
const input = startEditing();
|
||||
fireEvent.change(input, { target: { value: "New title" } });
|
||||
fireEvent.keyDown(input, { key: "Escape" });
|
||||
|
||||
expect(mockRename).not.toHaveBeenCalled();
|
||||
expect(queryInput()).toBeNull();
|
||||
expect(getTitle()).toBeTruthy();
|
||||
});
|
||||
|
||||
it("cancels on blur without renaming", () => {
|
||||
render(<TaskTopBarTitle taskId="task-1" taskTitle="My task" />);
|
||||
|
||||
const input = startEditing();
|
||||
fireEvent.change(input, { target: { value: "New title" } });
|
||||
fireEvent.blur(input);
|
||||
|
||||
expect(mockRename).not.toHaveBeenCalled();
|
||||
expect(queryInput()).toBeNull();
|
||||
});
|
||||
|
||||
it("returns focus to the title after a keyboard exit", () => {
|
||||
render(<TaskTopBarTitle taskId="task-1" taskTitle="My task" />);
|
||||
|
||||
const input = startEditing();
|
||||
fireEvent.keyDown(input, { key: "Escape" });
|
||||
|
||||
expect(document.activeElement).toBe(getTitle());
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,119 @@
|
||||
"use client";
|
||||
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
import { Breadcrumb, BreadcrumbItem, BreadcrumbList, BreadcrumbPage } from "@kandev/ui/breadcrumb";
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from "@kandev/ui/tooltip";
|
||||
import { Input } from "@kandev/ui/input";
|
||||
import { useTaskActions } from "@/hooks/use-task-actions";
|
||||
|
||||
type TaskTopBarTitleProps = {
|
||||
taskId?: string | null;
|
||||
taskTitle?: string;
|
||||
isArchived?: boolean;
|
||||
};
|
||||
|
||||
export function TaskTopBarTitle({ taskId, taskTitle, isArchived }: TaskTopBarTitleProps) {
|
||||
const { renameTaskById } = useTaskActions();
|
||||
const [isEditing, setIsEditing] = useState(false);
|
||||
const [draft, setDraft] = useState("");
|
||||
const titleRef = useRef<HTMLSpanElement>(null);
|
||||
const restoreFocusRef = useRef(false);
|
||||
const canRename = Boolean(taskId) && !isArchived;
|
||||
|
||||
// Return focus to the title after a keyboard-driven exit (Enter/Escape) so
|
||||
// keyboard users don't lose their place; blur exits keep focus where the
|
||||
// user clicked.
|
||||
useEffect(() => {
|
||||
if (!isEditing && restoreFocusRef.current) {
|
||||
restoreFocusRef.current = false;
|
||||
titleRef.current?.focus();
|
||||
}
|
||||
}, [isEditing]);
|
||||
|
||||
const startEditing = useCallback(() => {
|
||||
if (!taskId || isArchived) return;
|
||||
setDraft(taskTitle ?? "");
|
||||
setIsEditing(true);
|
||||
}, [taskId, isArchived, taskTitle]);
|
||||
|
||||
const handleTitleKeyDown = useCallback(
|
||||
(e: React.KeyboardEvent<HTMLSpanElement>) => {
|
||||
if (e.key === "Enter") {
|
||||
e.preventDefault();
|
||||
startEditing();
|
||||
}
|
||||
},
|
||||
[startEditing],
|
||||
);
|
||||
|
||||
const handleCancel = useCallback(() => setIsEditing(false), []);
|
||||
|
||||
const handleKeyDown = useCallback(
|
||||
(e: React.KeyboardEvent<HTMLInputElement>) => {
|
||||
// IME composition uses Enter to confirm a candidate; let the IME handle
|
||||
// it instead of committing the rename. keyCode 229 covers IMEs that
|
||||
// report the accepting Enter after isComposing has flipped false.
|
||||
if (e.nativeEvent.isComposing || e.nativeEvent.keyCode === 229) return;
|
||||
if (e.key === "Enter") {
|
||||
e.preventDefault();
|
||||
const trimmed = draft.trim();
|
||||
if (taskId && !isArchived && trimmed && trimmed !== taskTitle) {
|
||||
renameTaskById(taskId, trimmed).catch((err) =>
|
||||
console.error("Failed to rename task:", err),
|
||||
);
|
||||
}
|
||||
restoreFocusRef.current = true;
|
||||
setIsEditing(false);
|
||||
} else if (e.key === "Escape") {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
restoreFocusRef.current = true;
|
||||
setIsEditing(false);
|
||||
}
|
||||
},
|
||||
[draft, taskId, isArchived, taskTitle, renameTaskById],
|
||||
);
|
||||
|
||||
if (isEditing) {
|
||||
return (
|
||||
<Input
|
||||
data-testid="task-title-rename-input"
|
||||
aria-label="Task title"
|
||||
autoFocus
|
||||
value={draft}
|
||||
onChange={(e) => setDraft(e.target.value)}
|
||||
onFocus={(e) => e.target.select()}
|
||||
onBlur={handleCancel}
|
||||
onKeyDown={handleKeyDown}
|
||||
className="h-7 w-72 max-w-full text-sm font-medium"
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Breadcrumb className="min-w-0 max-w-full">
|
||||
<BreadcrumbList className="min-w-0 max-w-full flex-nowrap text-sm">
|
||||
<BreadcrumbItem className="min-w-0 max-w-full">
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
{/* BreadcrumbPage defaults to aria-disabled="true"; when renameable,
|
||||
mark it enabled and make it keyboard-operable (tab + Enter) so
|
||||
AT and pointer-actionability checks see a working control. */}
|
||||
<BreadcrumbPage
|
||||
ref={titleRef}
|
||||
className="block max-w-full truncate rounded-sm font-medium outline-none focus-visible:ring-[2px] focus-visible:ring-ring/35"
|
||||
aria-disabled={!canRename}
|
||||
tabIndex={canRename ? 0 : undefined}
|
||||
onDoubleClick={startEditing}
|
||||
onKeyDown={canRename ? handleTitleKeyDown : undefined}
|
||||
>
|
||||
{taskTitle ?? "Task details"}
|
||||
</BreadcrumbPage>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>{taskTitle ?? "Task details"}</TooltipContent>
|
||||
</Tooltip>
|
||||
</BreadcrumbItem>
|
||||
</BreadcrumbList>
|
||||
</Breadcrumb>
|
||||
);
|
||||
}
|
||||
@@ -4,8 +4,8 @@ import { memo, type ReactNode } from "react";
|
||||
import Link from "@/components/routing/app-link";
|
||||
import { IconBug, IconCircleDot } from "@tabler/icons-react";
|
||||
import { Button } from "@kandev/ui/button";
|
||||
import { Breadcrumb, BreadcrumbItem, BreadcrumbList, BreadcrumbPage } from "@kandev/ui/breadcrumb";
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from "@kandev/ui/tooltip";
|
||||
import { TaskTopBarTitle } from "@/components/task/task-top-bar-title";
|
||||
import { EditorsMenu } from "@/components/task/editors-menu";
|
||||
import { LayoutPresetSelector } from "@/components/task/layout-preset-selector";
|
||||
import { DocumentControls } from "@/components/task/document/document-controls";
|
||||
@@ -151,20 +151,7 @@ function TopBarLeft({
|
||||
const showExecutorSettings = shouldShowExecutorEnvironmentControls(remoteExecutorType);
|
||||
return (
|
||||
<div className="flex min-w-0 max-w-[min(44rem,45vw)] items-center gap-2.5 overflow-hidden">
|
||||
<Breadcrumb className="min-w-0 max-w-full">
|
||||
<BreadcrumbList className="min-w-0 max-w-full flex-nowrap text-sm">
|
||||
<BreadcrumbItem className="min-w-0 max-w-full">
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<BreadcrumbPage className="block max-w-full truncate font-medium">
|
||||
{taskTitle ?? "Task details"}
|
||||
</BreadcrumbPage>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>{taskTitle ?? "Task details"}</TooltipContent>
|
||||
</Tooltip>
|
||||
</BreadcrumbItem>
|
||||
</BreadcrumbList>
|
||||
</Breadcrumb>
|
||||
<TaskTopBarTitle taskId={taskId} taskTitle={taskTitle} isArchived={isArchived} />
|
||||
|
||||
{!isArchived && showExecutorSettings && (
|
||||
<ExecutorSettingsButton taskId={taskId} sessionId={activeSessionId ?? null} />
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
import { test, expect } from "../../fixtures/test-base";
|
||||
import { SessionPage } from "../../pages/session-page";
|
||||
|
||||
test.describe("Task topbar inline rename", () => {
|
||||
test("renames the task by double-clicking the title and pressing Enter", async ({
|
||||
testPage,
|
||||
apiClient,
|
||||
seedData,
|
||||
}) => {
|
||||
test.setTimeout(90_000);
|
||||
|
||||
const task = await apiClient.createTaskWithAgent(
|
||||
seedData.workspaceId,
|
||||
"Topbar rename original",
|
||||
seedData.agentProfileId,
|
||||
{
|
||||
description: "/e2e:simple-message",
|
||||
workflow_id: seedData.workflowId,
|
||||
workflow_step_id: seedData.startStepId,
|
||||
repository_ids: [seedData.repositoryId],
|
||||
},
|
||||
);
|
||||
|
||||
await testPage.goto(`/t/${task.id}`);
|
||||
const session = new SessionPage(testPage);
|
||||
await session.waitForLoad();
|
||||
|
||||
const title = testPage.locator('[data-testid="task-topbar"] [aria-current="page"]');
|
||||
await expect(title).toHaveText("Topbar rename original", { timeout: 10_000 });
|
||||
|
||||
await title.dblclick();
|
||||
const input = testPage.getByTestId("task-title-rename-input");
|
||||
await expect(input).toBeVisible();
|
||||
await input.fill("Topbar rename updated");
|
||||
await input.press("Enter");
|
||||
|
||||
// Title re-renders from the store once the task.updated WS event lands.
|
||||
await expect(title).toHaveText("Topbar rename updated", { timeout: 10_000 });
|
||||
|
||||
// Escape cancels without renaming.
|
||||
await title.dblclick();
|
||||
await input.fill("Should not persist");
|
||||
await input.press("Escape");
|
||||
await expect(input).not.toBeVisible();
|
||||
await expect(title).toHaveText("Topbar rename updated");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user