Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions chatbot/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2130,7 +2130,7 @@ export default function App() {
e.target.value = "";
}}
/>
{chat.executors.length > 1 && !pinnedExecutor ? (
{chat.executors.length > 1 ? (
<PermissionPicker
label="CLI"
options={chat.executors.map((executor) => {
Expand All @@ -2142,7 +2142,9 @@ export default function App() {
: null,
};
})}
value={chat.executor}
value={pinnedExecutor?.id || chat.executor}
disabled={Boolean(pinnedExecutor)}
title={pinnedExecutor ? "当前对话已绑定该 CLI,切换请新建对话" : undefined}
onSelect={(id) => {
chat.setExecutor(id);
input.current?.focus();
Expand Down
14 changes: 9 additions & 5 deletions chatbot/src/PermissionPicker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function rememberApprovalMode(userId, value) {
}

// `glyph` is a rendered brand mark. Options that only set `icon` keep the Harness icon.
export default function PermissionPicker({ value, onSelect, open, onOpenChange, label = "操作确认方式", icon, options = modes }) {
export default function PermissionPicker({ value, onSelect, open, onOpenChange, label = "操作确认方式", icon, options = modes, disabled = false, title }) {
const trigger = useRef(null);
const panel = useRef(null);
const initialFocus = useRef(null);
Expand Down Expand Up @@ -136,7 +136,7 @@ export default function PermissionPicker({ value, onSelect, open, onOpenChange,
close(true);
}
function keyDown(event) {
if (event.isComposing || event.nativeEvent?.isComposing) return;
if (disabled || event.isComposing || event.nativeEvent?.isComposing) return;
if (event.key === "Escape") {
event.preventDefault();
event.stopPropagation();
Expand Down Expand Up @@ -169,10 +169,14 @@ export default function PermissionPicker({ value, onSelect, open, onOpenChange,
className="permission-selector"
data-tone={current.tone}
aria-label={label}
aria-haspopup="menu"
aria-expanded={open}
disabled={disabled}
title={title}
aria-haspopup={disabled ? undefined : "menu"}
aria-expanded={disabled ? false : open}
aria-controls={identity}
onClick={() => onOpenChange(!open)}
onClick={() => {
if (!disabled) onOpenChange(!open);
}}
onKeyDown={(event) => {
if (["ArrowDown", "ArrowUp", "Home", "End"].includes(event.key)) {
if (open && presence.mounted) keyDown(event);
Expand Down
5 changes: 5 additions & 0 deletions chatbot/src/permission-picker.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
min-width: 0;
}

.chat-shell button.permission-selector:disabled {
cursor: default;
opacity: 1;
}

/* The portal defines its own colors outside the workbench's theme scope. */
.permission-menu {
--permission-surface: #fff;
Expand Down
24 changes: 24 additions & 0 deletions chatbot/tests/pickers-and-activity.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,30 @@ describe("pickers and activity", () => {
expect(selectPermission).toHaveBeenCalledWith("auto");
});

test("shows a locked CLI as a disabled, readable selector", async () => {
const onOpenChange = vi.fn();
const onSelect = vi.fn();
render(
<PermissionPicker
label="CLI"
options={[{ id: "codex", label: "Codex", icon: "terminal" }]}
value="codex"
disabled
title="当前对话已绑定该 CLI,切换请新建对话"
open={false}
onOpenChange={onOpenChange}
onSelect={onSelect}
/>,
);
const selector = screen.getByRole("button", { name: "CLI" });
expect(selector).toBeDisabled();
expect(selector).toHaveAttribute("title", "当前对话已绑定该 CLI,切换请新建对话");
await userEvent.click(selector);
expect(onOpenChange).not.toHaveBeenCalled();
expect(onSelect).not.toHaveBeenCalled();
expect(document.querySelector(".permission-menu")).not.toBeInTheDocument();
});

test("remembers the approval mode and ignores unknown values", () => {
expect(storedApprovalMode(1)).toBe("confirm");
rememberApprovalMode(1, "assisted");
Expand Down