From bef1fd6f5b0d1d4b00fa34980086c3699e54fd8b Mon Sep 17 00:00:00 2001 From: cp3hnu Date: Wed, 4 Dec 2024 16:24:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=A4=8D=E5=88=B6?= =?UTF-8?q?=E5=AE=9E=E9=AA=8C=E9=9D=A2=E5=8C=85=E5=B1=91=E4=B8=8D=E6=AD=A3?= =?UTF-8?q?=E7=A1=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- react-ui/config/routes.ts | 5 ++ react-ui/src/pages/AutoML/Create/index.tsx | 48 +++++++++---------- react-ui/src/pages/AutoML/List/index.tsx | 5 +- .../ModelDeployment/CreateVersion/index.tsx | 2 +- react-ui/src/utils/sessionStorage.ts | 2 - 5 files changed, 29 insertions(+), 33 deletions(-) diff --git a/react-ui/config/routes.ts b/react-ui/config/routes.ts index faa18dba..578d2474 100644 --- a/react-ui/config/routes.ts +++ b/react-ui/config/routes.ts @@ -169,6 +169,11 @@ export default [ path: 'edit/:id', component: './AutoML/Create/index', }, + { + name: '复制实验', + path: 'copy/:id', + component: './AutoML/Create/index', + }, { name: '实验实例详情', path: 'instance/:autoMLId/:id', diff --git a/react-ui/src/pages/AutoML/Create/index.tsx b/react-ui/src/pages/AutoML/Create/index.tsx index 93e4c2c6..19fedd19 100644 --- a/react-ui/src/pages/AutoML/Create/index.tsx +++ b/react-ui/src/pages/AutoML/Create/index.tsx @@ -9,8 +9,7 @@ import { addAutoMLReq, getAutoMLInfoReq, updateAutoMLReq } from '@/services/auto import { convertEmptyStringToUndefined, parseJsonText, trimCharacter } from '@/utils'; import { safeInvoke } from '@/utils/functional'; import { to } from '@/utils/promise'; -import SessionStorage from '@/utils/sessionStorage'; -import { useNavigate, useParams } from '@umijs/max'; +import { useLocation, useNavigate, useParams } from '@umijs/max'; import { App, Button, Form } from 'antd'; import { omit } from 'lodash'; import { useEffect } from 'react'; @@ -27,27 +26,18 @@ function CreateAutoML() { const { message } = App.useApp(); const params = useParams(); const id = safeInvoke(Number)(params.id); + const { pathname } = useLocation(); + const isCopy = pathname.includes('copy'); useEffect(() => { - // 复制和新建 - const recordId = SessionStorage.getItem(SessionStorage.autoMLRecordIDKey); - if (recordId && !Number.isNaN(Number(recordId))) { - getAutoMLInfo(Number(recordId), true); - } - return () => { - SessionStorage.removeItem(SessionStorage.autoMLRecordIDKey); - }; - }, []); - - useEffect(() => { - // 编辑 + // 编辑,复制 if (id && !Number.isNaN(id)) { - getAutoMLInfo(id, false); + getAutoMLInfo(id); } }, [id]); // 获取服务详情 - const getAutoMLInfo = async (id: number, isCopy = false) => { + const getAutoMLInfo = async (id: number) => { const [res] = await to(getAutoMLInfoReq({ id })); if (res && res.data) { const autoMLInfo: AutoMLData = res.data; @@ -127,14 +117,15 @@ function CreateAutoML() { target_columns, }; - const params = id - ? { - id: id, - ...object, - } - : object; + const params = + id && !isCopy + ? { + id: id, + ...object, + } + : object; - const request = id ? updateAutoMLReq : addAutoMLReq; + const request = id && !isCopy ? updateAutoMLReq : addAutoMLReq; const [res] = await to(request(params)); if (res) { message.success('操作成功'); @@ -153,10 +144,15 @@ function CreateAutoML() { }; let buttonText = '新建'; - let title = '新增实验'; + let title = '新建实验'; if (id) { - title = '编辑实验'; - buttonText = '更新'; + if (isCopy) { + title = '复制实验'; + buttonText = '确定'; + } else { + title = '编辑实验'; + buttonText = '更新'; + } } return ( diff --git a/react-ui/src/pages/AutoML/List/index.tsx b/react-ui/src/pages/AutoML/List/index.tsx index aa269e50..93dc1d27 100644 --- a/react-ui/src/pages/AutoML/List/index.tsx +++ b/react-ui/src/pages/AutoML/List/index.tsx @@ -17,7 +17,6 @@ import { import themes from '@/styles/theme.less'; import { type ExperimentInstance as ExperimentInstanceData } from '@/types'; import { to } from '@/utils/promise'; -import SessionStorage from '@/utils/sessionStorage'; import tableCellRender, { TableCellValueType } from '@/utils/table'; import { modalConfirm } from '@/utils/ui'; import { useNavigate } from '@umijs/max'; @@ -118,13 +117,11 @@ function AutoMLList() { if (record) { if (isCopy) { - SessionStorage.setItem(SessionStorage.autoMLRecordIDKey, record.id, false); - navigate(`/pipeline/autoML/create`); + navigate(`/pipeline/autoML/copy/${record.id}`); } else { navigate(`/pipeline/autoML/edit/${record.id}`); } } else { - SessionStorage.setItem(SessionStorage.autoMLRecordIDKey, '', false); navigate(`/pipeline/autoML/create`); } }; diff --git a/react-ui/src/pages/ModelDeployment/CreateVersion/index.tsx b/react-ui/src/pages/ModelDeployment/CreateVersion/index.tsx index 06a71073..29f8e739 100644 --- a/react-ui/src/pages/ModelDeployment/CreateVersion/index.tsx +++ b/react-ui/src/pages/ModelDeployment/CreateVersion/index.tsx @@ -169,7 +169,7 @@ function CreateServiceVersion() { if (lastPage === CreateServiceVersionFrom.ServiceInfo) { navigate(-1); } else { - navigate(`serviceInfo/${serviceId}`, { replace: true }); + navigate(`/modelDeployment/serviceInfo/${serviceId}`, { replace: true }); } } }; diff --git a/react-ui/src/utils/sessionStorage.ts b/react-ui/src/utils/sessionStorage.ts index 8f619881..4a41e214 100644 --- a/react-ui/src/utils/sessionStorage.ts +++ b/react-ui/src/utils/sessionStorage.ts @@ -9,8 +9,6 @@ export default class SessionStorage { static readonly editorUrlKey = 'editor-url'; // 客户端信息 static readonly clientInfoKey = 'client-info'; - // 自动机器学习记录ID - static readonly autoMLRecordIDKey = 'auto-ml-record-id'; static getItem(key: string, isObject: boolean = false) { const jsonStr = sessionStorage.getItem(key);