@@ -10,7 +10,6 @@ import { useTranslation } from "react-i18next";
10
10
11
11
import {
12
12
Application ,
13
- IReadFile ,
14
13
TaskData ,
15
14
Taskgroup ,
16
15
TaskgroupTask ,
@@ -36,9 +35,8 @@ import {
36
35
} from "./schema" ;
37
36
import { useAsyncYupValidation } from "@app/hooks/useAsyncYupValidation" ;
38
37
import { CustomRules } from "./custom-rules" ;
39
- import { useSetting } from "@app/queries/settings" ;
40
- import defaultSources from "./sources" ;
41
38
import { useFetchIdentities } from "@app/queries/identities" ;
39
+ import { TaskGroupProvider , useTaskGroup } from "./components/TaskGroupContext" ;
42
40
43
41
interface IAnalysisWizard {
44
42
applications : Application [ ] ;
@@ -67,7 +65,7 @@ const defaultTaskData: TaskData = {
67
65
} ,
68
66
} ;
69
67
70
- const defaultTaskgroup : Taskgroup = {
68
+ export const defaultTaskgroup : Taskgroup = {
71
69
name : `taskgroup.analyzer` ,
72
70
addon : "analyzer" ,
73
71
data : {
@@ -96,18 +94,16 @@ export const AnalysisWizard: React.FC<IAnalysisWizard> = ({
96
94
97
95
const { pushNotification } = React . useContext ( NotificationsContext ) ;
98
96
99
- const [ currentTaskgroup , setCurrentTaskgroup ] =
100
- React . useState < Taskgroup | null > ( ) ;
97
+ const { taskGroup, updateTaskGroup } = useTaskGroup ( ) ;
101
98
102
99
const [ stepIdReached , setStepIdReached ] = React . useState ( 1 ) ;
103
100
const isMutating = useIsMutating ( ) ;
104
101
105
102
const onCreateTaskgroupSuccess = ( data : Taskgroup ) => {
106
- setCurrentTaskgroup ( data ) ;
103
+ updateTaskGroup ( data ) ;
107
104
} ;
108
105
109
106
const onCreateTaskgroupError = ( error : Error | unknown ) => {
110
- console . log ( "Taskgroup creation failed: " , error ) ;
111
107
pushNotification ( {
112
108
title : "Taskgroup creation failed" ,
113
109
variant : "danger" ,
@@ -139,11 +135,10 @@ export const AnalysisWizard: React.FC<IAnalysisWizard> = ({
139
135
) ;
140
136
141
137
const onDeleteTaskgroupSuccess = ( ) => {
142
- setCurrentTaskgroup ( null ) ;
138
+ updateTaskGroup ( null ) ;
143
139
} ;
144
140
145
141
const onDeleteTaskgroupError = ( error : Error | unknown ) => {
146
- console . log ( "Taskgroup: delete failed: " , error ) ;
147
142
pushNotification ( {
148
143
title : "Taskgroup: delete failed" ,
149
144
variant : "danger" ,
@@ -282,20 +277,20 @@ export const AnalysisWizard: React.FC<IAnalysisWizard> = ({
282
277
const isModeValid = applications . every ( ( app ) => isModeSupported ( app , mode ) ) ;
283
278
284
279
const handleCancel = ( ) => {
285
- if ( currentTaskgroup && currentTaskgroup . id ) {
286
- deleteTaskgroup ( currentTaskgroup . id ) ;
280
+ if ( taskGroup && taskGroup . id ) {
281
+ deleteTaskgroup ( taskGroup . id ) ;
287
282
}
288
- setCurrentTaskgroup ( null ) ;
283
+ updateTaskGroup ( null ) ;
289
284
reset ( ) ;
290
285
onClose ( ) ;
291
286
} ;
292
287
293
288
const onSubmit = ( fieldValues : AnalysisWizardFormValues ) => {
294
- if ( currentTaskgroup ) {
295
- const taskgroup = setupTaskgroup ( currentTaskgroup , fieldValues ) ;
289
+ if ( taskGroup ) {
290
+ const taskgroup = setupTaskgroup ( taskGroup , fieldValues ) ;
296
291
submitTaskgroup ( taskgroup ) ;
297
292
}
298
- setCurrentTaskgroup ( null ) ;
293
+ updateTaskGroup ( null ) ;
299
294
reset ( ) ;
300
295
onClose ( ) ;
301
296
} ;
@@ -306,7 +301,7 @@ export const AnalysisWizard: React.FC<IAnalysisWizard> = ({
306
301
) => {
307
302
if ( id && stepIdReached < ( id as number ) ) setStepIdReached ( id as number ) ;
308
303
if ( id === StepId . SetTargets ) {
309
- if ( ! currentTaskgroup ) {
304
+ if ( ! taskGroup ) {
310
305
createTaskgroup ( defaultTaskgroup ) ;
311
306
}
312
307
}
@@ -335,11 +330,6 @@ export const AnalysisWizard: React.FC<IAnalysisWizard> = ({
335
330
component : (
336
331
< SetMode
337
332
isSingleApp = { applications . length === 1 ? true : false }
338
- taskgroupID = {
339
- currentTaskgroup && currentTaskgroup ?. id
340
- ? currentTaskgroup . id
341
- : null
342
- }
343
333
isModeValid = { isModeValid }
344
334
/>
345
335
) ,
@@ -365,15 +355,7 @@ export const AnalysisWizard: React.FC<IAnalysisWizard> = ({
365
355
{
366
356
id : StepId . CustomRules ,
367
357
name : t ( "wizard.terms.customRules" ) ,
368
- component : (
369
- < CustomRules
370
- taskgroupID = {
371
- currentTaskgroup && currentTaskgroup ?. id
372
- ? currentTaskgroup . id
373
- : null
374
- }
375
- />
376
- ) ,
358
+ component : < CustomRules /> ,
377
359
...getStepNavProps ( StepId . CustomRules ) ,
378
360
} ,
379
361
{
@@ -392,7 +374,6 @@ export const AnalysisWizard: React.FC<IAnalysisWizard> = ({
392
374
...getStepNavProps ( StepId . Review ) ,
393
375
} ,
394
376
] ;
395
-
396
377
return (
397
378
< >
398
379
{ isOpen && (
0 commit comments