3
3
retains certain rights in this software. */
4
4
import * as React from "react" ;
5
5
import { useAppDispatch , useAppSelector } from "./wizard-store/hooks" ;
6
+ import { produce } from "immer" ;
6
7
import {
8
+ Attribute ,
7
9
resetCCAWizard ,
8
10
selectDataLocation ,
9
11
selectFileUploaded ,
10
12
selectMid ,
11
13
selectPid ,
12
14
selectTab ,
15
+ setAttributes ,
13
16
setFileUploaded ,
14
17
setMid ,
15
18
setPid ,
@@ -19,6 +22,7 @@ import {
19
22
import client from "js/slycat-web-client" ;
20
23
import fileUploader from "js/slycat-file-uploader-factory" ;
21
24
import * as dialog from "js/slycat-dialog" ;
25
+ import { useSelector } from "node_modules/react-redux/dist/react-redux" ;
22
26
23
27
/**
24
28
* A hook for controlling how the back and continue buttons work based on the current redux state
@@ -60,7 +64,9 @@ export const useCCAWizardFooter = () => {
60
64
const backButton = (
61
65
< button
62
66
key = "back button"
63
- style = { { visibility : tabName === TabNames . CCA_DATA_WIZARD_SELECTION_TAB ? "hidden" : "visible" } }
67
+ style = { {
68
+ visibility : tabName === TabNames . CCA_DATA_WIZARD_SELECTION_TAB ? "hidden" : "visible" ,
69
+ } }
64
70
className = "btn btn-light mr-auto"
65
71
onClick = { handleBack }
66
72
>
@@ -78,7 +84,10 @@ export const useCCAWizardFooter = () => {
78
84
Continue { fileUploaded . toString ( ) }
79
85
</ button >
80
86
) ;
81
- return React . useMemo ( ( ) => [ backButton , nextButton ] , [ fileUploaded , tabName , dataLocation , dispatch ] ) ;
87
+ return React . useMemo (
88
+ ( ) => [ backButton , nextButton ] ,
89
+ [ fileUploaded , tabName , dataLocation , dispatch ] ,
90
+ ) ;
82
91
} ;
83
92
84
93
/**
@@ -139,7 +148,65 @@ export const useHandleClosingCallback = (
139
148
} ;
140
149
141
150
/**
142
- * handle file submission
151
+ * callback function for when a file is done uploading for gathering and setting all the file meta data
152
+ * @returns a memoized function to call once uploading a file is done
153
+ */
154
+ const useFileUploadSuccess = ( ) => {
155
+ const mid = useAppSelector ( selectMid ) ;
156
+ const dispatch = useAppDispatch ( ) ;
157
+ return React . useCallback (
158
+ (
159
+ setProgress : ( status : number ) => void ,
160
+ setProgressStatus : ( status : string ) => void ,
161
+ setUploadStatus : ( status : boolean ) => void ,
162
+ ) => {
163
+ setProgress ( 95 ) ;
164
+ setProgressStatus ( "Finishing..." ) ;
165
+ client . get_model_arrayset_metadata ( {
166
+ mid : mid ,
167
+ aid : "data-table" ,
168
+ arrays : "0" ,
169
+ statistics : "0/..." ,
170
+ success : function ( metadata : any ) {
171
+ setProgress ( 100 ) ;
172
+ setProgressStatus ( "Finished" ) ;
173
+ const attributes : Attribute [ ] = ( metadata ?. arrays [ 0 ] ?. attributes as [ ] ) ?. map (
174
+ ( attribute : any , index ) => {
175
+ const constant = metadata . statistics [ index ] . unique === 1 ;
176
+ const string = attribute . type == "string" ;
177
+ let tooltip = "" ;
178
+ if ( string ) {
179
+ tooltip =
180
+ "This variable's values contain strings, so it cannot be included in the analysis." ;
181
+ } else if ( constant ) {
182
+ tooltip =
183
+ "This variable's values are all identical, so it cannot be included in the analysis." ;
184
+ }
185
+ return {
186
+ index : index ,
187
+ name : attribute . name ,
188
+ type : attribute . type ,
189
+ "Axis Type" : constant || string ? "" : "Input" ,
190
+ constant : constant ,
191
+ disabled : constant || string ,
192
+ hidden : false ,
193
+ selected : false ,
194
+ lastSelected : false ,
195
+ tooltip : tooltip ,
196
+ } ;
197
+ } ,
198
+ ) ;
199
+ dispatch ( setAttributes ( attributes ?? [ ] ) ) ;
200
+ setUploadStatus ( true ) ;
201
+ } ,
202
+ } ) ;
203
+ } ,
204
+ [ mid , dispatch ] ,
205
+ ) ;
206
+ } ;
207
+
208
+ /**
209
+ * handle local file submission
143
210
*/
144
211
export const useHandleLocalFileSubmit = ( ) : [
145
212
( file : File , parser : string | undefined , setUploadStatus : ( status : boolean ) => void ) => void ,
@@ -148,6 +215,7 @@ export const useHandleLocalFileSubmit = (): [
148
215
] => {
149
216
const mid = useAppSelector ( selectMid ) ;
150
217
const pid = useAppSelector ( selectPid ) ;
218
+ const fileUploadSuccess = useFileUploadSuccess ( ) ;
151
219
const [ progress , setProgress ] = React . useState < number > ( 0 ) ;
152
220
const [ progressStatus , setProgressStatus ] = React . useState ( "" ) ;
153
221
const handleSubmit = React . useCallback (
@@ -179,6 +247,7 @@ export const useHandleLocalFileSubmit = (): [
179
247
setProgress ( 100 ) ;
180
248
setProgressStatus ( "File upload complete" ) ;
181
249
setUploadStatus ( true ) ;
250
+ fileUploadSuccess ( setProgress , setProgressStatus , setUploadStatus ) ;
182
251
} ,
183
252
error : function ( ) {
184
253
setUploadStatus ( false ) ;
@@ -221,3 +290,37 @@ export const useSetUploadStatus = () => {
221
290
[ dispatch ] ,
222
291
) ;
223
292
} ;
293
+
294
+ /**
295
+ * A function to handle effects of selection on the radio buttons in the ingestion tab for CCA
296
+ * @param attributes from redux
297
+ * @returns memoized onChange function to handle radio button selection
298
+ */
299
+ export const useHandleTableIngestionOnChange = ( attributes : Attribute [ ] ) => {
300
+ const dispatch = useAppDispatch ( ) ;
301
+ return React . useCallback (
302
+ ( input : any ) => {
303
+ // this function is overloaded to handle batching so we need to check for target or batchTarget
304
+ if ( input ?. target && ( input as any ) ?. target ?. name && ( input as any ) ?. target ?. value ) {
305
+ const nextAttributes = produce ( attributes , ( draftState ) => {
306
+ draftState [ input ?. target ?. name ] = {
307
+ ...draftState [ input ?. target ?. name ] ,
308
+ "Axis Type" : input ?. target ?. value ,
309
+ } ;
310
+ } ) ;
311
+ dispatch ( setAttributes ( nextAttributes ) ) ;
312
+ } else if ( input ?. batchTarget && input ?. batchTarget ?. length > 0 ) {
313
+ const nextAttributes = produce ( attributes , ( draftState ) => {
314
+ input ?. batchTarget . forEach ( ( row : any ) => {
315
+ draftState [ row ?. name ] = {
316
+ ...draftState [ row ?. name ] ,
317
+ "Axis Type" : row ?. value ,
318
+ } ;
319
+ } ) ;
320
+ } ) ;
321
+ dispatch ( setAttributes ( nextAttributes ) ) ;
322
+ }
323
+ } ,
324
+ [ attributes , dispatch ] ,
325
+ ) ;
326
+ } ;
0 commit comments