Skip to content

Commit 31e815a

Browse files
Handled API for Multiple file upload
1 parent 93b2c20 commit 31e815a

File tree

8 files changed

+84
-67
lines changed

8 files changed

+84
-67
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ __pycache__/
55

66
# C extensions
77
*.so
8-
8+
/backend/graph
99
# Distribution / packaging
1010
.Python
1111
build/

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"uuid": "^9.0.1"
2323
},
2424
"devDependencies": {
25+
"@types/node": "^20.11.10",
2526
"@types/react": "^18.2.15",
2627
"@types/react-dom": "^18.2.7",
2728
"@typescript-eslint/eslint-plugin": "^6.0.0",

frontend/src/components/DropZone.tsx

Lines changed: 55 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -22,59 +22,69 @@ export default function DropZone() {
2222
const [isBackendConnected, setIsBackendConnected] = useState<boolean>(false);
2323
const { userCredentials } = useCredentials();
2424

25-
const fileUpload = async (file: File, uid: string) => {
26-
try {
27-
setIsLoading(true);
28-
setFilesdata((prevfiles) =>
29-
prevfiles.map((curfile) => {
30-
if (curfile.id == uid) {
31-
return {
32-
...curfile,
33-
status: 'Processing',
34-
};
35-
} else {
36-
return curfile;
37-
}
38-
})
39-
);
40-
41-
const apiResponse = await uploadAPI(file, userCredentials);
42-
43-
if (apiResponse.data != 'Failure') {
25+
const fileUpload = async (file: File, uid: number) => {
26+
if (filesdata[uid].status == 'None') {
27+
const apirequests = [];
28+
try {
29+
setIsLoading(true);
4430
setFilesdata((prevfiles) =>
45-
prevfiles.map((curfile) => {
46-
if (curfile.id == uid) {
31+
prevfiles.map((curfile, idx) => {
32+
if (idx == uid) {
4733
return {
4834
...curfile,
49-
processing: apiResponse?.data.processingTime.toFixed(2),
50-
status: apiResponse?.data?.status,
51-
NodesCount: apiResponse?.data?.nodeCount,
52-
relationshipCount: apiResponse?.data?.relationshipCount,
35+
status: 'Processing',
5336
};
5437
} else {
5538
return curfile;
5639
}
5740
})
5841
);
42+
const apiResponse = await uploadAPI(file, userCredentials);
43+
apirequests.push(apiResponse);
44+
Promise.allSettled(apirequests)
45+
.then((r) => {
46+
r.forEach((apiRes) => {
47+
if (apiRes.status === 'fulfilled' && apiRes.value) {
48+
if (apiRes?.value?.data != 'Unexpected Error') {
49+
setFilesdata((prevfiles) =>
50+
prevfiles.map((curfile, idx) => {
51+
if (idx == uid) {
52+
return {
53+
...curfile,
54+
processing: apiRes?.value?.data?.processingTime?.toFixed(2),
55+
status: apiRes?.value?.data?.status,
56+
NodesCount: apiRes?.value?.data?.nodeCount,
57+
relationshipCount: apiRes?.value?.data?.relationshipCount,
58+
};
59+
} else {
60+
return curfile;
61+
}
62+
})
63+
);
64+
setIsLoading(false);
65+
} else {
66+
throw new Error('API Failure');
67+
}
68+
}
69+
});
70+
})
71+
.catch((err) => console.log(err));
72+
} catch (err) {
73+
console.log(err);
5974
setIsLoading(false);
60-
} else {
61-
throw new Error('API Failure');
75+
setFilesdata((prevfiles) =>
76+
prevfiles.map((curfile, idx) => {
77+
if (idx == uid) {
78+
return {
79+
...curfile,
80+
status: 'Failed',
81+
};
82+
} else {
83+
return curfile;
84+
}
85+
})
86+
);
6287
}
63-
} catch (err) {
64-
console.log(err);
65-
setIsLoading(false);
66-
setFilesdata((prevfiles) =>
67-
prevfiles.map((curfile) => {
68-
if (curfile.id == uid) {
69-
return {
70-
...curfile,
71-
status: 'Failed',
72-
};
73-
} else {
74-
return curfile;
75-
}
76-
})
77-
);
7888
}
7989
};
8090

@@ -92,7 +102,9 @@ export default function DropZone() {
92102

93103
useEffect(() => {
94104
if (files.length > 0) {
95-
fileUpload(files[files.length - 1], filesdata[filesdata.length - 1].id);
105+
for (let i = 0; i < files.length; i++) {
106+
fileUpload(files[i], i);
107+
}
96108
}
97109
}, [files]);
98110

frontend/src/components/FileTable.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { DataGrid } from '@neo4j-ndl/react';
22
import { useState, useEffect } from 'react';
33
import { useReactTable, getCoreRowModel, createColumnHelper } from '@tanstack/react-table';
4-
import { formatFileSize } from '../utils/utils';
54

65
interface CustomFile extends Partial<globalThis.File> {
76
processing: string;
@@ -21,7 +20,7 @@ export default function FileTable({ files }: { files: CustomFile[] | [] }) {
2120
}),
2221
columnHelper.accessor((row) => row.size, {
2322
id: 'fileSize',
24-
cell: (info) => <i>{formatFileSize(info.getValue())}</i>,
23+
cell: (info) => <i>{info.getValue()}kb</i>,
2524
header: () => <span>File Size</span>,
2625
footer: (info) => info.column.id,
2726
}),
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import axios from 'axios';
22
import { url } from '../utils/utils';
33
const healthStatus = async () => {
4-
try {
5-
const healthUrl = `${url()}health`;
6-
const response = await axios.get(healthUrl);
7-
return response;
8-
} catch (error) {
9-
console.log('API status error', error);
10-
throw error;
11-
}
12-
};
13-
export { healthStatus };
4+
try {
5+
const healthUrl = `${url()}/health`
6+
const response = await axios.get(healthUrl);
7+
return response
8+
} catch (error) {
9+
console.log("API status error", error)
10+
throw error
11+
}
12+
}
13+
export {healthStatus}

frontend/src/services/Upload.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@ const uploadAPI = async (file: any, userCredentials: any) => {
55
console.log('check URL', url());
66
try {
77
const formData = new FormData();
8-
98
formData.append('file', file);
109
formData.append('uri', userCredentials?.uri);
1110
formData.append('userName', userCredentials?.userName);
1211
formData.append('password', userCredentials?.password);
13-
14-
const response = await axios.post(`${url()}extract`, formData, {
12+
const response = await axios.post(`${url()}/extract`, formData, {
1513
headers: {
1614
'Content-Type': 'multipart/form-data',
1715
},

frontend/src/utils/utils.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@ export const url = () => {
22
if (process.env.BACKEND_API_URL !== undefined) {
33
return process.env.BACKEND_API_URL;
44
}
5-
6-
const origin = window.location.origin.split('-');
7-
origin[origin.length - 1] = '8000';
8-
const finalURL = `${origin.join('-')}.app.github.dev`;
9-
return finalURL;
105
};
116

127
export const formatFileSize = (bytes: any) => {

frontend/yarn.lock

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1892,6 +1892,13 @@
18921892
resolved "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz"
18931893
integrity sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==
18941894

1895+
"@types/node@^20.11.10":
1896+
version "20.11.10"
1897+
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.11.10.tgz#6c3de8974d65c362f82ee29db6b5adf4205462f9"
1898+
integrity sha512-rZEfe/hJSGYmdfX9tvcPMYeYPW2sNl50nsw4jZmRcaG0HIAb0WYEpsB05GOb53vjqpyE9GUhlDQ4jLSoB5q9kg==
1899+
dependencies:
1900+
undici-types "~5.26.4"
1901+
18951902
"@types/parse-json@^4.0.0":
18961903
version "4.0.2"
18971904
resolved "https://registry.npmjs.org/@types/parse-json/-/parse-json-4.0.2.tgz"
@@ -1942,7 +1949,7 @@
19421949

19431950
"@types/uuid@^9.0.7":
19441951
version "9.0.7"
1945-
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-9.0.7.tgz#b14cebc75455eeeb160d5fe23c2fcc0c64f724d8"
1952+
resolved "https://registry.npmjs.org/@types/uuid/-/uuid-9.0.7.tgz"
19461953
integrity sha512-WUtIVRUZ9i5dYXefDEAI7sh9/O7jGvHg7Df/5O/gtH3Yabe5odI3UWopVR1qbPXQtvOxWu3mM4XxlYeZtMWF4g==
19471954

19481955
"@typescript-eslint/eslint-plugin@^6.0.0":
@@ -4524,6 +4531,11 @@ unbox-primitive@^1.0.2:
45244531
has-symbols "^1.0.3"
45254532
which-boxed-primitive "^1.0.2"
45264533

4534+
undici-types@~5.26.4:
4535+
version "5.26.5"
4536+
resolved "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz"
4537+
integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==
4538+
45274539
update-browserslist-db@^1.0.13:
45284540
version "1.0.13"
45294541
resolved "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.0.13.tgz"
@@ -4566,12 +4578,12 @@ usehooks-ts@2.9.1:
45664578

45674579
uuid@^9.0.1:
45684580
version "9.0.1"
4569-
resolved "https://registry.yarnpkg.com/uuid/-/uuid-9.0.1.tgz#e188d4c8853cc722220392c424cd637f32293f30"
4581+
resolved "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz"
45704582
integrity sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==
45714583

45724584
vite@^4.4.5:
45734585
version "4.5.2"
4574-
resolved "https://registry.yarnpkg.com/vite/-/vite-4.5.2.tgz#d6ea8610e099851dad8c7371599969e0f8b97e82"
4586+
resolved "https://registry.npmjs.org/vite/-/vite-4.5.2.tgz"
45754587
integrity sha512-tBCZBNSBbHQkaGyhGCDUGqeo2ph8Fstyp6FMSvTtsXeZSPpSMGlviAOav2hxVTqFcx8Hj/twtWKsMJXNY0xI8w==
45764588
dependencies:
45774589
esbuild "^0.18.10"

0 commit comments

Comments
 (0)