mirror of
https://github.com/getpaseo/paseo.git
synced 2026-07-29 12:01:31 +00:00
fix(projects): reconcile grouped custom names
This commit is contained in:
53
packages/app/src/projects/workspace-structure.test.ts
Normal file
53
packages/app/src/projects/workspace-structure.test.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { WorkspaceDescriptor } from "@/stores/session-store";
|
||||
import { buildWorkspaceStructureProjects } from "./workspace-structure";
|
||||
|
||||
function workspace(input: {
|
||||
id: string;
|
||||
projectName: string;
|
||||
projectCustomName: string | null;
|
||||
}): WorkspaceDescriptor {
|
||||
return {
|
||||
id: input.id,
|
||||
projectId: `project-${input.id}`,
|
||||
projectGroupKey: "remote:github.com/acme/app",
|
||||
projectDisplayName: input.projectName,
|
||||
projectCustomName: input.projectCustomName,
|
||||
projectRootPath: `/repo/${input.id}`,
|
||||
workspaceDirectory: `/repo/${input.id}`,
|
||||
projectKind: "git",
|
||||
workspaceKind: "local_checkout",
|
||||
name: "main",
|
||||
status: "done",
|
||||
statusEnteredAt: null,
|
||||
archivingAt: null,
|
||||
diffStat: null,
|
||||
scripts: [],
|
||||
};
|
||||
}
|
||||
|
||||
describe("buildWorkspaceStructureProjects", () => {
|
||||
it("promotes a later grouped host's custom project name", () => {
|
||||
const projects = buildWorkspaceStructureProjects({
|
||||
sessions: [
|
||||
{
|
||||
serverId: "host-a",
|
||||
workspaces: [workspace({ id: "a", projectName: "acme/app", projectCustomName: null })],
|
||||
},
|
||||
{
|
||||
serverId: "host-b",
|
||||
workspaces: [
|
||||
workspace({ id: "b", projectName: "acme/app", projectCustomName: "My App" }),
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
expect(projects).toEqual([
|
||||
expect.objectContaining({
|
||||
projectKey: "remote:github.com/acme/app",
|
||||
projectName: "My App",
|
||||
}),
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -123,6 +123,7 @@ export function buildWorkspaceStructureProjects(input: {
|
||||
{
|
||||
projectKey: string;
|
||||
projectName: string;
|
||||
hasCustomName: boolean;
|
||||
projectKind: WorkspaceDescriptor["projectKind"];
|
||||
iconWorkingDir: string;
|
||||
hosts: Map<string, WorkspaceStructureHostPlacement>;
|
||||
@@ -153,6 +154,7 @@ export function buildWorkspaceStructureProjects(input: {
|
||||
emptyProject.projectCustomName ??
|
||||
emptyProject.projectDisplayName ??
|
||||
projectDisplayNameFromProjectId(projectKey),
|
||||
hasCustomName: Boolean(emptyProject.projectCustomName),
|
||||
projectKind: emptyProject.projectKind,
|
||||
iconWorkingDir: emptyProject.projectRootPath,
|
||||
hosts: new Map([[session.serverId, placement]]),
|
||||
@@ -161,6 +163,10 @@ export function buildWorkspaceStructureProjects(input: {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (emptyProject.projectCustomName && !existing.hasCustomName) {
|
||||
existing.projectName = emptyProject.projectCustomName;
|
||||
existing.hasCustomName = true;
|
||||
}
|
||||
existing.hosts.set(session.serverId, placement);
|
||||
}
|
||||
|
||||
@@ -180,6 +186,7 @@ export function buildWorkspaceStructureProjects(input: {
|
||||
workspace.projectCustomName ??
|
||||
workspace.projectDisplayName ??
|
||||
projectDisplayNameFromProjectId(projectKey),
|
||||
hasCustomName: Boolean(workspace.projectCustomName),
|
||||
projectKind: workspace.projectKind,
|
||||
iconWorkingDir: workspace.projectRootPath,
|
||||
hosts: new Map([
|
||||
@@ -204,6 +211,10 @@ export function buildWorkspaceStructureProjects(input: {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (workspace.projectCustomName && !existing.hasCustomName) {
|
||||
existing.projectName = workspace.projectCustomName;
|
||||
existing.hasCustomName = true;
|
||||
}
|
||||
existing.hosts.set(session.serverId, {
|
||||
serverId: session.serverId,
|
||||
projectId: workspace.projectId,
|
||||
|
||||
Reference in New Issue
Block a user