fix(app): show New workspace action on non-git sidebar projects (#1857)
* 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>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
6513b56571
commit
807d0d6d69
@@ -66,7 +66,7 @@ describe("buildSidebarProjectRowModel", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("renders a single-workspace git project as an expandable section with the new worktree action", () => {
|
||||
it("renders a single-workspace git project as an expandable section with the new workspace action", () => {
|
||||
const result = buildSidebarProjectRowModel({
|
||||
project: project({
|
||||
projectKind: "git",
|
||||
@@ -79,13 +79,49 @@ describe("buildSidebarProjectRowModel", () => {
|
||||
kind: "project_section",
|
||||
chevron: "expand",
|
||||
trailingAction: {
|
||||
kind: "new_worktree",
|
||||
kind: "new_workspace",
|
||||
target: { serverId: "srv", iconWorkingDir: "/repo" },
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("targets the project host, not route state, for new worktree actions", () => {
|
||||
it("shows the new workspace action for a non-git project when the host supports workspace multiplicity", () => {
|
||||
const result = buildSidebarProjectRowModel({
|
||||
project: project({ projectKind: "directory", workspaces: [] }),
|
||||
collapsed: false,
|
||||
supportsMultiplicityByServerId: new Map([["srv", true]]),
|
||||
});
|
||||
|
||||
expect(result.trailingAction).toEqual({
|
||||
kind: "new_workspace",
|
||||
target: { serverId: "srv", iconWorkingDir: "/repo" },
|
||||
});
|
||||
});
|
||||
|
||||
it("hides the new workspace action for a non-git project when the host lacks workspace multiplicity", () => {
|
||||
const result = buildSidebarProjectRowModel({
|
||||
project: project({ projectKind: "directory", workspaces: [] }),
|
||||
collapsed: false,
|
||||
supportsMultiplicityByServerId: new Map([["srv", false]]),
|
||||
});
|
||||
|
||||
expect(result.trailingAction).toEqual({ kind: "none" });
|
||||
});
|
||||
|
||||
it("still shows the new workspace action for a git project regardless of multiplicity", () => {
|
||||
const result = buildSidebarProjectRowModel({
|
||||
project: project({ projectKind: "git" }),
|
||||
collapsed: false,
|
||||
supportsMultiplicityByServerId: new Map([["srv", false]]),
|
||||
});
|
||||
|
||||
expect(result.trailingAction).toEqual({
|
||||
kind: "new_workspace",
|
||||
target: { serverId: "srv", iconWorkingDir: "/repo" },
|
||||
});
|
||||
});
|
||||
|
||||
it("targets the project host, not route state, for new workspace actions", () => {
|
||||
const result = buildSidebarProjectRowModel({
|
||||
project: project({
|
||||
hosts: [
|
||||
@@ -98,13 +134,34 @@ describe("buildSidebarProjectRowModel", () => {
|
||||
|
||||
expect(result).toMatchObject({
|
||||
trailingAction: {
|
||||
kind: "new_worktree",
|
||||
kind: "new_workspace",
|
||||
target: { serverId: "host-b", iconWorkingDir: "/repo/b" },
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("renders a multi-workspace git project as an expandable section with a new worktree action", () => {
|
||||
it("targets the first multiplicity-capable host for a non-git project", () => {
|
||||
const result = buildSidebarProjectRowModel({
|
||||
project: project({
|
||||
projectKind: "directory",
|
||||
hosts: [
|
||||
{ serverId: "host-a", iconWorkingDir: "/repo/a", canCreateWorktree: false },
|
||||
{ serverId: "host-b", iconWorkingDir: "/repo/b", canCreateWorktree: false },
|
||||
],
|
||||
}),
|
||||
collapsed: false,
|
||||
supportsMultiplicityByServerId: new Map([["host-b", true]]),
|
||||
});
|
||||
|
||||
expect(result).toMatchObject({
|
||||
trailingAction: {
|
||||
kind: "new_workspace",
|
||||
target: { serverId: "host-b", iconWorkingDir: "/repo/b" },
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("renders a multi-workspace git project as an expandable section with a new workspace action", () => {
|
||||
const result = buildSidebarProjectRowModel({
|
||||
project: project({
|
||||
projectKind: "git",
|
||||
@@ -120,7 +177,7 @@ describe("buildSidebarProjectRowModel", () => {
|
||||
kind: "project_section",
|
||||
chevron: "expand",
|
||||
trailingAction: {
|
||||
kind: "new_worktree",
|
||||
kind: "new_workspace",
|
||||
target: { serverId: "srv", iconWorkingDir: "/repo" },
|
||||
},
|
||||
});
|
||||
@@ -149,7 +206,7 @@ describe("buildSidebarProjectRowModel", () => {
|
||||
kind: "project_section",
|
||||
chevron: "collapse",
|
||||
trailingAction: {
|
||||
kind: "new_worktree",
|
||||
kind: "new_workspace",
|
||||
target: { serverId: "srv", iconWorkingDir: "/repo" },
|
||||
},
|
||||
});
|
||||
|
||||
@@ -6,7 +6,7 @@ export interface SidebarProjectHostTarget {
|
||||
}
|
||||
|
||||
export type SidebarProjectTrailingAction =
|
||||
| { kind: "new_worktree"; target: SidebarProjectHostTarget }
|
||||
| { kind: "new_workspace"; target: SidebarProjectHostTarget }
|
||||
| { kind: "none" };
|
||||
|
||||
export interface SidebarProjectSectionRowModel {
|
||||
@@ -17,6 +17,8 @@ export interface SidebarProjectSectionRowModel {
|
||||
|
||||
export type SidebarProjectRowModel = SidebarProjectSectionRowModel;
|
||||
|
||||
const EMPTY_MULTIPLICITY_MAP: ReadonlyMap<string, boolean> = new Map();
|
||||
|
||||
function hostTarget(input: {
|
||||
serverId: string;
|
||||
iconWorkingDir: string;
|
||||
@@ -40,9 +42,18 @@ export function resolveSidebarProjectIconTarget(
|
||||
return null;
|
||||
}
|
||||
|
||||
function resolveNewWorktreeTarget(project: SidebarProjectEntry): SidebarProjectHostTarget | 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) {
|
||||
if (!host.canCreateWorktree && !supportsMultiplicityByServerId.get(host.serverId)) {
|
||||
continue;
|
||||
}
|
||||
const target = hostTarget(host);
|
||||
@@ -53,18 +64,25 @@ function resolveNewWorktreeTarget(project: SidebarProjectEntry): SidebarProjectH
|
||||
return null;
|
||||
}
|
||||
|
||||
function projectTrailingAction(project: SidebarProjectEntry): SidebarProjectTrailingAction {
|
||||
const target = resolveNewWorktreeTarget(project);
|
||||
return target ? { kind: "new_worktree", target } : { kind: "none" };
|
||||
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),
|
||||
trailingAction: projectTrailingAction(
|
||||
input.project,
|
||||
input.supportsMultiplicityByServerId ?? EMPTY_MULTIPLICITY_MAP,
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user