Open the complete working comparison in a desktop workspace tab while preserving inline sidebar diffs when the tab is closed. Working and commit comparisons share one diff panel, and workspace layout is the sole owner of live tab persistence and identity. Refs #1520
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import { generateDraftId } from "@/stores/draft-keys";
|
|
import { buildWorkspaceTabPersistenceKey, type WorkspaceTabTarget } from "@/workspace-tabs/model";
|
|
|
|
export interface PrepareWorkspaceTabInput {
|
|
serverId: string;
|
|
workspaceId: string;
|
|
target: WorkspaceTabTarget;
|
|
pin?: boolean;
|
|
}
|
|
|
|
export interface PrepareWorkspaceTabDeps {
|
|
openTabFocused: (workspaceKey: string, target: WorkspaceTabTarget) => string | null;
|
|
pinAgent: (workspaceKey: string, agentId: string) => void;
|
|
}
|
|
|
|
function getPreparedTarget(target: WorkspaceTabTarget): WorkspaceTabTarget {
|
|
if (target.kind !== "draft" || target.draftId.trim() !== "new") {
|
|
return target;
|
|
}
|
|
return { kind: "draft", draftId: generateDraftId() };
|
|
}
|
|
|
|
export function prepareWorkspaceTab(
|
|
input: PrepareWorkspaceTabInput,
|
|
deps: PrepareWorkspaceTabDeps,
|
|
): void {
|
|
const target = getPreparedTarget(input.target);
|
|
const key =
|
|
buildWorkspaceTabPersistenceKey({
|
|
serverId: input.serverId,
|
|
workspaceId: input.workspaceId,
|
|
}) ?? "";
|
|
|
|
deps.openTabFocused(key, target);
|
|
|
|
if (input.pin && target.kind === "agent") {
|
|
deps.pinAgent(key, target.agentId);
|
|
}
|
|
}
|