Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix the problem of editing or rerunning tasks #566

Merged
merged 3 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion app/config/locale/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
5 changes: 4 additions & 1 deletion app/config/locale/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,10 @@ export default {
'modifyTime': '编辑时间',
'taskNameRequired': '请填写任务名称并选择图空间',
'fileMissing': '{files} 文件不存在,请重新上传文件或添加相关数据源',
'datasourceMissing': '{files} 所在数据源未找到,请重新添加相关数据源并重新配置任务'
'datasourceMissing': '{files} 所在数据源未找到,请重新添加相关数据源并重新配置任务',
'templateRerunTip': '模板导入生成的任务不支持编辑,请直接修改模板文件并导入',
'rerunError': '找不到任务配置记录,无法重跑任务',
'editTaskError': '找不到任务配置记录,无法继续编辑'
},
'schema': {
'spaceList': '图空间列表',
Expand Down
36 changes: 28 additions & 8 deletions app/pages/Import/TaskList/TaskItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -69,6 +70,7 @@ const TaskItem = (props: IProps) => {
const time = useRef('');
const timeoutId = useRef<number>(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);
Expand Down Expand Up @@ -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,
Expand All @@ -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;
}
Expand All @@ -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'));
Expand Down
1 change: 1 addition & 0 deletions app/pages/Schema/SchemaConfig/List/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
21 changes: 11 additions & 10 deletions app/stores/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down