-
Notifications
You must be signed in to change notification settings - Fork 62
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
feat: update importer version #502
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import Icon from '@app/components/Icon'; | ||
import { useI18n } from '@vesoft-inc/i18n'; | ||
import { Button, Input, Modal, Table, Popconfirm, Dropdown } from 'antd'; | ||
import { Button, Input, Modal, Table, Popconfirm, Dropdown, message } from 'antd'; | ||
import { v4 as uuidv4 } from 'uuid'; | ||
import React, { useCallback, useEffect, useState } from 'react'; | ||
import { usePapaParse } from 'react-papaparse'; | ||
|
@@ -10,6 +10,7 @@ import { useStore } from '@app/stores'; | |
import { observer, useLocalObservable } from 'mobx-react-lite'; | ||
import { ExclamationCircleFilled } from '@ant-design/icons'; | ||
import { observable } from 'mobx'; | ||
import Checkbox, { CheckboxChangeEvent } from 'antd/lib/checkbox'; | ||
import styles from './index.module.less'; | ||
interface IProps { | ||
visible: boolean; | ||
|
@@ -38,8 +39,8 @@ const UploadConfigModal = (props: IProps) => { | |
data: [], | ||
activeItem: null, | ||
previewContent: [], | ||
// checkAll: false, | ||
// indeterminate: false, | ||
checkAll: false, | ||
indeterminate: false, | ||
loading: false, | ||
uploading: false, | ||
setState: (obj) => Object.assign(state, obj), | ||
Comment on lines
39
to
46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. const localState = useLocalObservable(() => {
const initState = {
......
};
return {
...initState,
setState: (payload: Partial<typeof initState>) => Object.assign(localState, payload),
};
}); |
||
|
@@ -73,36 +74,36 @@ const UploadConfigModal = (props: IProps) => { | |
}); | ||
}, []); | ||
|
||
// const onCheckAllChange = useCallback((e: CheckboxChangeEvent) => { | ||
// const { data, setState } = state; | ||
// const { checked } = e.target; | ||
// setState({ | ||
// checkAll: checked, | ||
// indeterminate: false, | ||
// data: data.map(i => (i.withHeader = checked, i)) | ||
// }); | ||
// }, []); | ||
const onCheckAllChange = useCallback((e: CheckboxChangeEvent) => { | ||
const { data, setState } = state; | ||
const { checked } = e.target; | ||
setState({ | ||
checkAll: checked, | ||
indeterminate: false, | ||
data: data.map(i => (i.withHeader = checked, i)) | ||
}); | ||
}, []); | ||
|
||
// const updateItem = useCallback((e: CheckboxChangeEvent, item: StudioFile) => { | ||
// const { data, setState } = state; | ||
// const { checked } = e.target; | ||
// const nextData = data.map(i => (i === item && (i.withHeader = checked), i)); | ||
// const checkedNum = data.reduce((n, file) => n + (file.withHeader & 1), 0); | ||
// setState({ | ||
// checkAll: checkedNum === data.length, | ||
// indeterminate: !!checkedNum && checkedNum < data.length, | ||
// data: nextData | ||
// }); | ||
// }, []); | ||
const updateItem = useCallback((e: CheckboxChangeEvent, item: StudioFile) => { | ||
const { data, setState } = state; | ||
const { checked } = e.target; | ||
const nextData = data.map(i => (i === item && (i.withHeader = checked), i)); | ||
const checkedNum = data.reduce((n, file) => n + (file.withHeader & 1), 0); | ||
setState({ | ||
checkAll: checkedNum === data.length, | ||
indeterminate: !!checkedNum && checkedNum < data.length, | ||
data: nextData | ||
}); | ||
}, []); | ||
const deletePreviewFile = useCallback((e: React.MouseEvent, index: number) => { | ||
const { activeItem, data, setState, previewContent } = state; | ||
e.stopPropagation(); | ||
const isActive = activeItem?.uid === data[index].uid; | ||
const newData = data.filter((_, i) => i !== index); | ||
// const checkedNum = data.reduce((n, file) => n + (file.withHeader & 1), 0); | ||
const checkedNum = data.reduce((n, file) => n + (file.withHeader & 1), 0); | ||
setState({ | ||
// checkAll: checkedNum === newData.length && newData.length > 0, | ||
// indeterminate: !!checkedNum && checkedNum < newData.length, | ||
checkAll: checkedNum === newData.length && newData.length > 0, | ||
indeterminate: !!checkedNum && checkedNum < newData.length, | ||
data: newData, | ||
activeItem: isActive ? null : activeItem, | ||
previewContent: isActive ? [] : previewContent, | ||
|
@@ -158,6 +159,7 @@ const UploadConfigModal = (props: IProps) => { | |
const res = await uploadFile(data); | ||
if(res.code === 0) { | ||
onConfirm(); | ||
message.success(intl.get('import.uploadSuccessfully')); | ||
} | ||
setState({ uploading: false }); | ||
}, []); | ||
|
@@ -169,7 +171,7 @@ const UploadConfigModal = (props: IProps) => { | |
if(!visible) { | ||
return null; | ||
} | ||
const { uploading, data, activeItem, previewContent, loading, setState } = state; | ||
const { uploading, data, activeItem, previewContent, loading, setState, checkAll, indeterminate } = state; | ||
const parseColumns = previewContent.length | ||
? previewContent[0].map((header, index) => { | ||
const textIndex = index; | ||
|
@@ -185,18 +187,18 @@ const UploadConfigModal = (props: IProps) => { | |
{ | ||
title: intl.get('import.fileName'), | ||
dataIndex: 'name', | ||
// align: 'center' as const, | ||
width: '60%' | ||
align: 'center' as const, | ||
width: '30%' | ||
}, | ||
{ | ||
title: <> | ||
<Checkbox checked={checkAll} indeterminate={indeterminate} onChange={onCheckAllChange} /> | ||
<span style={{ paddingLeft: '5px' }}>{intl.get('import.withHeader')}</span> | ||
</>, | ||
key: 'withHeader', | ||
width: '30%', | ||
render: record => <Checkbox checked={record.withHeader} onChange={e => updateItem(e, record)}>{intl.get('import.hasHeader')}</Checkbox>, | ||
}, | ||
// { | ||
// title: <> | ||
// <Checkbox checked={checkAll} indeterminate={indeterminate} onChange={onCheckAllChange} /> | ||
// <span style={{ paddingLeft: '5px' }}>{intl.get('import.withHeader')}</span> | ||
// </>, | ||
// key: 'withHeader', | ||
// width: '30%', | ||
// render: record => <Checkbox checked={record.withHeader} onChange={e => updateItem(e, record)}>{intl.get('import.hasHeader')}</Checkbox>, | ||
// }, | ||
{ | ||
title: <> | ||
<span>{intl.get('import.delimiter')}</span> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,16 +57,13 @@ const TaskItem = (props: IProps) => { | |
const { intl } = useI18n(); | ||
const [progressStatus, setStatus] = useState<'success' | 'active' | 'normal' | 'exception' | undefined>(undefined); | ||
const [extraMsg, setExtraMsg] = useState(''); | ||
const { totalImportedBytes, totalBytes, numFailed, numReadFailed } = stats || {}; | ||
const { processedBytes, totalBytes, failedProcessed } = stats || {}; | ||
const time = useRef(''); | ||
const timeoutId = useRef<number>(null); | ||
const addMsg = () => { | ||
const info: string[] = []; | ||
if(numFailed > 0) { | ||
info.push(intl.get('import.notImported', { total: numFailed })); | ||
} | ||
if(numReadFailed > 0) { | ||
info.push(intl.get('import.readFailed', { total: numReadFailed })); | ||
if(failedProcessed > 0) { | ||
info.push(intl.get('import.notImported', { total: failedProcessed })); | ||
} | ||
info.length > 0 && setExtraMsg(info.join(', ')); | ||
}; | ||
Comment on lines
63
to
69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unnecessary string list |
||
|
@@ -91,10 +88,10 @@ const TaskItem = (props: IProps) => { | |
}, [status]); | ||
const refreshTime = () => { | ||
if(status === ITaskStatus.StatusProcessing) { | ||
time.current = dayjs.duration(dayjs(Date.now()).diff(dayjs.unix(createTime))).format('HH:mm:ss'); | ||
time.current = dayjs.duration(dayjs(Date.now()).diff(dayjs(createTime))).format('HH:mm:ss'); | ||
timeoutId.current = window.setTimeout(refreshTime, 1000); | ||
} else { | ||
time.current = dayjs.duration(dayjs.unix(updateTime).diff(dayjs.unix(createTime))).format('HH:mm:ss'); | ||
time.current = dayjs.duration(dayjs(updateTime).diff(dayjs(createTime))).format('HH:mm:ss'); | ||
} | ||
}; | ||
Comment on lines
89
to
96
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. trigger per second, but won't cause component rendering |
||
return ( | ||
|
@@ -131,8 +128,8 @@ const TaskItem = (props: IProps) => { | |
</span>} | ||
</span> | ||
<div className={styles.moreInfo}> | ||
{totalImportedBytes > 0 && <span> | ||
{status !== ITaskStatus.StatusFinished && `${getFileSize(totalImportedBytes)} / `} | ||
{processedBytes > 0 && <span> | ||
{status !== ITaskStatus.StatusFinished && `${getFileSize(processedBytes)} / `} | ||
Comment on lines
+131
to
+132
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TaskStatus.Finished |
||
{getFileSize(totalBytes)}{' '} | ||
</span>} | ||
<span>{time.current}</span> | ||
|
@@ -141,7 +138,7 @@ const TaskItem = (props: IProps) => { | |
{stats && <Progress | ||
format={percent => `${percent}%`} | ||
status={progressStatus} | ||
percent={status !== ITaskStatus.StatusFinished ? floor(totalImportedBytes / totalBytes * 100, 2) : 100} | ||
percent={status !== ITaskStatus.StatusFinished ? floor(processedBytes / totalBytes * 100, 2) : 100} | ||
strokeColor={progressStatus && COLOR_MAP[progressStatus]} />} | ||
</div> | ||
<div className={styles.operations}> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.