From bededeb101a539c3b98cf8c90c74a1ab775030aa Mon Sep 17 00:00:00 2001 From: "tao.chen" <93983997+taochen-ct@users.noreply.github.com> Date: Mon, 3 Aug 2026 10:49:39 +0800 Subject: [PATCH] optimize: add routes --- .../features/platform/ModelPlatformApp.tsx | 510 +----------------- frontend/app/routes.ts | 12 +- 2 files changed, 13 insertions(+), 509 deletions(-) diff --git a/frontend/app/features/platform/ModelPlatformApp.tsx b/frontend/app/features/platform/ModelPlatformApp.tsx index 92e8789..3f0a50d 100644 --- a/frontend/app/features/platform/ModelPlatformApp.tsx +++ b/frontend/app/features/platform/ModelPlatformApp.tsx @@ -39,6 +39,8 @@ import Icon from "../../components/Icon"; import SchedulePage from "../schedules/SchedulePage"; import { DashboardPage, SystemAdminPage } from "../admin/AdminPages"; import "../../styles/platform.css"; +import { WorkspaceTreeGroup, scriptIcon } from "./WorkspaceTree"; +import { ScriptWorkspace } from "./ScriptWorkspace"; type NewScriptForm = { @@ -88,29 +90,6 @@ const initialForm: NewScriptForm = { parentPath: "", }; -function formatTime(value: string) { - return new Intl.DateTimeFormat("zh-CN", { - month: "2-digit", - day: "2-digit", - hour: "2-digit", - minute: "2-digit", - hour12: false, - }).format(new Date(value)); -} - -function formatBytes(value: number) { - if (value < 1024) return `${value} B`; - return `${(value / 1024).toFixed(1)} KB`; -} - -function shortHash(value: string) { - return value ? `${value.slice(0, 8)}…${value.slice(-6)}` : "—"; -} - -function scriptIcon(item: ScriptItem) { - return item.script_type === "notebook" ? "notebook" : "python"; -} - function ownedScriptPath(item: ScriptItem) { return item.relative_path.replaceAll("\\", "/").split("/").slice(2).join("/"); } @@ -143,45 +122,6 @@ function mergeDirectories( [...left, ...right].map((item) => [item.path, item]), ).values()]; } - -function confineJupyterFrame(frame: HTMLIFrameElement): void { - try { - const document = frame.contentDocument; - if (!document?.documentElement) return; - const keepInside = (): void => { - document.querySelectorAll("button,[role='button']").forEach( - (element) => { - const label = `${element.getAttribute("aria-label") ?? ""} ${ - element.getAttribute("title") ?? "" - } ${element.textContent ?? ""}`.trim(); - if (/^open in\b/i.test(label) || /\bopen in\.\.\./i.test(label)) { - element.style.setProperty("display", "none", "important"); - } - }, - ); - document.querySelectorAll("a[target]").forEach((link) => { - if (["_blank", "_top", "_parent"].includes(link.target)) { - link.target = "_self"; - } - }); - }; - keepInside(); - new MutationObserver(keepInside).observe(document.documentElement, { - childList: true, - subtree: true, - }); - document.addEventListener("click", (event) => { - const target = event.target as HTMLElement | null; - const link = target?.closest?.("a") as HTMLAnchorElement | null; - if (link && ["_blank", "_top", "_parent"].includes(link.target)) { - link.target = "_self"; - } - }, true); - } catch { - // The iframe remains sandboxed even if its document is not yet accessible. - } -} - export default function ModelPlatformApp() { const location = useLocation(); const navigate = useNavigate(); @@ -1518,448 +1458,4 @@ export default function ModelPlatformApp() { )} ); -} - -function WorkspaceTreeGroup({ - title, - scripts, - directories, - selectedId, - onSelect, - onContextMenu, - readOnly = false, -}: { - title: string; - scripts: ScriptItem[]; - directories: WorkspaceDirectory[]; - selectedId: string | null; - onSelect: (id: string) => void; - onContextMenu?: ( - event: ReactMouseEvent, - target: Omit, - ) => void; - readOnly?: boolean; -}) { - const [open, setOpen] = useState(true); - return ( -
- - {open && ( -
- - {scripts.length === 0 && directories.length === 0 && ( -

- {readOnly ? "暂无文件" : "右键此目录即可新建或上传"} -

- )} -
- )} -
- ); -} - -function WorkspaceTreeItems({ - path, - depth, - scripts, - directories, - selectedId, - onSelect, - onContextMenu, -}: { - path: string; - depth: number; - scripts: ScriptItem[]; - directories: WorkspaceDirectory[]; - selectedId: string | null; - onSelect: (id: string) => void; - onContextMenu?: ( - event: ReactMouseEvent, - target: Omit, - ) => void; -}) { - const childDirectories = directories.filter( - (item) => item.parent_path === path, - ); - const childScripts = scripts.filter( - (item) => parentOf(ownedScriptPath(item)) === path, - ); - return ( - <> - {childDirectories.map((directory) => ( - - ))} - {childScripts.map((item) => ( - - ))} - - ); -} - -function DirectoryBranch({ - directory, - depth, - scripts, - directories, - selectedId, - onSelect, - onContextMenu, -}: { - directory: WorkspaceDirectory; - depth: number; - scripts: ScriptItem[]; - directories: WorkspaceDirectory[]; - selectedId: string | null; - onSelect: (id: string) => void; - onContextMenu?: ( - event: ReactMouseEvent, - target: Omit, - ) => void; -}) { - const [open, setOpen] = useState(true); - return ( -
- - {open && ( - - )} -
- ); -} - -function ScriptWorkspace({ - script, - editSession, - jupyterUrl, - editBusy, - openError, - latestVersion, - versionsLoading, - onOpenEditor, - onEndEditing, - onClose, - onPublish, - onInfo, -}: { - script: ScriptItem; - editSession: ActiveEditSession | null; - jupyterUrl: string | null; - editBusy: boolean; - openError: string | null; - latestVersion: StableVersion | null; - versionsLoading: boolean; - onOpenEditor: () => void; - onEndEditing: () => void; - onClose: () => void; - onPublish: () => void; - onInfo: (toast: ToastState) => void; -}) { - const isNotebook = script.script_type === "notebook"; - const isEditing = editSession?.session_status === "active"; - return ( - <> -
-
- - - - {script.script_name} - -
- -
- -
-
- - - - 工作副本 - - {script.script_name} -
-
- {isEditing ? ( - - ) : ( - - )} - - - - {isEditing - ? isNotebook - ? "Demo 无锁模式 · Kernel 已连接" - : "Demo 无锁模式 · 编辑中" - : latestVersion - ? `最新 ${latestVersion.version_label}` - : "工作副本已就绪"} - -
-
- -
- {isEditing && jupyterUrl ? ( -
-
- - - Workspace Jupyter Server - - - {isNotebook ? "Notebook Session · Python 3 Kernel" : "Jupyter 文本编辑器"} - - - Runtime {editSession.runtime_id.slice(-8)} - -
-