refactor: use confirmDialog and unique draft agent IDs

This commit is contained in:
Mohamed Boudra
2026-03-04 15:28:55 +07:00
parent f47ea7afe5
commit 430ad54d77
5 changed files with 58 additions and 48 deletions
@@ -1,8 +1,30 @@
import { describe, expect, it } from "vitest";
import { canToggleFileExplorerShortcut } from "./keyboard-shortcut-routing";
import {
canToggleFileExplorerShortcut,
resolveSelectedOrRouteAgentKey,
} from "./keyboard-shortcut-routing";
describe("keyboard-shortcut-routing", () => {
describe("resolveSelectedOrRouteAgentKey", () => {
it("returns selected agent key when provided", () => {
const key = resolveSelectedOrRouteAgentKey({
selectedAgentId: "server-1:agent-1",
pathname: "/h/server-1/workspace/workspace-1/tab/draft_123",
});
expect(key).toBe("server-1:agent-1");
});
it("maps workspace draft tabs to the draft tab id key", () => {
const key = resolveSelectedOrRouteAgentKey({
pathname: "/h/server-1/workspace/workspace-1/tab/draft_123",
});
expect(key).toBe("server-1:draft_123");
});
});
describe("canToggleFileExplorerShortcut", () => {
const toggleFileExplorer = () => undefined;
@@ -4,8 +4,6 @@ import {
parseHostWorkspaceTabRouteFromPathname,
} from "@/utils/host-routes";
const DRAFT_AGENT_ID = "__new_agent__";
export function resolveSelectedOrRouteAgentKey(input: {
selectedAgentId?: string;
pathname: string;
@@ -22,7 +20,7 @@ export function resolveSelectedOrRouteAgentKey(input: {
return agentId ? `${workspaceTabRoute.serverId}:${agentId}` : null;
}
if (tabId.startsWith("draft_")) {
return `${workspaceTabRoute.serverId}:${DRAFT_AGENT_ID}`;
return `${workspaceTabRoute.serverId}:${tabId}`;
}
}