fix(webui): preserve picker compatibility and column keyboard navigation
This commit is contained in:
1 parent
cc5f2a84d3
commit
f78a0994c8
6 files changed
+57
-18
No files matched your search
+15
-3
@@ -293,9 +293,21 @@ or a result you must retain.
|
||||
|
||||
Use the workspace picker to browse folders on the connected nanobot host, enter
|
||||
an absolute path, or return to recent and starred projects; favorites persist
|
||||
across gateway restarts. Tab completes paths and Shift+wheel scrolls directory
|
||||
columns.
|
||||
Project paths refer to the gateway machine, not the browser's filesystem.
|
||||
across gateway restarts. The title identifies the host. Project paths refer to
|
||||
that machine, not the browser's filesystem.
|
||||
|
||||
Use the breadcrumbs, Back, Forward, and Parent folder controls to navigate.
|
||||
**Filter this folder** only filters the current directory. **Edit path** (or
|
||||
**Cmd/Ctrl+Shift+G**) accepts a host path; Tab completes it and Enter opens it.
|
||||
Browsing does not change the workspace until you choose **Select folder**.
|
||||
**Cancel** leaves the current workspace unchanged. Desktop uses directory
|
||||
columns with Shift+wheel horizontal scrolling; narrow screens show one folder
|
||||
at a time, with favorites and recent projects under **Saved locations**.
|
||||
|
||||
On a compatible host without the optional directory-browser capabilities,
|
||||
manual path entry remains available. Browse and favorite requests are not sent
|
||||
to that host. The gateway still validates the selected workspace and owns its
|
||||
access policy.
|
||||
|
||||
Selecting a project does not replace the configured agent workspace. The two
|
||||
paths have different responsibilities:
|
||||
|
||||
@@ -3682,6 +3682,9 @@ def test_workspace_payload_separates_remote_project_selection_from_full_access(
|
||||
controls = json.loads(response.body.decode())["controls"]
|
||||
assert controls["can_change_project"] is True
|
||||
assert controls["can_use_full_access"] is can_use_full_access
|
||||
assert controls["can_browse_directories"] is True
|
||||
assert controls["can_resolve_project"] is True
|
||||
assert controls["can_manage_favorites"] is True
|
||||
|
||||
|
||||
def test_local_browser_request_requires_loopback_host_and_forwarded_origin() -> None:
|
||||
|
||||
@@ -32,7 +32,7 @@ function WorkspaceFavoriteButton({ path, pinned, busy, onToggle }: {
|
||||
}
|
||||
|
||||
type PickerOption = ProjectDirectory & { kind: "directory" | "manual" };
|
||||
type PickerColumn = { path: string; options: PickerOption[]; selectedPath: string | null; hidden: boolean };
|
||||
type PickerColumn = { path: string; parent: string | null; options: PickerOption[]; selectedPath: string | null; hidden: boolean };
|
||||
|
||||
function WorkspacePickerTooltip({ label, children }: { label: string; children: ReactElement }) {
|
||||
return (
|
||||
@@ -434,7 +434,7 @@ export function WorkspaceProjectPicker({ isHero, disabled, scope, defaultScope,
|
||||
if (!canBrowse) { void chooseProject(project.path, project.name); return; }
|
||||
navigate(project.path);
|
||||
}
|
||||
const columns: PickerColumn[] = [...previousColumns, { path: directory?.path ?? requestedPath, options, selectedPath: null, hidden: showHidden }];
|
||||
const columns: PickerColumn[] = [...previousColumns, { path: directory?.path ?? requestedPath, parent: directory?.parent ?? null, options, selectedPath: null, hidden: showHidden }];
|
||||
const activeOptions = columns[activeColumn]?.options ?? options;
|
||||
const activeOption = Math.min(activeIndex, Math.max(activeOptions.length - 1, 0));
|
||||
const selectionPath = canBrowse ? (!loading && directory && !directory.partial ? directory.path : null) : (pathDraft.trim() ? absoluteDraft ? pathDraft.trim() : null : scope?.project_path ?? defaultScope?.project_path);
|
||||
@@ -464,10 +464,9 @@ export function WorkspaceProjectPicker({ isHero, disabled, scope, defaultScope,
|
||||
async function completePath(keepEditing = true) {
|
||||
if (!absoluteDraft) { setPathError(t("workspace.dialog.absolutePathRequired")); return; }
|
||||
const request = workspacePathCompletionQuery(pathDraft) ?? { path: basePath, query: "" };
|
||||
// Complete an exact address before descending into its implicitly active child.
|
||||
const completingAddress = absoluteDraft && !!request.query && !highlightActive;
|
||||
const option = activeOptions[activeOption];
|
||||
if (highlightActive && option && option.kind !== "manual" && !completingAddress) { navigate(option.path, undefined, keepEditing); return; }
|
||||
// Only an explicit keyboard selection may enter a child before resolving the address.
|
||||
if (highlightActive && option && option.kind !== "manual") { navigate(option.path, undefined, keepEditing); return; }
|
||||
if (!directoryCache || !canBrowse) return;
|
||||
const id = ++completionRequest.current;
|
||||
const session = pickerSession.current;
|
||||
@@ -604,7 +603,7 @@ export function WorkspaceProjectPicker({ isHero, disabled, scope, defaultScope,
|
||||
setActiveIndex(event.key === "Home" ? 0 : event.key === "End" ? count - 1 : highlightActive ? (activeIndex + (event.key === "ArrowDown" ? 1 : -1) + count) % count : event.key === "ArrowDown" ? 0 : count - 1);
|
||||
} else if (count && (event.key === "Enter" || event.key === "ArrowRight")) {
|
||||
event.preventDefault(); activate(column.options[Math.min(activeIndex, count - 1)], columnIndex);
|
||||
} else if (event.key === "ArrowLeft" && parentPath) { event.preventDefault(); navigate(parentPath); }
|
||||
} else if (event.key === "ArrowLeft" && column.parent) { event.preventDefault(); navigate(column.parent); }
|
||||
}}
|
||||
renderOption={(option, index) => <div role="presentation" className="workspace-picker-row relative" data-keyboard-active={highlightActive && columnIndex === activeColumn && index === activeOption ? "" : undefined}>
|
||||
<button id={`${optionsId}-${columnIndex}-${index}`} type="button" role="option" tabIndex={-1} aria-label={option.path} aria-selected={sameWorkspacePath(column.selectedPath, option.path)} aria-posinset={index + 1} aria-setsize={column.options.length} disabled={pickingFolder}
|
||||
|
||||
@@ -1161,8 +1161,9 @@ describe("App layout", () => {
|
||||
access_mode: "restricted",
|
||||
restrict_to_workspace: true,
|
||||
},
|
||||
controls: { can_change_project: true, can_use_full_access: true },
|
||||
controls: { can_change_project: true, can_use_full_access: true, can_browse_directories: true, can_resolve_project: true },
|
||||
},
|
||||
[directoryUrl("C:\\workspace")]: directory("C:\\workspace"),
|
||||
[directoryUrl("C:\\workspace\\")]: directory("C:\\workspace"),
|
||||
[directoryUrl(projectPath)]: directory(projectPath),
|
||||
[directoryUrl(`${projectPath}\\`)]: directory(projectPath),
|
||||
@@ -1172,6 +1173,7 @@ describe("App layout", () => {
|
||||
|
||||
await waitFor(() => expect(connectSpy).toHaveBeenCalled());
|
||||
fireEvent.click(await screen.findByRole("button", { name: "Switch working directory" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Edit path" }));
|
||||
fireEvent.change(await screen.findByRole("combobox"), {
|
||||
target: { value: projectPath },
|
||||
});
|
||||
@@ -1191,6 +1193,7 @@ describe("App layout", () => {
|
||||
"The gateway rejected this project or access mode. Choose an existing project or a different access mode, then try again.",
|
||||
);
|
||||
fireEvent.click(projectButton);
|
||||
fireEvent.click(screen.getByRole("button", { name: "Edit path" }));
|
||||
const pathInput = await screen.findByRole("combobox");
|
||||
expect(pathInput).toHaveValue(`${projectPath}\\`);
|
||||
expect(pathInput).toHaveAttribute("aria-invalid", "true");
|
||||
|
||||
@@ -1490,7 +1490,7 @@ describe("ThreadComposer", () => {
|
||||
}}
|
||||
workspaceDefaultScope={defaultScope}
|
||||
{...workspacePickerProps(defaultScope)}
|
||||
workspaceControls={{ can_change_project: true, can_use_full_access: true }}
|
||||
workspaceControls={{ can_change_project: true, can_use_full_access: true, can_browse_directories: true, can_resolve_project: true }}
|
||||
onWorkspaceScopeChange={onWorkspaceScopeChange}
|
||||
/>,
|
||||
);
|
||||
@@ -1500,14 +1500,15 @@ describe("ThreadComposer", () => {
|
||||
expect(await screen.findByRole("button", { name: "/Users/test/.nanobot/workspace" })).toBeInTheDocument();
|
||||
expect(screen.getByRole("dialog")).toBeInTheDocument();
|
||||
|
||||
await user.click(screen.getByRole("button", { name: "Edit path" }));
|
||||
const input = screen.getByRole("combobox");
|
||||
fireEvent.change(input, { target: { value: "relative/project" } });
|
||||
expect(screen.queryByRole("option", { name: "relative/project" })).not.toBeInTheDocument();
|
||||
expect(onWorkspaceScopeChange).not.toHaveBeenCalled();
|
||||
|
||||
fireEvent.change(input, { target: { value: "/Users/test/project-alpha" } });
|
||||
await waitFor(() => expect(screen.getByRole("button", { name: "Select" })).toBeEnabled());
|
||||
await user.click(screen.getByRole("button", { name: "Select" }));
|
||||
await waitFor(() => expect(screen.getByRole("button", { name: "Select folder" })).toBeEnabled());
|
||||
await user.click(screen.getByRole("button", { name: "Select folder" }));
|
||||
|
||||
expect(onWorkspaceScopeChange).toHaveBeenCalledWith(expect.objectContaining({
|
||||
project_path: "/Users/test/project-alpha",
|
||||
@@ -1517,10 +1518,11 @@ describe("ThreadComposer", () => {
|
||||
}));
|
||||
|
||||
await user.click(screen.getByRole("button", { name: "Switch working directory" }));
|
||||
await user.click(screen.getByRole("button", { name: "Edit path" }));
|
||||
const reopenedInput = await screen.findByRole("combobox");
|
||||
fireEvent.change(reopenedInput, { target: { value: "~/Pictures/Photos" } });
|
||||
await waitFor(() => expect(screen.getByRole("button", { name: "Select" })).toBeEnabled());
|
||||
await user.click(screen.getByRole("button", { name: "Select" }));
|
||||
await waitFor(() => expect(screen.getByRole("button", { name: "Select folder" })).toBeEnabled());
|
||||
await user.click(screen.getByRole("button", { name: "Select folder" }));
|
||||
|
||||
expect(onWorkspaceScopeChange).toHaveBeenLastCalledWith(expect.objectContaining({
|
||||
project_path: "/Users/test/Pictures/Photos",
|
||||
@@ -1561,7 +1563,7 @@ describe("ThreadComposer", () => {
|
||||
await user.click(screen.getByRole("button", { name: "Switch working directory" }));
|
||||
|
||||
fireEvent.change(await screen.findByRole("combobox"), { target: { value: selectedPath } });
|
||||
await waitFor(() => expect(screen.getByRole("button", { name: "Select" })).toBeEnabled());
|
||||
await waitFor(() => expect(screen.getByRole("button", { name: "Select folder" })).toBeEnabled());
|
||||
fireEvent.keyDown(screen.getByRole("combobox"), { key: "Enter" });
|
||||
await waitFor(() => expect(onWorkspaceScopeChange).toHaveBeenCalledWith(expect.objectContaining({ project_path: selectedPath })));
|
||||
});
|
||||
@@ -1662,6 +1664,8 @@ describe("ThreadComposer", () => {
|
||||
workspaceControls={{
|
||||
can_change_project: true,
|
||||
can_use_full_access: true,
|
||||
can_browse_directories: true,
|
||||
can_resolve_project: true,
|
||||
}}
|
||||
onBrowseWorkspaceDirectories={onBrowseWorkspaceDirectories}
|
||||
onResolveWorkspaceProject={onResolveWorkspaceProject}
|
||||
@@ -1717,8 +1721,8 @@ describe("ThreadComposer", () => {
|
||||
fireEvent.change(screen.getByRole("combobox"), {
|
||||
target: { value: "/srv/nas-project" },
|
||||
});
|
||||
await waitFor(() => expect(screen.getByRole("button", { name: "Select" })).toBeEnabled());
|
||||
await user.click(screen.getByRole("button", { name: "Select" }));
|
||||
await waitFor(() => expect(screen.getByRole("button", { name: "Select folder" })).toBeEnabled());
|
||||
await user.click(screen.getByRole("button", { name: "Select folder" }));
|
||||
|
||||
expect(onWorkspaceScopeChange).toHaveBeenCalledWith(expect.objectContaining({
|
||||
project_path: "/srv/nas-project",
|
||||
|
||||
@@ -509,6 +509,24 @@ describe("Workspace project picker", () => {
|
||||
expect(input).toBeDisabled();
|
||||
expect(screen.getByRole("combobox")).toHaveValue("/srv/workspace/");
|
||||
});
|
||||
it("moves to the focused column's parent with the left arrow", async () => {
|
||||
const user = userEvent.setup();
|
||||
const browse = vi.fn((raw: string) => {
|
||||
const path = raw.replace(/\/$/, "");
|
||||
return Promise.resolve({ ...directory, path, parent: path.slice(0, path.lastIndexOf("/")) || "/",
|
||||
entries: [{ name: "child", path: `${path}/child` }] });
|
||||
});
|
||||
render(<WorkspaceProjectPicker isHero scope={scope} defaultScope={scope} controls={catalog.controls} onBrowseDirectories={browse} onChange={vi.fn()} />);
|
||||
await user.click(screen.getByRole("button", { name: "Switch working directory" }));
|
||||
await user.click(await screen.findByRole("option", { name: "/srv/workspace/child" }));
|
||||
await user.click(await screen.findByRole("option", { name: "/srv/workspace/child/child" }));
|
||||
const ancestor = screen.getByRole("listbox", { name: "/srv/workspace", exact: true });
|
||||
act(() => ancestor.focus());
|
||||
await user.keyboard("{ArrowLeft}");
|
||||
await screen.findByRole("listbox", { name: "/srv", exact: true });
|
||||
expect(screen.getAllByRole("listbox")).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("keeps ancestor columns and replaces descendants when another folder is opened", async () => {
|
||||
const user = userEvent.setup();
|
||||
const onChange = vi.fn();
|
||||
|
||||
Reference in new issue
Block a user