@@ -17,7 +17,11 @@ import {
17
17
selectMarking ,
18
18
selectMid ,
19
19
selectName ,
20
+ selectParser ,
20
21
selectPid ,
22
+ selectProgress ,
23
+ selectProgressStatus ,
24
+ selectRemotePath ,
21
25
selectScaleInputs ,
22
26
selectTab ,
23
27
setAttributes ,
@@ -26,6 +30,8 @@ import {
26
30
setLoading ,
27
31
setMid ,
28
32
setPid ,
33
+ setProgress ,
34
+ setProgressStatus ,
29
35
setTabName ,
30
36
TabNames ,
31
37
} from "./wizard-store/reducers/cCAWizardSlice" ;
@@ -46,6 +52,7 @@ export const useCCAWizardFooter = () => {
46
52
const authInfo = useAppSelector ( selectAuthInfo ) ;
47
53
const dispatch = useAppDispatch ( ) ;
48
54
const uploadSelection = useUploadSelection ( ) ;
55
+ const uploadHandleRemoteFileSubmit = useHandleRemoteFileSubmit ( ) ;
49
56
const handleAuthentication = useHandleAuthentication ( ) ;
50
57
const finishModel = useFinishModel ( ) ;
51
58
@@ -54,11 +61,9 @@ export const useCCAWizardFooter = () => {
54
61
*/
55
62
const handleContinue = React . useCallback ( ( ) => {
56
63
if ( tabName === TabNames . CCA_DATA_WIZARD_SELECTION_TAB && dataLocation === "local" ) {
57
- console . log ( dataLocation ) ;
58
64
dispatch ( setTabName ( TabNames . CCA_LOCAL_BROWSER_TAB ) ) ;
59
65
}
60
66
if ( tabName === TabNames . CCA_DATA_WIZARD_SELECTION_TAB && dataLocation === "remote" ) {
61
- console . log ( dataLocation ) ;
62
67
dispatch ( setTabName ( TabNames . CCA_AUTHENTICATION_TAB ) ) ;
63
68
}
64
69
if ( tabName === TabNames . CCA_AUTHENTICATION_TAB ) {
@@ -68,6 +73,9 @@ export const useCCAWizardFooter = () => {
68
73
handleAuthentication ( ) ;
69
74
}
70
75
}
76
+ if ( tabName === TabNames . CCA_REMOTE_BROWSER_TAB ) {
77
+ uploadHandleRemoteFileSubmit ( ) ;
78
+ }
71
79
if ( tabName === TabNames . CCA_LOCAL_BROWSER_TAB && fileUploaded ) {
72
80
dispatch ( setTabName ( TabNames . CCA_TABLE_INGESTION ) ) ;
73
81
}
@@ -81,6 +89,7 @@ export const useCCAWizardFooter = () => {
81
89
dispatch ,
82
90
uploadSelection ,
83
91
handleAuthentication ,
92
+ uploadHandleRemoteFileSubmit ,
84
93
fileUploaded ,
85
94
setTabName ,
86
95
tabName ,
@@ -100,9 +109,12 @@ export const useCCAWizardFooter = () => {
100
109
if ( tabName === TabNames . CCA_REMOTE_BROWSER_TAB ) {
101
110
dispatch ( setTabName ( TabNames . CCA_AUTHENTICATION_TAB ) ) ;
102
111
}
103
- if ( tabName === TabNames . CCA_TABLE_INGESTION ) {
112
+ if ( tabName === TabNames . CCA_TABLE_INGESTION && dataLocation === "local" ) {
104
113
dispatch ( setTabName ( TabNames . CCA_LOCAL_BROWSER_TAB ) ) ;
105
114
}
115
+ if ( tabName === TabNames . CCA_TABLE_INGESTION && dataLocation === "remote" ) {
116
+ dispatch ( setTabName ( TabNames . CCA_REMOTE_BROWSER_TAB ) ) ;
117
+ }
106
118
if ( tabName === TabNames . CCA_FINISH_MODEL ) {
107
119
dispatch ( setTabName ( TabNames . CCA_TABLE_INGESTION ) ) ;
108
120
}
@@ -132,7 +144,7 @@ export const useCCAWizardFooter = () => {
132
144
Continue
133
145
</ button >
134
146
) : (
135
- < button className = "btn btn-primary" type = "button" disabled >
147
+ < button className = "btn btn-primary" type = "button" key = "loading" disabled >
136
148
< span className = "spinner-border spinner-border-sm" role = "status" aria-hidden = "true" > </ span >
137
149
Loading...
138
150
</ button >
@@ -249,6 +261,7 @@ const useFileUploadSuccess = () => {
249
261
} ,
250
262
) ;
251
263
dispatch ( setAttributes ( attributes ?? [ ] ) ) ;
264
+ dispatch ( setLoading ( false ) ) ;
252
265
setUploadStatus ( true ) ;
253
266
dispatch ( setTabName ( TabNames . CCA_TABLE_INGESTION ) ) ;
254
267
} ,
@@ -258,33 +271,116 @@ const useFileUploadSuccess = () => {
258
271
) ;
259
272
} ;
260
273
274
+ /**
275
+ * Sets up a stable function for handling remote file uploads, including setting loading status, progress bar, and switching to the next tab.
276
+ * @returns a stable function for handling remote file upload
277
+ */
278
+ export const useHandleRemoteFileSubmit = ( ) => {
279
+ const mid = useAppSelector ( selectMid ) ;
280
+ const pid = useAppSelector ( selectPid ) ;
281
+ const fileDescriptor = useAppSelector ( selectRemotePath ) ;
282
+ const parser = useAppSelector ( selectParser ) ;
283
+ const { hostname } = useAppSelector ( selectAuthInfo ) ;
284
+ const dispatch = useAppDispatch ( ) ;
285
+ const progress = useAppSelector ( selectProgress ) ;
286
+ const progressStatus = useAppSelector ( selectProgressStatus ) ;
287
+ const fileUploadSuccess = useFileUploadSuccess ( ) ;
288
+ return React . useCallback ( ( ) => {
289
+ dispatch ( setLoading ( true ) ) ;
290
+ console . log ( fileDescriptor ) ;
291
+ if ( ! fileDescriptor ?. path ) {
292
+ dialog . ajax_error ( `no file selected` ) ( ) ;
293
+ dispatch ( setLoading ( false ) ) ;
294
+ return ;
295
+ }
296
+ if ( fileDescriptor . type !== "f" ) {
297
+ dialog . ajax_error (
298
+ `Did you choose the correct file and filetype? selected file: ${ fileDescriptor ?. path } is not a file ` ,
299
+ ) ( ) ;
300
+ dispatch ( setLoading ( false ) ) ;
301
+ return ;
302
+ }
303
+ client
304
+ . get_remote_file_fetch ( { hostname : hostname , path : fileDescriptor ?. path } )
305
+ . then ( ( response : any ) => {
306
+ return response . text ( ) ;
307
+ } )
308
+ . then ( ( file ) => {
309
+ const progressCallback = ( input ?: number ) => {
310
+ if ( ! input ) {
311
+ return progress ;
312
+ }
313
+ dispatch ( setProgress ( input ) ) ;
314
+ } ;
315
+ const progressStatusCallback = ( input ?: string ) => {
316
+ if ( ! input ) {
317
+ return progressStatus ;
318
+ }
319
+ dispatch ( setProgressStatus ( input ) ) ;
320
+ } ;
321
+ const fileObject = {
322
+ pid,
323
+ mid,
324
+ file,
325
+ parser,
326
+ hostname,
327
+ paths : fileDescriptor . path ,
328
+ aids : [ [ "data-table" ] , fileDescriptor . path . split ( "/" ) . at ( - 1 ) ] ,
329
+ progress : progressCallback ,
330
+ progress_status : progressStatusCallback ,
331
+ progress_final : 90 ,
332
+ success : function ( ) {
333
+ setProgress ( 100 ) ;
334
+ setProgressStatus ( "File upload complete" ) ;
335
+ dispatch ( setLoading ( false ) ) ;
336
+ dispatch ( setTabName ( TabNames . CCA_TABLE_INGESTION ) ) ;
337
+ // setUploadStatus(true);
338
+ fileUploadSuccess ( setProgress , setProgressStatus , ( status ) => console . log ( status ) ) ;
339
+ } ,
340
+ error : function ( ) {
341
+ // setUploadStatus(false);
342
+ dispatch ( setLoading ( false ) ) ;
343
+ dialog . ajax_error (
344
+ "Did you choose the correct file and filetype? There was a problem parsing the file: " ,
345
+ ) ( ) ;
346
+ dispatch ( setProgress ( 0 ) ) ;
347
+ dispatch ( setProgressStatus ( "" ) ) ;
348
+ } ,
349
+ } ;
350
+ fileUploader . uploadFile ( fileObject ) ;
351
+ } ) ;
352
+ } , [ mid , pid , hostname , fileDescriptor , fileUploadSuccess , parser , dispatch ] ) ;
353
+ } ;
354
+
261
355
/**
262
356
* handle local file submission
263
357
*/
264
358
export const useHandleLocalFileSubmit = ( ) : [
265
359
( file : File , parser : string | undefined , setUploadStatus : ( status : boolean ) => void ) => void ,
266
360
number ,
267
- string ,
361
+ string | undefined ,
268
362
] => {
269
363
const mid = useAppSelector ( selectMid ) ;
270
364
const pid = useAppSelector ( selectPid ) ;
365
+ const progress = useAppSelector ( selectProgress ) ;
366
+ const progressStatus = useAppSelector ( selectProgressStatus ) ;
367
+ const dispatch = useAppDispatch ( ) ;
271
368
const fileUploadSuccess = useFileUploadSuccess ( ) ;
272
- const [ progress , setProgress ] = React . useState < number > ( 0 ) ;
273
- const [ progressStatus , setProgressStatus ] = React . useState ( "" ) ;
274
369
const handleSubmit = React . useCallback (
275
370
( file : File , parser : string | undefined , setUploadStatus : ( status : boolean ) => void ) => {
276
371
const progressCallback = ( input ?: number ) => {
277
372
if ( ! input ) {
278
373
return progress ;
279
374
}
280
- setProgress ( input ) ;
375
+ dispatch ( setProgress ( input ) ) ;
281
376
} ;
282
377
const progressStatusCallback = ( input ?: string ) => {
283
378
if ( ! input ) {
284
379
return progressStatus ;
285
380
}
286
- setProgressStatus ( input ) ;
381
+ dispatch ( setProgressStatus ( input ) ) ;
287
382
} ;
383
+ dispatch ( setLoading ( true ) ) ;
288
384
const fileObject = {
289
385
pid,
290
386
mid,
@@ -296,19 +392,19 @@ export const useHandleLocalFileSubmit = (): [
296
392
progress_status : progressStatusCallback ,
297
393
progress_final : 90 ,
298
394
success : function ( ) {
299
- setProgress ( 100 ) ;
300
- setProgressStatus ( "File upload complete" ) ;
395
+ dispatch ( setProgress ( 100 ) ) ;
396
+ dispatch ( setProgressStatus ( "File upload complete" ) ) ;
301
397
setUploadStatus ( true ) ;
302
398
fileUploadSuccess ( setProgress , setProgressStatus , setUploadStatus ) ;
303
399
} ,
304
400
error : function ( ) {
305
401
setUploadStatus ( false ) ;
402
+ dispatch ( setLoading ( false ) ) ;
306
403
dialog . ajax_error (
307
404
"Did you choose the correct file and filetype? There was a problem parsing the file: " ,
308
405
) ( ) ;
309
- // TODO: toggle disabled for continue
310
- setProgress ( 0 ) ;
311
- setProgressStatus ( "" ) ;
406
+ dispatch ( setProgress ( 0 ) ) ;
407
+ dispatch ( setProgressStatus ( "" ) ) ;
312
408
} ,
313
409
} ;
314
410
fileUploader . uploadFile ( fileObject ) ;
@@ -323,7 +419,7 @@ export const useHandleLocalFileSubmit = (): [
323
419
* Returns a function that sets the callback "setParser" value to the selected parser
324
420
*/
325
421
export const handleParserChange = (
326
- setParser : React . Dispatch < React . SetStateAction < string | undefined > > ,
422
+ setParser : ( parser : string ) => void | React . Dispatch < React . SetStateAction < string | undefined > > ,
327
423
) =>
328
424
React . useCallback (
329
425
( e : React . ChangeEvent < HTMLSelectElement > ) => {
0 commit comments