feat(sidebar): show host name on every row in multi-host setups (#1775)
The host name previously appeared only in project grouping mode, and only for projects shared across hosts. It now shows on every workspace row in both project and status grouping modes whenever the sidebar spans more than one host, so you can always tell which machine a workspace lives on. Status rows read "Project · Host". Single-host setups are unchanged.
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
||||
buildSidebarProjectsFromStructure,
|
||||
computeSidebarOrderUpdates,
|
||||
deriveSidebarLoadingState,
|
||||
shouldShowSidebarHostLabels,
|
||||
type SidebarProjectEntry,
|
||||
} from "./sidebar-workspaces-view-model";
|
||||
|
||||
@@ -297,6 +298,63 @@ describe("shared sidebar workspace model", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("shouldShowSidebarHostLabels", () => {
|
||||
it("is false with no visible projects", () => {
|
||||
expect(shouldShowSidebarHostLabels([])).toBe(false);
|
||||
});
|
||||
|
||||
it("is false when every project lives on a single host", () => {
|
||||
const projects = buildSidebarProjectsFromStructure({
|
||||
projects: [
|
||||
project({ projectKey: "project-a", workspaceKeys: ["ws-1"] }),
|
||||
project({ projectKey: "project-b", workspaceKeys: ["ws-2"] }),
|
||||
],
|
||||
});
|
||||
|
||||
expect(shouldShowSidebarHostLabels(projects)).toBe(false);
|
||||
});
|
||||
|
||||
it("is true when projects span separate hosts", () => {
|
||||
const projects = buildSidebarProjectsFromStructure({
|
||||
projects: [
|
||||
project({
|
||||
projectKey: "project-a",
|
||||
hosts: [
|
||||
{ serverId: "host-a", iconWorkingDir: "/repo/project-a", canCreateWorktree: true },
|
||||
],
|
||||
workspaceKeys: ["host-a:ws-1"],
|
||||
}),
|
||||
project({
|
||||
projectKey: "project-b",
|
||||
hosts: [
|
||||
{ serverId: "host-b", iconWorkingDir: "/repo/project-b", canCreateWorktree: true },
|
||||
],
|
||||
workspaceKeys: ["host-b:ws-2"],
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
expect(shouldShowSidebarHostLabels(projects)).toBe(true);
|
||||
});
|
||||
|
||||
it("is true for a single project shared across hosts", () => {
|
||||
const projects = buildSidebarProjectsFromStructure({
|
||||
projects: [
|
||||
project({
|
||||
projectKey: "getpaseo/paseo",
|
||||
hosts: [
|
||||
{ serverId: "host-a", iconWorkingDir: "/repo/paseo", canCreateWorktree: true },
|
||||
{ serverId: "host-b", iconWorkingDir: "/repo/paseo", canCreateWorktree: true },
|
||||
],
|
||||
workspaceKeys: ["host-a:main", "host-b:feature"],
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
expect(shouldShowSidebarHostLabels(projects)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("computeSidebarOrderUpdates", () => {
|
||||
it("returns no updates when there are no visible projects", () => {
|
||||
const updates = computeSidebarOrderUpdates({
|
||||
|
||||
@@ -351,6 +351,20 @@ export function buildSidebarProjectsFromHostProjects(input: {
|
||||
}));
|
||||
}
|
||||
|
||||
// Host labels disambiguate which machine a workspace lives on; they only earn their
|
||||
// space once the visible sidebar spans more than one host. Counting distinct hosts
|
||||
// across the visible projects (not all connected hosts) keeps labels off when a host
|
||||
// filter pins the view to a single host.
|
||||
export function shouldShowSidebarHostLabels(projects: SidebarProjectEntry[]): boolean {
|
||||
const serverIds = new Set<string>();
|
||||
for (const project of projects) {
|
||||
for (const host of project.hosts) {
|
||||
serverIds.add(host.serverId);
|
||||
}
|
||||
}
|
||||
return serverIds.size >= 2;
|
||||
}
|
||||
|
||||
export function applyStoredOrdering<T>(input: {
|
||||
items: T[];
|
||||
storedOrder: string[];
|
||||
|
||||
@@ -31,6 +31,7 @@ export {
|
||||
computeSidebarOrderUpdates,
|
||||
createSidebarWorkspaceEntry,
|
||||
deriveSidebarLoadingState,
|
||||
shouldShowSidebarHostLabels,
|
||||
type SidebarLoadingState,
|
||||
type SidebarOrderUpdates,
|
||||
type SidebarStatusWorkspacePlacement,
|
||||
|
||||
Reference in New Issue
Block a user