From b0e4f2474870feae96d5b8ada427afa78c22426d Mon Sep 17 00:00:00 2001 From: Nut He <18328704+hetao92@users.noreply.github.com> Date: Tue, 23 May 2023 17:23:35 +0800 Subject: [PATCH] fix: fix the problem of editing or rerunning tasks (#566) * fix: the problem of editing or rerunning tasks generated by templates * fix: render problem --- app/config/locale/en-US.ts | 5 ++- app/config/locale/zh-CN.ts | 5 ++- app/pages/Import/TaskList/TaskItem/index.tsx | 36 ++++++++++++++----- .../Schema/SchemaConfig/List/Search/index.tsx | 1 + app/stores/import.ts | 21 +++++------ 5 files changed, 48 insertions(+), 20 deletions(-) diff --git a/app/config/locale/en-US.ts b/app/config/locale/en-US.ts index 087b6f30..33bc353f 100644 --- a/app/config/locale/en-US.ts +++ b/app/config/locale/en-US.ts @@ -323,7 +323,10 @@ export default { 'modifyTime': 'Modify time', 'taskNameRequired': 'Please enter the task name and select space', 'fileMissing': '{files} does not exist, please re-upload the file', - 'datasourceMissing': 'The related data source of {files} is not found, please re-add the related datasource and reconfigure the task' + 'datasourceMissing': 'The related data source of {files} is not found, please re-add the related datasource and reconfigure the task', + 'templateRerunTip': 'The task generated by template import does not support editing, please directly modify the template file and import it.', + 'rerunError': 'The task configuration record cannot be found, and the task cannot be rerun', + 'editTaskError': 'Cannot find task configuration record, cannot continue editing' }, 'schema': { 'spaceList': 'Graph Space List', diff --git a/app/config/locale/zh-CN.ts b/app/config/locale/zh-CN.ts index f5dadf40..10229a06 100644 --- a/app/config/locale/zh-CN.ts +++ b/app/config/locale/zh-CN.ts @@ -323,7 +323,10 @@ export default { 'modifyTime': '编辑时间', 'taskNameRequired': '请填写任务名称并选择图空间', 'fileMissing': '{files} 文件不存在,请重新上传文件或添加相关数据源', - 'datasourceMissing': '{files} 所在数据源未找到,请重新添加相关数据源并重新配置任务' + 'datasourceMissing': '{files} 所在数据源未找到,请重新添加相关数据源并重新配置任务', + 'templateRerunTip': '模板导入生成的任务不支持编辑,请直接修改模板文件并导入', + 'rerunError': '找不到任务配置记录,无法重跑任务', + 'editTaskError': '找不到任务配置记录,无法继续编辑' }, 'schema': { 'spaceList': '图空间列表', diff --git a/app/pages/Import/TaskList/TaskItem/index.tsx b/app/pages/Import/TaskList/TaskItem/index.tsx index 63069981..98842e9f 100644 --- a/app/pages/Import/TaskList/TaskItem/index.tsx +++ b/app/pages/Import/TaskList/TaskItem/index.tsx @@ -10,6 +10,7 @@ import { useI18n } from '@vesoft-inc/i18n'; import { observer } from 'mobx-react-lite'; import { useStore } from '@app/stores'; import { useHistory } from 'react-router-dom'; +import { safeParse } from '@app/utils/function'; import ConfigConfirmModal from '../../TaskCreate/ConfigConfirmModal'; import styles from './index.module.less'; interface IProps { @@ -69,6 +70,7 @@ const TaskItem = (props: IProps) => { const time = useRef(''); const timeoutId = useRef(null); const [rerunLoading, setRerunLoading] = useState(false); + const fromTemplate = useMemo(() => rawConfig && typeof safeParse(rawConfig) === 'string', [rawConfig]); const addMsg = () => failedProcessed > 0 && setExtraMsg(intl.get('import.notImported', { total: failedProcessed })); useEffect(() => { window.clearTimeout(timeoutId.current); @@ -99,6 +101,14 @@ const TaskItem = (props: IProps) => { }; const handleEdit = () => { + if (!rawConfig) { + antMsg.info(intl.get('import.editTaskError')); + return; + } + if(fromTemplate) { + antMsg.info(intl.get('import.templateRerunTip')); + return; + } history.push(`/import/edit/${id}`, { id, space, @@ -108,7 +118,11 @@ const TaskItem = (props: IProps) => { }; const handleRerun = () => { - if(needPwdConfirm) { + if(!rawConfig) { + antMsg.info(intl.get('import.rerunError')); + return; + } + if(needPwdConfirm && !fromTemplate) { setVisible(true); return; } @@ -119,19 +133,25 @@ const TaskItem = (props: IProps) => { setVisible(false); setRerunLoading(true); const spaceVidType = await schema.getSpaceVidType(space); - const { basicConfig, tagConfig, edgeConfig } = JSON.parse(rawConfig); - const code = await importTask({ + const config = JSON.parse(rawConfig); + const payload = { name: `task-${Date.now()}`, - config: { + password, + type: 'rerun' + } as any; + if(fromTemplate) { + payload.template = config; + } else { + const { basicConfig, tagConfig, edgeConfig } = config; + payload.config = { space, spaceVidType, basicConfig, tagConfig, edgeConfig - }, - password, - type: 'rerun' - }); + }; + } + const code = await importTask(payload); setRerunLoading(false); if(code === 0) { antMsg.success(intl.get('import.startImporting')); diff --git a/app/pages/Schema/SchemaConfig/List/Search/index.tsx b/app/pages/Schema/SchemaConfig/List/Search/index.tsx index cbf890c6..966f5a94 100644 --- a/app/pages/Schema/SchemaConfig/List/Search/index.tsx +++ b/app/pages/Schema/SchemaConfig/List/Search/index.tsx @@ -22,6 +22,7 @@ const Search = (props: IProps) => { const { schema: { currentSpace } } = useStore(); useEffect(() => { setValue(''); + onSearch(''); }, [location.pathname, currentSpace]); const onChange = useCallback(e => { setValue(e.target.value); diff --git a/app/stores/import.ts b/app/stores/import.ts index 28187898..98064ea8 100644 --- a/app/stores/import.ts +++ b/app/stores/import.ts @@ -238,21 +238,22 @@ export class ImportStore { const { template, name, password, id, config, type } = params; let _config; let rawConfig; - const { basicConfig, tagConfig, edgeConfig, space, spaceVidType } = config; - if(id !== undefined || type === 'rerun' || type === 'rebuild') { + if(template) { + // template import + _config = template; + rawConfig = template; + } else { + const { basicConfig, tagConfig, edgeConfig, space, spaceVidType } = config; + if(id !== undefined || type === 'rerun' || type === 'rebuild') { // id: import an existed draft task // rebuild: edit old task and save as new task // formData: rerun task directly // validate resource,maybe the resource has been deleted - const isValid = await this.validateResource({ tagConfig, edgeConfig }); - if(isValid === false) { - return; + const isValid = await this.validateResource({ tagConfig, edgeConfig }); + if(isValid === false) { + return; + } } - } - if(template) { - // template import - _config = template; - } else { const { username } = this.rootStore.global; _config = configToJson({ ...basicConfig,