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 import & file model #229

Merged
merged 1 commit into from
May 26, 2022
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
60 changes: 28 additions & 32 deletions app/config/service.ts
Original file line number Diff line number Diff line change
@@ -1,61 +1,57 @@
import { _delete, get, post, put } from '../utils/http';

let service = {
execNGQL: (params, config?) => {
return post('/api-nebula/db/exec')(params, config)
const service = {
execNGQL: (params, config?) => {
return post('/api-nebula/db/exec')(params, config);
},
batchExecNGQL: (params, config?) => {
return post('/api-nebula/db/batchExec')(params, config)
return post('/api-nebula/db/batchExec')(params, config);
},
connectDB: (params, config?) => {
return post('/api-nebula/db/connect')(params, config)
return post('/api-nebula/db/connect')(params, config);
},
disconnectDB: (params, config?) => {
return post('/api-nebula/db/disconnect')(params, config)
return post('/api-nebula/db/disconnect')(params, config);
},
// import
importData: (params, config?) => {
return post('/api/import-tasks/import')(params, config)
return post('/api/import-tasks')(params, config);
},
handleImportAction: (params, config?) => {
return post('/api/import-tasks/action')(params, config)
stopImportTask: (id: number) => {
return post(`/api/import-tasks/${id}/stop`)();
},
getLog: (params, config?) => {
return get('/api/import-tasks/logs')(params, config)
deleteImportTask: (id: number) => {
return post(`/api/import-tasks/${id}/stop`)();
},
getErrLog: (params, config?) => {
return get('/api/import-tasks/err-logs')(params, config)
getTaskList: (params?, config?) => {
return get('/api/import-tasks')(params, config);
},
finishImport: (params, config?) => {
return post('/api/import/finish')(params, config)
},
getUploadDir: () => {
return get('/api/import-tasks/working-dir')()
getTaskLogs: (params?, config?) => {
const { id, ...others } = params;
return get(`/api/import-tasks/${id}/task-log-names`)(others, config);
},
getTaskDir: () => {
return get('/api/import-tasks/task-dir')()
getLogDetail: (params, config?) => {
const { id, ...others } = params;
return get(`/api/import-tasks/${id}/logs`)(others, config);
},
deteleFile:params => {
getTaskConfig: (id: string | number) => `/api/import-tasks/${id}/download-config`,
getTaskLog: (id: string | number) => `/api/import-tasks/${id}/download-logs`,
// files
deteleFile: params => {
const { filename } = params;
return _delete(`/api/files/${filename}`)();
},
getFiles: () => {
return get('/api/files')()
return get('/api/files')();
},
uploadFiles: (params?, config?) => {
put('/api/files')(params, { ...config, headers: { 'Content-Type': 'multipart/form-data' } });
},
getTaskLogs: (params?, config?) => {
const { id, ...others } = params;
return get(`/api/import-tasks/${id}/task-log-names`)(others, config);
},
getTaskConfigUrl: (id: string | number) => `/api/import-tasks/config/${id}`,
getTaskLogUrl: (id: string | number) => `/api/import-tasks/${id}/log`,
getTaskErrLogUrl: (id: string | number) => `/api/import-tasks/${id}/err-logs`,
}
};

export const updateService = (partService: any) => {
Object.assign(service, partService)
}
Object.assign(service, partService);
};

export default service;

12 changes: 6 additions & 6 deletions app/interfaces/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ export interface ITaskStats {
numReadFailed: number;
}
export interface ITaskItem {
taskID: number;
nebulaAddress: string;
id: number;
address: string;
space: string;
name: string;
createdTime: number;
updatedTime: number;
createTime: number;
updateTime: number;
user: string;
taskStatus: ITaskStatus;
taskMessage: string;
status: ITaskStatus;
message: string;
stats: ITaskStats;
}

Expand Down
31 changes: 12 additions & 19 deletions app/pages/Import/FileUpload/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,48 @@ import React, { useEffect, useState } from 'react';
import { observer } from 'mobx-react-lite';
import { useStore } from '@app/stores';
import { trackPageView } from '@app/utils/stat';
import FileList from './FileList';
import { debounce } from 'lodash';
import { message } from 'antd';
import intl from 'react-intl-universal';
interface IProps {
needFileDir: boolean
}
import FileList from './FileList';

const FileUpload = (props: IProps) => {
const FileUpload = () => {
const { files } = useStore();
const { fileList, uploadDir, deleteFile, getFiles, uploadFile, getUploadDir } = files;
const { fileList, deleteFile, getFiles, uploadFile } = files;
const [loading, setLoading] = useState(false);
const { needFileDir = true } = props;
const transformFile = async (_file, fileList) => {
fileList.forEach(file => {
if(needFileDir) {
file.path = `${uploadDir}/${file.name}`;
}
file.path = `${file.name}`;
file.withHeader = false;
})
await handleUpdate(fileList)
return false
});
await handleUpdate(fileList);
return false;
};

const handleUpdate = async (fileList: any) => {
setLoading(true);
await uploadFile(fileList).then(_ => {
setTimeout(() => {
getFileList();
message.success(intl.get('import.uploadSuccessfully'))
}, 2000)
message.success(intl.get('import.uploadSuccessfully'));
}, 2000);
}).catch(_err => {
setLoading(false);
});
};

const handleDelete = async (index: number) => {
const file = fileList[index].name;
await deleteFile(file)
}
await deleteFile(file);
};

const getFileList = async () => {
!loading && setLoading(true);
await getFiles();
setLoading(false);
}
};
useEffect(() => {
getFileList();
needFileDir && getUploadDir();
trackPageView('/import/files');
}, []);
return (
Expand Down
14 changes: 9 additions & 5 deletions app/pages/Import/TaskCreate/FileSelect/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Button, Form, Popover, Select } from 'antd';
import React, { useEffect, useState } from 'react';
import React, { useState } from 'react';
import intl from 'react-intl-universal';
import { observer } from 'mobx-react-lite';
import { useStore } from '@app/stores';
Expand Down Expand Up @@ -42,9 +42,13 @@ const FileSelect = (props: IProps) => {
}
setVisible(false);
};
useEffect(() => {
getFiles();
}, []);

const handleGetFiles = () => {
if(fileList.length === 0) {
getFiles();
}
};

return (
<Popover
destroyTooltipOnHide={true}
Expand All @@ -54,7 +58,7 @@ const FileSelect = (props: IProps) => {
onVisibleChange={visible => setVisible(visible)}
content={<Form className={styles.fileSelectForm} onFinish={onFinish} layout="inline">
<FormItem name="name" rules={[{ required: true }]}>
<Select className={styles.fileSelect} showSearch={true} dropdownMatchSelectWidth={false}>
<Select className={styles.fileSelect} showSearch={true} onDropdownVisibleChange={handleGetFiles} dropdownMatchSelectWidth={false}>
{fileList.map((file: any) => (
<Option value={file.name} key={file.name}>
{file.name}
Expand Down
2 changes: 1 addition & 1 deletion app/pages/Import/TaskCreate/PasswordInputModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const PasswordInputModal = (props: IProps) => {
const handleCancel = () => {
setPassword('');
onCancel();
}
};
return (
<Modal
title={intl.get('import.enterPassword')}
Expand Down
30 changes: 15 additions & 15 deletions app/pages/Import/TaskCreate/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ const formItemLayout = {

interface IProps {
needPwdConfirm?: boolean;
mode?: string
}
const TaskCreate = (props: IProps) => {
const { dataImport, schema } = useStore();
const { getTaskDir, basicConfig, verticesConfig, edgesConfig, updateBasicConfig, importTask } = dataImport;
const { dataImport, schema, files } = useStore();
const { basicConfig, verticesConfig, edgesConfig, updateBasicConfig, importTask } = dataImport;
const { spaces, getSpaces, updateSpaceInfo, currentSpace } = schema;
const { getFiles } = files;
const { batchSize } = basicConfig;
const [modalVisible, setVisible] = useState(false);
const history = useHistory();
const { needPwdConfirm = true, mode = 'local' } = props;
const { needPwdConfirm = true } = props;
const routes = [
{
path: '/import/tasks',
Expand Down Expand Up @@ -107,33 +107,33 @@ const TaskCreate = (props: IProps) => {
}
};

const clearConfig = () => {
dataImport.update({
basicConfig: { taskName: '' },
const clearConfig = (type?: string) => {
const params = {
verticesConfig: [],
edgesConfig: []
});
} as any;
if(type === 'all') {
params.basicConfig = { taskName: '' };
}
dataImport.update(params);
};
const handleSpaceChange = (space: string) => {
clearConfig();
updateSpaceInfo(space);
};

const initTaskDir = async () => {
const dir = await getTaskDir();
if(dir) {
const count = dir.split('/').pop();
updateBasicConfig('taskName', `task-${count}`);
}
updateBasicConfig('taskName', `task-${Date.now()}`);
};
useEffect(() => {
mode === 'local' && initTaskDir();
initTaskDir();
getSpaces();
getFiles();
if(currentSpace) {
updateSpaceInfo(currentSpace);
}
trackPageView('/import/create');
return () => clearConfig();
return () => clearConfig('all');
}, []);
return (
<div className={styles.importCreate}>
Expand Down
20 changes: 7 additions & 13 deletions app/pages/Import/TaskList/TaskItem/LogModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ interface ILogDimension {
status: ITaskStatus;
}

interface ILog {
name: string;
}
interface IProps {
logDimension: ILogDimension;
visible: boolean;
Expand All @@ -25,15 +22,15 @@ interface IProps {
}
const LogModal = (props: IProps) => {
const { visible, onCancel, showLogDownload, logDimension: { space, id, status } } = props;
const { dataImport: { getLogs, downloadTaskLog, getImportLogDetail, getErrLogDetail } } = useStore();
const { dataImport: { getLogs, downloadTaskLog, getLogDetail } } = useStore();
const logRef = useRef<HTMLDivElement>(null);
const timer = useRef<any>(null);
const offset = useRef(0);
const _status = useRef(status);
const [logs, setLogs] = useState<ILog[]>([]);
const [currentLog, setCurrentLog] = useState<ILog | null>(null);
const [logs, setLogs] = useState<string[]>([]);
const [currentLog, setCurrentLog] = useState<string | null>(null);
const handleTabChange = (key: string) => {
setCurrentLog(logs.filter(item => item.name === key)[0]);
setCurrentLog(logs.filter(item => item === key)[0]);
};

const getAllLogs = async () => {
Expand All @@ -46,22 +43,19 @@ const LogModal = (props: IProps) => {

const handleLogDownload = () => {
if(currentLog) {
const type = currentLog!.name === 'import.log' ? 'import' : 'err';
downloadTaskLog({
id,
type,
name: currentLog.name
name: currentLog
});
}
};

const readLog = async () => {
const getLogDetail = currentLog!.name === 'import.log' ? getImportLogDetail : getErrLogDetail;
const res = await getLogDetail({
offset: offset.current,
id,
limit: 500,
name: currentLog!.name
file: currentLog
});
handleLogData(res);
};
Expand Down Expand Up @@ -125,7 +119,7 @@ const LogModal = (props: IProps) => {
>
<Tabs className={styles.logTab} tabBarGutter={0} tabPosition="left" onChange={handleTabChange}>
{logs.map(log => (
<TabPane tab={`${log.name}`} key={log.name} />
<TabPane tab={log} key={log} />
))}
</Tabs>
<div className={styles.logContainer} ref={logRef}/>
Expand Down
Loading