Files
paseo/packages/app/src/screens/new-workspace-picker-item.ts
T
Mohamed BoudraandGitHub de44c8cd66 Show New Workspace isolation controls immediately (#2702)
* fix(workspaces): show isolation without checkout delay

* fix(workspaces): trust hydrated project capability

* fix(workspaces): resolve branch before creation

* fix(workspaces): honor invalidated checkout status

* fix(workspaces): preserve isolation while projects load

* fix(workspaces): keep provisional project routes usable

Route-derived projects do not know their worktree capability. Represent that uncertainty at the placement boundary so remembered worktree intent survives hydration without disabling the New Workspace screen indefinitely.
2026-07-31 17:50:35 +02:00

60 lines
1.9 KiB
TypeScript

import type { CreatePaseoWorktreeInput } from "@getpaseo/client/internal/daemon-client";
import type { ForgeSearchItem } from "@getpaseo/protocol/messages";
import type { CheckoutStatusPayload } from "@/git/checkout-status-cache";
export type PickerItem =
| { kind: "branch"; name: string }
| {
kind: "github-pr";
item: ForgeSearchItem;
};
export type PickerCheckoutRequest = Pick<
CreatePaseoWorktreeInput,
"action" | "refName" | "checkoutSource" | "githubPrNumber"
>;
export function pickerItemToCheckoutRequest(
item: PickerItem | null,
): PickerCheckoutRequest | undefined {
if (!item) return undefined;
switch (item.kind) {
case "branch":
return { action: "branch-off", refName: item.name };
case "github-pr": {
const headRefName = item.item.headRefName?.trim();
const forge = item.item.forge ?? "github";
return {
action: "checkout",
...(headRefName ? { refName: headRefName } : {}),
checkoutSource: {
kind: "change_request",
forge,
number: item.item.number,
...(item.item.projectPath ? { projectPath: item.item.projectPath } : {}),
},
...(forge === "github"
? {
// COMPAT(githubPrNumber): added in v0.1.106, remove after 2026-12-28 once
// daemon floor parses checkoutSource.
githubPrNumber: item.item.number,
}
: {}),
};
}
}
}
export function resolveCheckoutRequest(
selectedItem: PickerItem | null,
checkoutStatus: CheckoutStatusPayload,
): PickerCheckoutRequest | undefined {
const selectedCheckoutRequest = pickerItemToCheckoutRequest(selectedItem);
if (selectedCheckoutRequest) return selectedCheckoutRequest;
if (!checkoutStatus.currentBranch) return undefined;
return {
action: "branch-off",
refName: checkoutStatus.currentBranch,
};
}