Skip to content

Commit 854faf1

Browse files
Merge pull request #125 from neo4j-labs/update-graph-inmplementation
Update graph implementation
2 parents b7ec837 + d42ba3f commit 854faf1

File tree

4 files changed

+77
-49
lines changed

4 files changed

+77
-49
lines changed

frontend/src/HOC/CustomModal.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const CustomModal: React.FC<CustomModalProps> = ({
1111
status,
1212
setStatus,
1313
}) => {
14+
const isDisabled = status === 'danger' || status === 'info' || status === 'warning' || status === 'success';
1415
return (
1516
<Dialog
1617
size='small'
@@ -36,7 +37,7 @@ const CustomModal: React.FC<CustomModalProps> = ({
3637
<Button color='neutral' fill='outlined' onClick={onClose} size='medium'>
3738
Cancel
3839
</Button>
39-
<Button onClick={submitHandler} size='medium'>
40+
<Button onClick={submitHandler} size='medium' disabled={isDisabled}>
4041
{submitLabel}
4142
</Button>
4243
</Dialog.Actions>

frontend/src/components/Content.tsx

Lines changed: 43 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { useFileContext } from '../context/UsersFiles';
99
import CustomAlert from './Alert';
1010
import { extractAPI } from '../utils/FileAPI';
1111
import { ContentProps } from '../types';
12+
import { updateGraphAPI } from '../services/UpdateGraph';
1213

1314
const Content: React.FC<ContentProps> = ({ isExpanded }) => {
1415
const [init, setInit] = useState<boolean>(false);
@@ -60,7 +61,6 @@ const Content: React.FC<ContentProps> = ({ isExpanded }) => {
6061

6162
const extractData = async (file: File, uid: number) => {
6263
if (filesData[uid]?.status == 'New') {
63-
const apirequests = [];
6464
try {
6565
setFilesData((prevfiles) =>
6666
prevfiles.map((curfile, idx) => {
@@ -83,46 +83,39 @@ const Content: React.FC<ContentProps> = ({ isExpanded }) => {
8383
filesData[uid].max_sources,
8484
filesData[uid].wiki_query ?? ''
8585
);
86-
apirequests.push(apiResponse);
87-
const results = await Promise.allSettled(apirequests);
88-
results.forEach(async (apiRes) => {
89-
if (apiRes.status === 'fulfilled' && apiRes.value) {
90-
if (apiRes?.value?.status === 'Failed') {
91-
console.log('Error', apiRes?.value);
92-
setShowAlert(true);
93-
setErrorMessage(apiRes?.value?.message);
94-
setFilesData((prevfiles) =>
95-
prevfiles.map((curfile, idx) => {
96-
if (idx == uid) {
97-
return {
98-
...curfile,
99-
status: 'Failed',
100-
};
101-
}
102-
return curfile;
103-
})
104-
);
105-
throw new Error(apiRes?.value?.message);
106-
} else {
107-
setFilesData((prevfiles) => {
108-
return prevfiles.map((curfile, idx) => {
109-
if (idx == uid) {
110-
const apiResponse = apiRes?.value?.data;
111-
return {
112-
...curfile,
113-
processing: apiResponse?.processingTime?.toFixed(2),
114-
status: apiResponse?.status,
115-
NodesCount: apiResponse?.nodeCount,
116-
relationshipCount: apiResponse?.relationshipCount,
117-
model: apiResponse?.model,
118-
};
119-
}
120-
return curfile;
121-
});
122-
});
123-
}
124-
}
125-
});
86+
if (apiResponse?.data?.status === 'Failed') {
87+
setShowAlert(true);
88+
setErrorMessage(apiResponse?.data?.message);
89+
setFilesData((prevfiles) =>
90+
prevfiles.map((curfile, idx) => {
91+
if (idx == uid) {
92+
return {
93+
...curfile,
94+
status: 'Failed',
95+
};
96+
}
97+
return curfile;
98+
})
99+
);
100+
throw new Error(apiResponse?.data?.message);
101+
} else {
102+
setFilesData((prevfiles) => {
103+
return prevfiles.map((curfile, idx) => {
104+
if (idx == uid) {
105+
const apiRes = apiResponse?.data;
106+
return {
107+
...curfile,
108+
processing: apiRes?.processingTime?.toFixed(2),
109+
status: apiRes?.status,
110+
NodesCount: apiRes?.nodeCount,
111+
relationshipCount: apiRes?.relationshipCount,
112+
model: apiRes?.model,
113+
};
114+
}
115+
return curfile;
116+
});
117+
});
118+
}
126119
} catch (err: any) {
127120
console.log(err);
128121
setShowAlert(true);
@@ -142,23 +135,26 @@ const Content: React.FC<ContentProps> = ({ isExpanded }) => {
142135
}
143136
};
144137

145-
const handleGenerateGraph = () => {
138+
const handleGenerateGraph = async () => {
139+
const data = [];
146140
if (files.length > 0) {
147141
for (let i = 0; i < files.length; i++) {
148-
if (filesData[i].status === 'New') {
149-
extractData(files[i], i);
142+
if (filesData[i]?.status === 'New') {
143+
data.push(extractData(files[i], i));
150144
}
151145
}
146+
Promise.allSettled(data).then(async (_) => {
147+
await updateGraphAPI(userCredentials);
148+
});
152149
}
153150
};
154151

155152
const handleClose = () => {
156153
setShowAlert(false);
157154
};
158155

159-
const openGraphUrl = `${process.env.BLOOM_URL}${userCredentials?.userName}@${localStorage.getItem('hostname')}%3A${
160-
localStorage.getItem('port') ?? '7687'
161-
}&search=Show+me+a+graph`;
156+
const openGraphUrl = ` https://bloom-latest.s3.eu-west-2.amazonaws.com/assets/index.html?connectURL=${userCredentials?.userName}@${localStorage.getItem('hostname')}%3A${localStorage.getItem('port') ?? '7687'
157+
}&search=Show+me+a+graph`;
162158

163159
const classNameCheck = isExpanded ? 'contentWithExpansion' : 'contentWithNoExpansion';
164160
return (

frontend/src/components/FileTable.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,15 @@ const FileTable: React.FC<FileTableProps> = ({ isExpanded, connectionStatus, set
3939
const sourceFindVal = sourceFind(info.getValue());
4040
return (
4141
<div className='textellipsis'>
42-
<span title={sourceFindVal?.fileSource === 's3 bucket' ? sourceFindVal?.source_url : info.getValue()}>
42+
<span
43+
title={
44+
sourceFindVal?.fileSource === 's3 bucket'
45+
? sourceFindVal?.source_url
46+
: sourceFindVal?.fileSource === 'youtube'
47+
? sourceFindVal?.source_url
48+
: info.getValue()
49+
}
50+
>
4351
{info.getValue()}
4452
</span>
4553
</div>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import axios from 'axios';
2+
import { url } from '../utils/Utils';
3+
4+
const updateGraphAPI = async (userCredentials: any) => {
5+
try {
6+
const formData = new FormData();
7+
formData.append('uri', userCredentials?.uri ?? '');
8+
formData.append('database', userCredentials?.database ?? '');
9+
formData.append('userName', userCredentials?.userName ?? '');
10+
formData.append('password', userCredentials?.password ?? '');
11+
const response: any = await axios.post(`${url()}/update_similarity_graph`, userCredentials, {
12+
headers: {
13+
'Content-Type': 'multipart/form-data',
14+
},
15+
});
16+
return response;
17+
} catch (error) {
18+
console.log('Error uploading file:', error);
19+
throw error;
20+
}
21+
};
22+
23+
export { updateGraphAPI };

0 commit comments

Comments
 (0)