Skip to content

Commit 1e85de9

Browse files
authored
Merge pull request #727 from xuewenjie123/fix-upfile-graphModel
Fix upfile graph model
2 parents c3c10dd + 1d68e53 commit 1e85de9

File tree

8 files changed

+67
-22
lines changed

8 files changed

+67
-22
lines changed

packages/studio-components/src/EmptyCanvas/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { EmptyCanvas } from '@graphscope/studio-components';
66
export default () => {
77
return (
88
<div>
9-
<EmptyCanvas />
9+
<EmptyCanvas description="This is a empty canvas"/>
1010
</div>
1111
);
1212
};

packages/studio-components/src/ImportFiles/index.tsx

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { forwardRef, useState, LegacyRef } from 'react';
1+
import React, { forwardRef, useState, LegacyRef, useEffect } from 'react';
22
import UploadFile from './update-file';
33
import { Button, Collapse, Space, Typography } from 'antd';
44
import Mapping from './mapping';
@@ -12,6 +12,7 @@ export interface IState {
1212
files: ParsedFile[];
1313
loading: boolean;
1414
csvFiles: File[];
15+
completed: boolean;
1516
}
1617

1718
export interface IImportFromFileProps {
@@ -33,11 +34,21 @@ const ImportFromCSV = forwardRef((props: IImportFromFileProps, ref: LegacyRef<HT
3334
files: [],
3435
loading: false,
3536
csvFiles: [],
37+
completed: false
3638
});
3739

38-
const { files } = state;
40+
const { files } = state;
41+
const handleAllCompleted = () => {
42+
setState(preState => {
43+
return {
44+
...preState,
45+
completed: true,
46+
};
47+
});
48+
};
49+
50+
3951
const onChange = (value: ParsedFile[], csvFiles?: File[]) => {
40-
console.log(value);
4152
setState(preState => {
4253
return {
4354
...preState,
@@ -53,12 +64,24 @@ const ImportFromCSV = forwardRef((props: IImportFromFileProps, ref: LegacyRef<HT
5364
...preState,
5465
files: [],
5566
csvFiles: [],
67+
completed: false,
5668
};
5769
});
5870
localforage.setItem('DRAFT_GRAPH_FILES', []);
5971
};
6072
const isEmpty = files.length === 0;
6173

74+
useEffect(() => {
75+
if(isEmpty){
76+
setState(preState => {
77+
return {
78+
...preState,
79+
completed: false,
80+
};
81+
});
82+
}
83+
}, [isEmpty]);
84+
6285
const items = files.map((item, index) => {
6386
const { meta, id } = item;
6487
return {
@@ -96,7 +119,7 @@ const ImportFromCSV = forwardRef((props: IImportFromFileProps, ref: LegacyRef<HT
96119
}}
97120
>
98121
{isEmpty ? (
99-
<UploadFile isSaveFiles={isSaveFiles} onChange={onChange} {...upload} />
122+
<UploadFile onAllCompleted={handleAllCompleted} isSaveFiles={isSaveFiles} onChange={onChange} {...upload} />
100123
) : (
101124
<>
102125
{/* <Typography.Text type="secondary">fffdsaf</Typography.Text> */}

packages/studio-components/src/ImportFiles/mapping-header.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ interface IMappingHeaderProps {
1414
files: ParsedFile[];
1515
loading: boolean;
1616
csvFiles: File[];
17+
completed: boolean;
1718
}>
1819
>;
1920
meta: IMeta;

packages/studio-components/src/ImportFiles/mapping.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ interface IMappingProps {
1111
files: ParsedFile[];
1212
loading: boolean;
1313
csvFiles: File[];
14+
completed: boolean;
1415
}>
1516
>;
1617

packages/studio-components/src/ImportFiles/update-file.tsx

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,43 @@ const { Dragger } = Upload;
1010
export type IProps = {
1111
onChange?: (value: ParsedFile[], csvFiles?: File[]) => void;
1212
isSaveFiles?: boolean;
13+
onAllCompleted?: () => void; // 新增:所有文件上传完成后的回调
1314
} & Pick<IImportFromFileProps['upload'], 'accept' | 'description' | 'title'>;
1415

15-
const UploadFile = ({ onChange, accept, title, description, isSaveFiles }: IProps) => {
16+
const UploadFile = ({ onChange, accept, title, description, isSaveFiles, onAllCompleted }: IProps) => {
17+
const activePromises = React.useRef<Promise<void>[]>([]);
1618
const customRequest: UploadProps['customRequest'] = async options => {
1719
const { file } = options;
1820
const { type } = file as File;
1921

20-
try {
21-
if (type === 'application/json') {
22-
const files = await parseJSON(file as File);
23-
onChange && onChange(files);
22+
const uploadPromise = (async () => {
23+
try {
24+
if (type === 'application/json') {
25+
const files = await parseJSON(file as File);
26+
if(onChange){
27+
onChange(files);
28+
}
29+
}
30+
if (type === 'text/csv') {
31+
const csvFiles = isSaveFiles ? [file] : [];
32+
const files = await parseCSV(file as File);
33+
if(onChange){
34+
onChange([files], csvFiles as File[]);
35+
}
36+
}
37+
} catch (error) {
38+
console.error('解析文件失败:', error);
2439
}
25-
if (type === 'text/csv') {
26-
const csvFiles = isSaveFiles ? [file] : [];
27-
const files = await parseCSV(file as File);
28-
onChange && onChange([files], csvFiles as File[]);
40+
})();
41+
activePromises.current.push(uploadPromise);
42+
43+
uploadPromise.finally(() => {
44+
activePromises.current = activePromises.current.filter(p => p !== uploadPromise);
45+
if (activePromises.current.length === 0 && onAllCompleted) {
46+
onAllCompleted();
2947
}
30-
} catch (error) {
31-
console.error('解析文件失败:', error);
32-
}
48+
});
49+
return uploadPromise;
3350
};
3451
const onDrop = e => {
3552
console.log('Dropped files', e.dataTransfer.files);

packages/studio-components/src/Importor/index.zh-CN.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default () => {
2121
return { nodes: [], edges: [] };
2222
};
2323
return (
24-
<div style={{ position: 'relative', height: '400px' }}>
24+
<div >
2525
<ImportorApp
2626
/** 属性下拉选项值 */
2727
queryPrimitiveTypes={() => {
@@ -50,7 +50,7 @@ export default () => {
5050
return { nodes: [], edges: [] };
5151
};
5252
return (
53-
<div style={{ position: 'relative', height: '400px' }}>
53+
<div>
5454
<ImportorApp
5555
/** 属性下拉选项值 */
5656
queryPrimitiveTypes={() => {

packages/studio-components/src/SideTabs/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
```jsx
44
import React, { useState } from 'react';
55
import { Space } from 'antd';
6-
import { SegmentedTabs } from '@graphscope/studio-components';
6+
import { SideTabs } from '@graphscope/studio-components';
77
const Tab1 = () => {
88
return <div>Tab-1 components</div>;
99
};
@@ -33,7 +33,7 @@ export default () => {
3333
];
3434
return (
3535
<div>
36-
<Sidebar options={items} value="Tab-1" collapse={false} />
36+
<SideTabs items={items} />
3737
</div>
3838
);
3939
};

packages/studio-importor/src/app/import-schema/import-from-csv/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { transform } from './transform';
66
import { Button } from 'antd';
77
import localforage from 'localforage';
88
import { FormattedMessage } from 'react-intl';
9+
10+
911
interface IImportFromCSVProps {
1012
onCallback?: () => void;
1113
}
@@ -18,6 +20,7 @@ const ImportFromCSV: React.FunctionComponent<IImportFromCSVProps> = props => {
1820
params: {
1921
files: ParsedFile[];
2022
csvFiles: File[];
23+
completed: boolean;
2124
},
2225
updateState,
2326
) => {
@@ -67,7 +70,7 @@ const ImportFromCSV: React.FunctionComponent<IImportFromCSVProps> = props => {
6770
>
6871
{(params, updateState) => {
6972
return (
70-
<Button type="primary" onClick={() => onSubmit(params, updateState)} loading={params.loading}>
73+
<Button type="primary" onClick={() => onSubmit(params, updateState)} loading={!params.completed||params.loading}>
7174
<FormattedMessage id="Generate graph model" />
7275
</Button>
7376
);

0 commit comments

Comments
 (0)