import { type FormEvent } from "react"; import Icon from "../../components/common/Icon"; import type { ScriptType, Visibility } from "../../services/api"; type NewScriptForm = { name: string; scriptType: ScriptType; visibility: Visibility; parentPath: string; }; type CreateScriptModalProps = { open: boolean; creating: boolean; form: NewScriptForm; scripts: Array<{ script_type: ScriptType; script_name: string; relative_path?: string; }>; onFormChange: (form: NewScriptForm) => void; onSubmit: (event: FormEvent) => void; onClose: () => void; }; export function CreateScriptModal({ open, creating, form, scripts, onFormChange, onSubmit, onClose, }: CreateScriptModalProps) { if (!open) return null; const suffix = form.scriptType === "notebook" ? ".ipynb" : ".py"; const requestedName = form.name.trim(); const normalizedName = requestedName.toLocaleLowerCase().endsWith(suffix) ? requestedName : `${requestedName}${suffix}`; const duplicate = scripts.some((script) => { if (script.script_type !== form.scriptType) return false; if (script.script_name.toLocaleLowerCase() !== normalizedName.toLocaleLowerCase()) return false; // Same name in a different subdirectory is allowed; mirror the // backend name_clash scope (StorageObjects.relative_path JOIN). if (!script.relative_path) return true; const segments = script.relative_path.replaceAll("\\", "/") .split("/").slice(2); const existingUserPath = segments.join("/"); const existingParent = existingUserPath.includes("/") ? existingUserPath.slice(0, existingUserPath.lastIndexOf("/")) : ""; return existingParent === form.parentPath; }); return (
工作副本

新建构建脚本

保存到:{form.parentPath || "个人根目录"}
脚本类型
); }