fix(projects): make freshly-added projects editable

Make workspace-less projects flow through aggregated project fetching and keep the settings screen editable immediately after adding one.
This commit is contained in:
huiliaoning
2026-06-27 12:44:16 +08:00
committed by GitHub
parent a908384e5a
commit 26a8a04651
10 changed files with 1531 additions and 22 deletions
+23 -6
View File
@@ -1,4 +1,4 @@
import type { WorkspaceDescriptor } from "@/stores/session-store";
import type { EmptyProjectDescriptor, WorkspaceDescriptor } from "@/stores/session-store";
import { buildHostProjectList, type HostProjectListItem } from "@/projects/host-project-model";
import { buildWorkspaceStructureProjects } from "@/projects/workspace-structure";
@@ -37,6 +37,8 @@ export interface ProjectHost {
serverName: string;
isOnline: boolean;
workspaces: WorkspaceDescriptor[];
/** Project parents with no active workspaces, so they still surface as projects. */
emptyProjects?: EmptyProjectDescriptor[];
}
export interface BuildProjectsInput {
@@ -54,6 +56,9 @@ interface HostGroup {
serverName: string;
isOnline: boolean;
workspaces: WorkspaceDescriptor[];
// Repo root for a project parent that has no workspaces yet. Without it the
// host's repoRoot resolves to "" and the project reads as non-editable.
fallbackRepoRoot: string;
}
interface ProjectGroup {
@@ -81,7 +86,13 @@ function findProjectCustomName(
function buildHostProjectEntries(host: ProjectHost): HostProjectListItem[] {
return buildHostProjectList({
projects: buildWorkspaceStructureProjects({
sessions: [{ serverId: host.serverId, workspaces: host.workspaces }],
sessions: [
{
serverId: host.serverId,
workspaces: host.workspaces,
emptyProjects: host.emptyProjects,
},
],
}),
});
}
@@ -94,14 +105,14 @@ function deriveGithubUrl(projectKey: string): string | undefined {
return `https://github.com/${match[1]}/${match[2]}`;
}
function resolveHostRepoRoot(workspaces: WorkspaceDescriptor[]): string {
for (const workspace of workspaces) {
function resolveHostRepoRoot(group: HostGroup): string {
for (const workspace of group.workspaces) {
const mainRepoRoot = workspace.project?.checkout.mainRepoRoot;
if (mainRepoRoot) {
return mainRepoRoot;
}
}
return workspaces[0]?.projectRootPath ?? "";
return group.workspaces[0]?.projectRootPath ?? group.fallbackRepoRoot;
}
function toWorkspaceSummary(workspace: WorkspaceDescriptor): WorkspaceSummary {
@@ -115,7 +126,7 @@ function toWorkspaceSummary(workspace: WorkspaceDescriptor): WorkspaceSummary {
}
function toHostEntry(group: HostGroup): ProjectHostEntry {
const repoRoot = resolveHostRepoRoot(group.workspaces);
const repoRoot = resolveHostRepoRoot(group);
const canonical =
group.workspaces.find((workspace) => workspace.projectRootPath === repoRoot) ??
group.workspaces[0];
@@ -159,6 +170,11 @@ export function buildProjects(input: BuildProjectsInput): BuildProjectsResult {
const groups = new Map<string, ProjectGroup>();
for (const host of input.hosts) {
const emptyRepoRootByProjectKey = new Map<string, string>();
for (const emptyProject of host.emptyProjects ?? []) {
emptyRepoRootByProjectKey.set(emptyProject.projectId, emptyProject.projectRootPath);
}
const hostProjects = buildHostProjectEntries(host);
for (const hostProject of hostProjects) {
const customName = findProjectCustomName(host.workspaces, hostProject.projectKey);
@@ -182,6 +198,7 @@ export function buildProjects(input: BuildProjectsInput): BuildProjectsResult {
serverName: host.serverName,
isOnline: host.isOnline,
workspaces: [],
fallbackRepoRoot: emptyRepoRootByProjectKey.get(hostProject.projectKey) ?? "",
});
}
}