4
4
import * as React from "react" ;
5
5
import { useAppDispatch , useAppSelector } from "./wizard-store/hooks" ;
6
6
import { produce } from "immer" ;
7
+ import server_root from "js/slycat-server-root" ;
7
8
import {
8
9
Attribute ,
9
10
resetCCAWizard ,
10
11
selectAttributes ,
11
12
selectDataLocation ,
13
+ selectDescription ,
12
14
selectFileUploaded ,
15
+ selectMarking ,
13
16
selectMid ,
17
+ selectName ,
14
18
selectPid ,
15
19
selectScaleInputs ,
16
20
selectTab ,
@@ -35,6 +39,7 @@ export const useCCAWizardFooter = () => {
35
39
const fileUploaded = useAppSelector ( selectFileUploaded ) ;
36
40
const dispatch = useAppDispatch ( ) ;
37
41
const uploadSelection = useUploadSelection ( ) ;
42
+ const finishModel = useFinishModel ( ) ;
38
43
39
44
/**
40
45
* handle continue operation
@@ -49,6 +54,9 @@ export const useCCAWizardFooter = () => {
49
54
if ( tabName === TabNames . CCA_TABLE_INGESTION ) {
50
55
uploadSelection ( ) ;
51
56
}
57
+ if ( tabName === TabNames . CCA_FINISH_MODEL ) {
58
+ finishModel ( ) ;
59
+ }
52
60
} , [ dispatch , uploadSelection , fileUploaded , setTabName , tabName ] ) ;
53
61
54
62
/**
@@ -145,7 +153,6 @@ export const useHandleClosingCallback = (
145
153
return React . useCallback ( ( ) => {
146
154
setModalOpen ( false ) ;
147
155
if ( stateMid ) {
148
- console . log ( "delete" ) ;
149
156
client . delete_model_fetch ( { mid : stateMid } ) ;
150
157
}
151
158
dispatch ( resetCCAWizard ( ) ) ;
@@ -250,7 +257,6 @@ export const useHandleLocalFileSubmit = (): [
250
257
progress_status : progressStatusCallback ,
251
258
progress_final : 90 ,
252
259
success : function ( ) {
253
- console . log ( "uploaded" ) ;
254
260
setProgress ( 100 ) ;
255
261
setProgressStatus ( "File upload complete" ) ;
256
262
setUploadStatus ( true ) ;
@@ -291,7 +297,6 @@ export const useSetUploadStatus = () => {
291
297
const dispatch = useAppDispatch ( ) ;
292
298
return React . useCallback (
293
299
( status : boolean ) => {
294
- console . log ( "dispatching" , status ) ;
295
300
dispatch ( setFileUploaded ( status ) ) ;
296
301
} ,
297
302
[ dispatch ] ,
@@ -332,6 +337,36 @@ export const useHandleTableIngestionOnChange = (attributes: Attribute[]) => {
332
337
) ;
333
338
} ;
334
339
340
+ /**
341
+ * Hook for dealing with submission to the server of the final model values such as name and description
342
+ * @returns a function for finalizing the cca model
343
+ */
344
+ export const useFinishModel = ( ) => {
345
+ const mid = useAppSelector ( selectMid ) ;
346
+ const description = useAppSelector ( selectDescription ) ;
347
+ const name = useAppSelector ( selectName ) ;
348
+ const marking = useAppSelector ( selectMarking ) ;
349
+ return React . useCallback ( ( ) => {
350
+ // update the final model meta data and trigger the post model finish script
351
+ client . put_model ( {
352
+ mid : mid ,
353
+ name : name ,
354
+ description : description ,
355
+ marking : marking ,
356
+ success : ( ) => {
357
+ client . post_model_finish ( {
358
+ mid : mid ,
359
+ success : ( ) => {
360
+ location . href = server_root + "models/" + mid ;
361
+ } ,
362
+ } ) ;
363
+ } ,
364
+ // throw up a dialog if we get into an error state
365
+ error : dialog . ajax_error ( "Error updating model." ) ,
366
+ } ) ;
367
+ } , [ mid , name , description , marking , server_root ] ) ;
368
+ } ;
369
+
335
370
/**
336
371
* Hook for dealing with submission to the server of the inputs, outputs, and scale inputs to the server.
337
372
* @returns a function for updating inputs and outputs
@@ -348,9 +383,6 @@ export const useUploadSelection = () => {
348
383
const outputs = attributes
349
384
. filter ( ( attribute ) => attribute [ "Axis Type" ] === "Output" )
350
385
. map ( ( attribute ) => attribute . index ) ;
351
- console . log ( "attributes" , attributes ) ;
352
- console . log ( "inputs" , inputs ) ;
353
- console . log ( "outputs" , outputs ) ;
354
386
if ( inputs . length === 0 ) {
355
387
dialog . dialog ( {
356
388
message : "The number of inputs must be at least one." ,
0 commit comments