@@ -7,10 +7,12 @@ import { produce } from "immer";
7
7
import {
8
8
Attribute ,
9
9
resetCCAWizard ,
10
+ selectAttributes ,
10
11
selectDataLocation ,
11
12
selectFileUploaded ,
12
13
selectMid ,
13
14
selectPid ,
15
+ selectScaleInputs ,
14
16
selectTab ,
15
17
setAttributes ,
16
18
setFileUploaded ,
@@ -22,7 +24,6 @@ import {
22
24
import client from "js/slycat-web-client" ;
23
25
import fileUploader from "js/slycat-file-uploader-factory" ;
24
26
import * as dialog from "js/slycat-dialog" ;
25
- import { useSelector } from "node_modules/react-redux/dist/react-redux" ;
26
27
27
28
/**
28
29
* A hook for controlling how the back and continue buttons work based on the current redux state
@@ -33,6 +34,7 @@ export const useCCAWizardFooter = () => {
33
34
const dataLocation = useAppSelector ( selectDataLocation ) ;
34
35
const fileUploaded = useAppSelector ( selectFileUploaded ) ;
35
36
const dispatch = useAppDispatch ( ) ;
37
+ const uploadSelection = useUploadSelection ( ) ;
36
38
37
39
/**
38
40
* handle continue operation
@@ -45,9 +47,9 @@ export const useCCAWizardFooter = () => {
45
47
dispatch ( setTabName ( TabNames . CCA_TABLE_INGESTION ) ) ;
46
48
}
47
49
if ( tabName === TabNames . CCA_TABLE_INGESTION ) {
48
- dispatch ( setTabName ( TabNames . CCA_TABLE_INGESTION ) ) ;
50
+ uploadSelection ( ) ;
49
51
}
50
- } , [ dispatch , fileUploaded , setTabName , tabName ] ) ;
52
+ } , [ dispatch , uploadSelection , fileUploaded , setTabName , tabName ] ) ;
51
53
52
54
/**
53
55
* handle back operation
@@ -59,6 +61,9 @@ export const useCCAWizardFooter = () => {
59
61
if ( tabName === TabNames . CCA_TABLE_INGESTION ) {
60
62
dispatch ( setTabName ( TabNames . CCA_LOCAL_BROWSER_TAB ) ) ;
61
63
}
64
+ if ( tabName === TabNames . CCA_FINISH_MODEL ) {
65
+ dispatch ( setTabName ( TabNames . CCA_TABLE_INGESTION ) ) ;
66
+ }
62
67
} , [ dispatch , setTabName , tabName ] ) ;
63
68
64
69
const backButton = (
@@ -86,7 +91,7 @@ export const useCCAWizardFooter = () => {
86
91
) ;
87
92
return React . useMemo (
88
93
( ) => [ backButton , nextButton ] ,
89
- [ fileUploaded , tabName , dataLocation , dispatch ] ,
94
+ [ fileUploaded , handleContinue , handleBack , tabName , dataLocation , dispatch ] ,
90
95
) ;
91
96
} ;
92
97
@@ -198,6 +203,7 @@ const useFileUploadSuccess = () => {
198
203
) ;
199
204
dispatch ( setAttributes ( attributes ?? [ ] ) ) ;
200
205
setUploadStatus ( true ) ;
206
+ dispatch ( setTabName ( TabNames . CCA_TABLE_INGESTION ) ) ;
201
207
} ,
202
208
} ) ;
203
209
} ,
@@ -215,6 +221,7 @@ export const useHandleLocalFileSubmit = (): [
215
221
] => {
216
222
const mid = useAppSelector ( selectMid ) ;
217
223
const pid = useAppSelector ( selectPid ) ;
224
+ const dispatch = useAppDispatch ( ) ;
218
225
const fileUploadSuccess = useFileUploadSuccess ( ) ;
219
226
const [ progress , setProgress ] = React . useState < number > ( 0 ) ;
220
227
const [ progressStatus , setProgressStatus ] = React . useState ( "" ) ;
@@ -324,3 +331,61 @@ export const useHandleTableIngestionOnChange = (attributes: Attribute[]) => {
324
331
[ attributes , dispatch ] ,
325
332
) ;
326
333
} ;
334
+
335
+ /**
336
+ * Hook for dealing with submission to the server of the inputs, outputs, and scale inputs to the server.
337
+ * @returns a function for updating inputs and outputs
338
+ */
339
+ export const useUploadSelection = ( ) => {
340
+ const mid = useAppSelector ( selectMid ) ;
341
+ const scaleInputs = useAppSelector ( selectScaleInputs ) ;
342
+ const attributes = useAppSelector ( selectAttributes ) ;
343
+ const dispatch = useAppDispatch ( ) ;
344
+ return React . useCallback ( ( ) => {
345
+ const inputs = attributes
346
+ . filter ( ( attribute ) => attribute [ "Axis Type" ] === "Input" )
347
+ . map ( ( attribute ) => attribute . index ) ;
348
+ const outputs = attributes
349
+ . filter ( ( attribute ) => attribute [ "Axis Type" ] === "Output" )
350
+ . map ( ( attribute ) => attribute . index ) ;
351
+ console . log ( "attributes" , attributes ) ;
352
+ console . log ( "inputs" , inputs ) ;
353
+ console . log ( "outputs" , outputs ) ;
354
+ if ( inputs . length === 0 ) {
355
+ dialog . dialog ( {
356
+ message : "The number of inputs must be at least one." ,
357
+ } ) ;
358
+ } else if ( outputs . length === 0 ) {
359
+ dialog . dialog ( {
360
+ message : "The number of outputs must be at least one." ,
361
+ } ) ;
362
+ } else {
363
+ client . put_model_parameter ( {
364
+ mid : mid ,
365
+ aid : "input-columns" ,
366
+ value : inputs ,
367
+ input : true ,
368
+ success : function ( ) {
369
+ client . put_model_parameter ( {
370
+ mid : mid ,
371
+ aid : "output-columns" ,
372
+ value : outputs ,
373
+ input : true ,
374
+ success : function ( ) {
375
+ client . put_model_parameter ( {
376
+ mid : mid ,
377
+ aid : "scale-inputs" ,
378
+ value : scaleInputs ,
379
+ input : true ,
380
+ success : function ( ) {
381
+ // set the tab
382
+ dispatch ( setTabName ( TabNames . CCA_FINISH_MODEL ) ) ;
383
+ } ,
384
+ } ) ;
385
+ } ,
386
+ } ) ;
387
+ } ,
388
+ } ) ;
389
+ }
390
+ } , [ mid , attributes , scaleInputs , dispatch ] ) ;
391
+ } ;
0 commit comments