7
7
GalleryItem ,
8
8
Form ,
9
9
Alert ,
10
+ SelectOptionProps ,
10
11
} from "@patternfly/react-core" ;
11
12
import { useTranslation } from "react-i18next" ;
12
13
import { useFormContext } from "react-hook-form" ;
@@ -15,24 +16,53 @@ import { TargetCard } from "@app/components/target-card/target-card";
15
16
import { AnalysisWizardFormValues } from "./schema" ;
16
17
import { useSetting } from "@app/queries/settings" ;
17
18
import { useFetchTargets } from "@app/queries/targets" ;
18
- import { Target } from "@app/api/models" ;
19
- import { SimpleSelectTypeahead } from "@app/components/SimpleSelectTypeahead" ;
20
-
21
- export const SetTargets : React . FC = ( ) => {
19
+ import { Application , TagCategory , Target } from "@app/api/models" ;
20
+ import { useFetchTagCategories } from "@app/queries/tags" ;
21
+ import { SimpleSelectCheckbox } from "@app/components/SimpleSelectCheckbox" ;
22
+ interface SetTargetsProps {
23
+ applications : Application [ ] ;
24
+ }
25
+
26
+ export const SetTargets : React . FC < SetTargetsProps > = ( { applications } ) => {
22
27
const { t } = useTranslation ( ) ;
23
28
24
29
const { targets } = useFetchTargets ( ) ;
25
30
26
- const [ provider , setProvider ] = useState ( "Java" ) ;
27
-
28
31
const targetOrderSetting = useSetting ( "ui.target.order" ) ;
29
32
30
33
const { watch, setValue, getValues } =
31
34
useFormContext < AnalysisWizardFormValues > ( ) ;
35
+
32
36
const values = getValues ( ) ;
33
37
const formLabels = watch ( "formLabels" ) ;
34
38
const selectedTargets = watch ( "selectedTargets" ) ;
35
39
40
+ const { tagCategories, isFetching, fetchError } = useFetchTagCategories ( ) ;
41
+
42
+ const findCategoryForTag = ( tagId : number ) => {
43
+ return tagCategories . find (
44
+ ( category : TagCategory ) =>
45
+ category . tags ?. some ( ( categoryTag ) => categoryTag . id === tagId )
46
+ ) ;
47
+ } ;
48
+
49
+ const initialProviders = Array . from (
50
+ new Set (
51
+ applications
52
+ . flatMap ( ( app ) => app . tags || [ ] )
53
+ . map ( ( tag ) => {
54
+ return {
55
+ category : findCategoryForTag ( tag . id ) ,
56
+ tag,
57
+ } ;
58
+ } )
59
+ . filter ( ( tagWithCat ) => tagWithCat ?. category ?. name === "Language" )
60
+ . map ( ( tagWithCat ) => tagWithCat . tag . name )
61
+ )
62
+ ) . filter ( ( name ) => name !== undefined ) ;
63
+
64
+ const [ provider , setProvider ] = useState ( initialProviders ) ;
65
+
36
66
const handleOnSelectedCardTargetChange = ( selectedLabelName : string ) => {
37
67
const otherSelectedLabels = formLabels ?. filter ( ( formLabel ) => {
38
68
return formLabel . name !== selectedLabelName ;
@@ -124,6 +154,10 @@ export const SetTargets: React.FC = () => {
124
154
}
125
155
} ;
126
156
157
+ const allProviders = targets . flatMap ( ( target ) => target . provider ) ;
158
+
159
+ const languageOptions = Array . from ( new Set ( allProviders ) ) ;
160
+
127
161
return (
128
162
< Form
129
163
onSubmit = { ( event ) => {
@@ -136,26 +170,21 @@ export const SetTargets: React.FC = () => {
136
170
</ Title >
137
171
< Text > { t ( "wizard.label.setTargets" ) } </ Text >
138
172
</ TextContent >
139
- < SimpleSelectTypeahead
140
- width = { 200 }
173
+ < SimpleSelectCheckbox
174
+ placeholderText = "Select a language..."
175
+ width = { 300 }
141
176
value = { provider }
142
- toggleAriaLabel = "Action select dropdown toggle"
143
- toggleId = "action-select-toggle"
144
- hideClearButton
145
- id = "action-select"
146
- options = { [
147
- {
148
- value : "Java" ,
149
- children : "Java" ,
150
- } ,
151
- {
152
- value : "Go" ,
153
- children : "Go" ,
154
- } ,
155
- ] }
177
+ options = { languageOptions ?. map ( ( language ) : SelectOptionProps => {
178
+ return {
179
+ children : < div > { language } </ div > ,
180
+
181
+ value : language ,
182
+ } ;
183
+ } ) }
156
184
onChange = { ( selection ) => {
157
- setProvider ( selection as string ) ;
185
+ setProvider ( selection as string [ ] ) ;
158
186
} }
187
+ toggleId = "language-select-toggle"
159
188
/>
160
189
{ values . selectedTargets . length === 0 &&
161
190
values . customRulesFiles . length === 0 &&
@@ -172,8 +201,10 @@ export const SetTargets: React.FC = () => {
172
201
const matchingTarget = targets . find ( ( target ) => target . id === id ) ;
173
202
174
203
const isSelected = selectedTargets ?. includes ( id ) ;
175
-
176
- if ( matchingTarget && matchingTarget . provider === provider ) {
204
+ if (
205
+ matchingTarget &&
206
+ provider ?. some ( ( p ) => matchingTarget ?. provider ?. includes ( p ) )
207
+ ) {
177
208
return (
178
209
< GalleryItem key = { index } >
179
210
< TargetCard
0 commit comments