feat(coding): add project identity UX
This commit is contained in:
@@ -5,6 +5,13 @@ import type {
|
||||
CodingProjectSummary,
|
||||
} from '@/types/coding-project';
|
||||
import type { ProjectType } from '../../shared/project-config';
|
||||
import type { ProjectIdentityChoice } from '../../shared/coding-project-contracts';
|
||||
|
||||
const CANONICAL_PROJECT_ID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/u;
|
||||
|
||||
export function isCanonicalCodingProjectId(value: string): boolean {
|
||||
return CANONICAL_PROJECT_ID_PATTERN.test(value.trim());
|
||||
}
|
||||
|
||||
export interface CodingProjectCatalog {
|
||||
projects: CodingProjectSummary[];
|
||||
@@ -28,6 +35,7 @@ export async function createCodingProject(input: {
|
||||
parentPath?: string;
|
||||
projectName?: string;
|
||||
projectType?: ProjectType;
|
||||
identity: ProjectIdentityChoice;
|
||||
}): Promise<CodingProjectConfigSnapshot> {
|
||||
const response = await hostApiFetch<{ snapshot: CodingProjectConfigSnapshot }>('/api/coding/projects/create', {
|
||||
method: 'POST',
|
||||
@@ -36,6 +44,33 @@ export async function createCodingProject(input: {
|
||||
return response.snapshot;
|
||||
}
|
||||
|
||||
export async function resolveCodingProjectIdentity(
|
||||
localProjectId: string,
|
||||
identity: ProjectIdentityChoice,
|
||||
): Promise<CodingProjectConfigSnapshot> {
|
||||
const response = await hostApiFetch<{ snapshot: CodingProjectConfigSnapshot }>(
|
||||
'/api/coding/projects/identity',
|
||||
{
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ localProjectId, identity }),
|
||||
},
|
||||
);
|
||||
return response.snapshot;
|
||||
}
|
||||
|
||||
export async function makeCodingProjectIndependentCopy(
|
||||
localProjectId: string,
|
||||
): Promise<CodingProjectConfigSnapshot> {
|
||||
const response = await hostApiFetch<{ snapshot: CodingProjectConfigSnapshot }>(
|
||||
'/api/coding/projects/identity/independent-copy',
|
||||
{
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ localProjectId, confirmed: true }),
|
||||
},
|
||||
);
|
||||
return response.snapshot;
|
||||
}
|
||||
|
||||
export async function setActiveCodingProject(projectId: string): Promise<CodingProjectSummary> {
|
||||
const response = await hostApiFetch<{ project: CodingProjectSummary }>('/api/coding/projects/active', {
|
||||
method: 'POST',
|
||||
|
||||
Reference in New Issue
Block a user