* fix(app): show New workspace action on non-git sidebar projects The per-project "New workspace" affordance in the sidebar (the project- header + button and the empty-project ghost row) was gated on host.canCreateWorktree, i.e. projectKind === "git". Non-git projects (non_git / directory) therefore showed no way to add a workspace, even though a host with the workspaceMultiplicity capability can create additional local workspaces for them. Thread the per-host workspaceMultiplicity flag into the sidebar project row model and show the affordance when canCreateWorktree || supportsWorkspaceMultiplicity, matching the gate already used by the global "New workspace" button and the Cmd+N handler. Rename the internal trailing-action kind new_worktree -> new_workspace (a client-only UI model, not a wire type) to reflect that it now also covers non-git workspaces. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * test(app): expect the per-row New workspace icon on non-git projects The sidebar "+" now shows for non-git projects on a multiplicity-capable host, so the Model B sidebar spec no longer asserts the non-git project has zero new-worktree icons — it now expects the icon, like git projects. Also refresh the now-stale "no new-worktree icon" comments in the entry-points spec (the picker is still one valid entry point). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
89 lines
2.8 KiB
TypeScript
89 lines
2.8 KiB
TypeScript
import type { SidebarProjectEntry } from "@/hooks/use-sidebar-workspaces-list";
|
|
|
|
export interface SidebarProjectHostTarget {
|
|
serverId: string;
|
|
iconWorkingDir: string;
|
|
}
|
|
|
|
export type SidebarProjectTrailingAction =
|
|
| { kind: "new_workspace"; target: SidebarProjectHostTarget }
|
|
| { kind: "none" };
|
|
|
|
export interface SidebarProjectSectionRowModel {
|
|
kind: "project_section";
|
|
chevron: "expand" | "collapse";
|
|
trailingAction: SidebarProjectTrailingAction;
|
|
}
|
|
|
|
export type SidebarProjectRowModel = SidebarProjectSectionRowModel;
|
|
|
|
const EMPTY_MULTIPLICITY_MAP: ReadonlyMap<string, boolean> = new Map();
|
|
|
|
function hostTarget(input: {
|
|
serverId: string;
|
|
iconWorkingDir: string;
|
|
}): SidebarProjectHostTarget | null {
|
|
const iconWorkingDir = input.iconWorkingDir.trim();
|
|
if (!input.serverId || !iconWorkingDir) {
|
|
return null;
|
|
}
|
|
return { serverId: input.serverId, iconWorkingDir };
|
|
}
|
|
|
|
export function resolveSidebarProjectIconTarget(
|
|
project: SidebarProjectEntry,
|
|
): SidebarProjectHostTarget | null {
|
|
for (const host of project.hosts) {
|
|
const target = hostTarget(host);
|
|
if (target) {
|
|
return target;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
// A project can host a brand-new workspace on a host when that host can create a
|
|
// git worktree (git projects) OR the host supports running multiple independent
|
|
// workspaces per directory (`workspaceMultiplicity`), which is what lets non-git
|
|
// directories add a second workspace. Mirrors the gate used by the global "New
|
|
// workspace" affordances (use-global-new-workspace-action.ts and left-sidebar's
|
|
// SidebarNewWorkspaceHeaderRow): `canCreateWorktree || supportsMultiplicity`.
|
|
function resolveNewWorkspaceTarget(
|
|
project: SidebarProjectEntry,
|
|
supportsMultiplicityByServerId: ReadonlyMap<string, boolean>,
|
|
): SidebarProjectHostTarget | null {
|
|
for (const host of project.hosts) {
|
|
if (!host.canCreateWorktree && !supportsMultiplicityByServerId.get(host.serverId)) {
|
|
continue;
|
|
}
|
|
const target = hostTarget(host);
|
|
if (target) {
|
|
return target;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
function projectTrailingAction(
|
|
project: SidebarProjectEntry,
|
|
supportsMultiplicityByServerId: ReadonlyMap<string, boolean>,
|
|
): SidebarProjectTrailingAction {
|
|
const target = resolveNewWorkspaceTarget(project, supportsMultiplicityByServerId);
|
|
return target ? { kind: "new_workspace", target } : { kind: "none" };
|
|
}
|
|
|
|
export function buildSidebarProjectRowModel(input: {
|
|
project: SidebarProjectEntry;
|
|
collapsed: boolean;
|
|
supportsMultiplicityByServerId?: ReadonlyMap<string, boolean>;
|
|
}): SidebarProjectRowModel {
|
|
return {
|
|
kind: "project_section",
|
|
chevron: input.collapsed ? "expand" : "collapse",
|
|
trailingAction: projectTrailingAction(
|
|
input.project,
|
|
input.supportsMultiplicityByServerId ?? EMPTY_MULTIPLICITY_MAP,
|
|
),
|
|
};
|
|
}
|