feat: rename graph titles with select-then-edit interaction

This commit is contained in:
2026-11-06 01:40:40 +08:00
parent c9ce5fc2f1
commit af9988f78d
11 changed files with 212 additions and 9 deletions
+2
View File
@@ -45,6 +45,8 @@ export const errorText = (error: unknown) => {
workspace_not_loaded: "空间列表尚未加载成功,请刷新页面后重试。",
workspace_required: "请先创建或选择一个工作空间。",
invalid_workspace: "工作空间名称不符合要求,请修改后重试。",
invalid_title: "名称不能为空,且不能超过 300 字节(约 100 个汉字)。",
version_conflict: "图谱已在别处修改,请再次保存以读取最新版本。",
invalid_profile: "请检查显示名称,以及用户名是否为 3–40 位小写字母、数字、下划线或连字符。",
forbidden: "你没有在此工作空间创建或编辑图谱的权限。",
invalid_material: "画布名称或内容不符合要求,请修改后重试。",
+16
View File
@@ -8,6 +8,7 @@ export type Board = {
title: string;
version: number;
content?: { schema_version: number };
description?: string;
};
export const DEFAULT_BOARD_TITLE = "未命名图谱";
@@ -56,3 +57,18 @@ export async function createBoard(
});
return { ...result, workspace_id: result.workspace_id || id, title: name };
}
export async function renameBoard(request: Request, workspaceId: string, boardId: string, title: string): Promise<Board> {
const name = title.trim();
if (!name || new TextEncoder().encode(name).length > 300) throw new Error("invalid_title");
const path = `workspaces/${encodeURIComponent(workspaceId)}/materials/${encodeURIComponent(boardId)}`;
const current = await request<Board>(path);
if (current.kind !== "board" || current.id !== boardId || current.workspace_id !== workspaceId) throw new Error("invalid_reference");
await request(path, {
method: "PATCH",
headers: { "If-Match": `"${current.version}"` },
body: JSON.stringify({ title: name, description: current.description || "", content: current.content || { schema_version: 1 } }),
});
return { ...current, title: name, version: current.version + 1 };
}