Skip to content

Commit 25f2458

Browse files
removed binary filesstate
1 parent ec97a9d commit 25f2458

File tree

12 files changed

+73
-137
lines changed

12 files changed

+73
-137
lines changed

frontend/.eslintrc.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,7 @@
101101
"no-octal-escape": "error",
102102
"no-param-reassign": "off", // Off for v1
103103
"no-path-concat": "error",
104-
"no-plusplus": [
105-
"error",
106-
{
107-
"allowForLoopAfterthoughts": true
108-
}
109-
],
104+
"no-plusplus": "off",
110105
"no-proto": "off", // Off for v1
111106
"no-restricted-globals": "error",
112107
"no-return-assign": "error",
@@ -154,7 +149,7 @@
154149
"prefer-spread": "warn",
155150
"prefer-template": "warn",
156151
"radix": "off", // Off for v1
157-
"require-atomic-updates": "error",
152+
"require-atomic-updates": "off",
158153
"require-await": "warn", // Warn for v1
159154
"sort-keys": "off",
160155
"spaced-comment": [

frontend/src/components/Content.tsx

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@ import GraphViewModal from './GraphViewModal';
1313
import { initialiseDriver } from '../utils/Driver';
1414
import Driver from 'neo4j-driver/types/driver';
1515

16-
1716
const Content: React.FC<ContentProps> = ({ isExpanded, showChatBot, openChatBot }) => {
1817
const [init, setInit] = useState<boolean>(false);
1918
const [openConnection, setOpenConnection] = useState<boolean>(false);
2019
const [openGraphView, setOpenGraphView] = useState<boolean>(false);
2120
const [inspectedName, setInspectedName] = useState<string>('');
2221
const [connectionStatus, setConnectionStatus] = useState<boolean>(false);
2322
const { setUserCredentials, userCredentials, driver, setDriver } = useCredentials();
24-
const { filesData, files, setFilesData, setModel, model } = useFileContext();
23+
const { filesData, setFilesData, setModel, model } = useFileContext();
2524
const [errorMessage, setErrorMessage] = useState<string>('');
2625
const [showAlert, setShowAlert] = useState<boolean>(false);
2726
const [viewPoint, setViewPoint] = useState<'tableView' | 'showGraphView'>('tableView');
@@ -65,9 +64,7 @@ const Content: React.FC<ContentProps> = ({ isExpanded, showChatBot, openChatBot
6564
});
6665
}, [model]);
6766

68-
const disableCheck = !files.length || !filesData.some((f) => f.status === 'New');
69-
70-
const disableCheckGraph = !files.length;
67+
const disableCheck = !filesData.some((f) => f.status === 'New');
7168

7269
const handleDropdownChange = (option: OptionType | null | void) => {
7370
if (option?.value) {
@@ -173,8 +170,8 @@ const Content: React.FC<ContentProps> = ({ isExpanded, showChatBot, openChatBot
173170

174171
const handleGenerateGraph = () => {
175172
const data = [];
176-
if (files.length > 0) {
177-
for (let i = 0; i < files.length; i++) {
173+
if (filesData.length > 0) {
174+
for (let i = 0; i < filesData.length; i++) {
178175
if (filesData[i]?.status === 'New') {
179176
data.push(extractData(i));
180177
}
@@ -191,8 +188,9 @@ const Content: React.FC<ContentProps> = ({ isExpanded, showChatBot, openChatBot
191188

192189
const handleOpenGraphClick = () => {
193190
const bloomUrl = process.env.BLOOM_URL;
194-
const connectURL = `${userCredentials?.userName}@${localStorage.getItem('URI')}%3A${localStorage.getItem('port') ?? '7687'
195-
}`;
191+
const connectURL = `${userCredentials?.userName}@${localStorage.getItem('URI')}%3A${
192+
localStorage.getItem('port') ?? '7687'
193+
}`;
196194
const encodedURL = encodeURIComponent(connectURL);
197195
const replacedUrl = bloomUrl?.replace('{CONNECT_URL}', encodedURL);
198196
window.open(replacedUrl, '_blank');
@@ -202,10 +200,10 @@ const Content: React.FC<ContentProps> = ({ isExpanded, showChatBot, openChatBot
202200
isExpanded && showChatBot
203201
? 'contentWithBothDrawers'
204202
: isExpanded
205-
? 'contentWithExpansion'
206-
: showChatBot
207-
? 'contentWithChatBot'
208-
: 'contentWithNoExpansion';
203+
? 'contentWithExpansion'
204+
: showChatBot
205+
? 'contentWithChatBot'
206+
: 'contentWithNoExpansion';
209207

210208
const handleGraphView = () => {
211209
setOpenGraphView(true);
@@ -272,15 +270,15 @@ const Content: React.FC<ContentProps> = ({ isExpanded, showChatBot, openChatBot
272270
Generate Graph
273271
</Button>
274272
<Button
275-
disabled={disableCheckGraph || !filesData.some((f) => f?.status === 'Completed')}
273+
disabled={!filesData.some((f) => f?.status === 'Completed')}
276274
onClick={handleGraphView}
277275
className='mr-0.5'
278276
>
279277
Show Graph
280278
</Button>
281279
<Button
282280
onClick={handleOpenGraphClick}
283-
disabled={disableCheckGraph || !filesData.some((f) => f?.status === 'Completed')}
281+
disabled={!filesData.some((f) => f?.status === 'Completed')}
284282
className='ml-0.5'
285283
>
286284
Open Graph
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ProgressBar } from '@neo4j-ndl/react';
22

33
export default function CustomProgressBar({ value }: { value: number }) {
4-
return <ProgressBar heading={value < 100 ? 'Uploading' : 'Uploaded'} size='small' value={value}></ProgressBar>;
5-
}
4+
return <ProgressBar heading={value < 100 ? 'Uploading ' : 'Uploaded'} size='small' value={value}></ProgressBar>;
5+
}

frontend/src/components/DropZone.tsx

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import { useFileContext } from '../context/UsersFiles';
88
import CustomAlert from './Alert';
99
import { CustomFile, alertState } from '../types';
1010
import { chunkSize } from '../utils/Constants';
11-
import { getFileFromLocal, url } from '../utils/Utils';
11+
import { url } from '../utils/Utils';
1212

1313
const DropZone: FunctionComponent = () => {
14-
const { files, filesData, setFiles, setFilesData, model } = useFileContext();
14+
const { filesData, setFilesData, model } = useFileContext();
1515
const [isLoading, setIsLoading] = useState<boolean>(false);
1616
const [isClicked, setIsClicked] = useState<boolean>(false);
1717
const { userCredentials } = useCredentials();
@@ -36,14 +36,13 @@ const DropZone: FunctionComponent = () => {
3636
type: 'PDF',
3737
model: model,
3838
fileSource: 'local file',
39+
uploadprogess: 0,
3940
};
4041

4142
const copiedFilesData: CustomFile[] = [...filesData];
42-
const copiedFiles: (File | null)[] = [...files];
4343

4444
f.forEach((file) => {
4545
const filedataIndex = copiedFilesData.findIndex((filedataitem) => filedataitem?.name === file?.name);
46-
const fileIndex = copiedFiles.findIndex((filedataitem) => filedataitem?.name === file?.name);
4746
if (filedataIndex == -1) {
4847
copiedFilesData.unshift({
4948
name: file.name,
@@ -64,17 +63,7 @@ const DropZone: FunctionComponent = () => {
6463
fileSource: defaultValues.fileSource,
6564
});
6665
}
67-
if (fileIndex == -1) {
68-
copiedFiles.unshift(file as File);
69-
} else {
70-
const tempFile = copiedFiles[filedataIndex];
71-
copiedFiles.splice(fileIndex, 1);
72-
if (tempFile) {
73-
copiedFiles.unshift(getFileFromLocal(tempFile.name));
74-
}
75-
}
7666
});
77-
setFiles(copiedFiles);
7867
setFilesData(copiedFilesData);
7968
}
8069
};
@@ -105,7 +94,7 @@ const DropZone: FunctionComponent = () => {
10594
const uploadNextChunk = async () => {
10695
if (chunkNumber <= totalChunks) {
10796
const chunk = file.slice(start, end);
108-
console.log({ chunkNumber })
97+
console.log({ chunkNumber });
10998
const formData = new FormData();
11099
formData.append('file', chunk);
111100
formData.append('chunkNumber', chunkNumber.toString());
@@ -128,15 +117,11 @@ const DropZone: FunctionComponent = () => {
128117
})
129118
);
130119
try {
131-
const apiResponse = await axios.post(
132-
`${url()}/upload`,
133-
formData,
134-
{
135-
headers: {
136-
'Content-Type': 'multipart/form-data',
137-
},
138-
}
139-
);
120+
const apiResponse = await axios.post(`${url()}/upload`, formData, {
121+
headers: {
122+
'Content-Type': 'multipart/form-data',
123+
},
124+
});
140125
console.log(apiResponse.data);
141126
if (apiResponse?.data.status === 'Failed') {
142127
throw new Error(`message:${apiResponse.data.message},fileName:${apiResponse.data.file_name}`);
@@ -146,7 +131,7 @@ const DropZone: FunctionComponent = () => {
146131
if (curfile.name == file.name) {
147132
return {
148133
...curfile,
149-
uploadprogess: (chunkNumber) * chunkProgressIncrement,
134+
uploadprogess: chunkNumber * chunkProgressIncrement,
150135
};
151136
}
152137
return curfile;
@@ -155,14 +140,14 @@ const DropZone: FunctionComponent = () => {
155140
chunkNumber++;
156141
start = end;
157142
if (start + chunkSize < file.size) {
158-
end = start + chunkSize
143+
end = start + chunkSize;
159144
} else {
160145
end = file.size + 1;
161146
}
162147
uploadNextChunk();
163148
}
164149
} catch (error) {
165-
setIsLoading(false)
150+
setIsLoading(false);
166151
setalertDetails({
167152
showAlert: true,
168153
alertType: 'error',
@@ -187,7 +172,7 @@ const DropZone: FunctionComponent = () => {
187172
if (curfile.name == file.name) {
188173
return {
189174
...curfile,
190-
status:"New",
175+
status: 'New',
191176
uploadprogess: 100,
192177
};
193178
}
@@ -239,4 +224,4 @@ const DropZone: FunctionComponent = () => {
239224
);
240225
};
241226

242-
export default DropZone;
227+
export default DropZone;

frontend/src/components/FileTable.tsx

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
import { useFileContext } from '../context/UsersFiles';
1414
import { getSourceNodes } from '../services/GetFiles';
1515
import { v4 as uuidv4 } from 'uuid';
16-
import {statusCheck } from '../utils/Utils';
16+
import { statusCheck } from '../utils/Utils';
1717
import { SourceNode, CustomFile, FileTableProps, UserCredentials } from '../types';
1818
import { useCredentials } from '../context/UserCredentials';
1919
import { MagnifyingGlassCircleIconSolid } from '@neo4j-ndl/react/icons';
@@ -74,17 +74,29 @@ const FileTable: React.FC<FileTableProps> = ({ isExpanded, connectionStatus, set
7474
columnHelper.accessor((row) => row.uploadprogess, {
7575
id: 'uploadprogess',
7676
cell: (info: CellContext<CustomFile, string>) => {
77-
if (parseInt(info.getValue()) === 100) {
78-
return <Typography variant='body-medium'><StatusIndicator type="success" />Uploaded</Typography>
79-
} else if (info.row.original?.status === "Uploading") {
80-
return <CustomProgressBar value={parseInt(info?.getValue())}></CustomProgressBar>
81-
} else if (info.row.original?.status === "New") {
82-
return <Typography variant='body-medium'><StatusIndicator type="info" />Not Started</Typography>
83-
} else if (info.row.original?.status === "Failed") {
84-
return <Typography variant='body-medium'><StatusIndicator type="danger" />NA</Typography>
85-
} else {
86-
return <Typography variant='body-medium'><StatusIndicator type="info" />Uploaded</Typography>
77+
if (parseInt(info.getValue()) === 100 || info.row.original?.status === 'New') {
78+
return (
79+
<Typography variant='body-medium'>
80+
<StatusIndicator type='success' />
81+
Uploaded
82+
</Typography>
83+
);
84+
} else if (info.row.original?.status === 'Uploading') {
85+
return <CustomProgressBar value={parseInt(info?.getValue())}></CustomProgressBar>;
86+
} else if (info.row.original?.status === 'Failed') {
87+
return (
88+
<Typography variant='body-medium'>
89+
<StatusIndicator type='danger' />
90+
NA
91+
</Typography>
92+
);
8793
}
94+
return (
95+
<Typography variant='body-medium'>
96+
<StatusIndicator type='success' />
97+
Uploaded
98+
</Typography>
99+
);
88100
},
89101
header: () => <span>Upload Progress</span>,
90102
footer: (info) => info.column.id,
@@ -186,22 +198,22 @@ const FileTable: React.FC<FileTableProps> = ({ isExpanded, connectionStatus, set
186198
item.fileSource === 's3 bucket' && localStorage.getItem('accesskey') === item?.awsAccessKeyId
187199
? item.status
188200
: item.fileSource === 'local file'
189-
? item.status
190-
: item.status === 'Completed' || item.status === 'Failed'
191-
? item.status
192-
: item.fileSource == 'Wikipedia' ||
193-
item.fileSource == 'youtube' ||
194-
item.fileSource == 'gcs bucket'
195-
? item.status
196-
: 'N/A',
201+
? item.status
202+
: item.status === 'Completed' || item.status === 'Failed'
203+
? item.status
204+
: item.fileSource == 'Wikipedia' ||
205+
item.fileSource == 'youtube' ||
206+
item.fileSource == 'gcs bucket'
207+
? item.status
208+
: 'N/A',
197209
model: item?.model ?? model,
198210
id: uuidv4(),
199211
source_url: item.url != 'None' && item?.url != '' ? item.url : '',
200212
fileSource: item.fileSource ?? 'None',
201213
gcsBucket: item?.gcsBucket,
202214
gcsBucketFolder: item?.gcsBucketFolder,
203215
errorMessage: item?.errorMessage,
204-
uploadprogess: item?.uploadprogress ?? 0
216+
uploadprogess: item?.uploadprogress ?? 0,
205217
});
206218
}
207219
});
@@ -265,8 +277,6 @@ const FileTable: React.FC<FileTableProps> = ({ isExpanded, connectionStatus, set
265277
};
266278
}, []);
267279

268-
269-
270280
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
271281
table.getColumn('status')?.setFilterValue(e.target.checked);
272282
};

frontend/src/components/GCSModal.tsx

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@ import { urlScanAPI } from '../services/URLScan';
66
import { CustomFile, S3ModalProps, fileName } from '../types';
77
import { v4 as uuidv4 } from 'uuid';
88
import CustomModal from '../HOC/CustomModal';
9-
import { getFileFromLocal } from '../utils/Utils';
109

1110
const GCSModal: React.FC<S3ModalProps> = ({ hideModal, open }) => {
1211
const [bucketName, setbucketName] = useState<string>('');
1312
const [folderName, setFolderName] = useState<string>('');
1413
const [status, setStatus] = useState<'unknown' | 'success' | 'info' | 'warning' | 'danger'>('unknown');
1514
const [statusMessage, setStatusMessage] = useState<string>('');
1615
const { userCredentials } = useCredentials();
17-
const { setFiles, setFilesData, model, filesData, files } = useFileContext();
16+
const { setFilesData, model, filesData } = useFileContext();
1817
const reset = () => {
1918
setbucketName('');
2019
setFolderName('');
@@ -62,10 +61,8 @@ const GCSModal: React.FC<S3ModalProps> = ({ hideModal, open }) => {
6261
setStatus('success');
6362
setStatusMessage(`Successfully Created Source Nodes for ${apiResponse.data.success_count} Files`);
6463
const copiedFilesData = [...filesData];
65-
const copiedFiles = [...files];
6664
apiResponse?.data?.file_name?.forEach((item: fileName) => {
6765
const filedataIndex = copiedFilesData.findIndex((filedataitem) => filedataitem?.name === item.fileName);
68-
const fileIndex = copiedFiles.findIndex((filedataitem) => filedataitem?.name === item.fileName);
6966
if (filedataIndex == -1) {
7067
copiedFilesData.unshift({
7168
name: item.fileName,
@@ -87,18 +84,8 @@ const GCSModal: React.FC<S3ModalProps> = ({ hideModal, open }) => {
8784
fileSource: defaultValues.fileSource,
8885
});
8986
}
90-
if (fileIndex == -1) {
91-
copiedFiles.unshift(null);
92-
} else {
93-
const tempFile = copiedFiles[filedataIndex];
94-
copiedFiles.splice(fileIndex, 1);
95-
if (tempFile) {
96-
copiedFiles.unshift(getFileFromLocal(tempFile?.name) ?? tempFile);
97-
}
98-
}
9987
});
10088
setFilesData(copiedFilesData);
101-
setFiles(copiedFiles);
10289
reset();
10390
}
10491
} catch (error) {

0 commit comments

Comments
 (0)