@@ -165,6 +165,56 @@ function RegistriesPicker(props: {
165
165
) ;
166
166
}
167
167
168
+ function RegistryTagsPicker ( props : {
169
+ tagEnabled : { tagName : string ; enabled : boolean } [ ] ;
170
+ setTagEnabled : React . Dispatch <
171
+ React . SetStateAction < { tagName : string ; enabled : boolean } [ ] >
172
+ > ;
173
+ } ) {
174
+ function onCheckboxClick ( clickedTag : string , checked : boolean ) {
175
+ const prevVal = props . tagEnabled . find (
176
+ ( entry ) => entry . tagName === clickedTag ,
177
+ ) ;
178
+ const updatedList = [ ...props . tagEnabled ] //
179
+ . filter ( ( entry ) => entry . tagName !== clickedTag ) ;
180
+ updatedList . push ( {
181
+ tagName : clickedTag ,
182
+ enabled : checked ,
183
+ } ) ;
184
+ updatedList . sort ( ( tagA , tagB ) => tagA . tagName . localeCompare ( tagB . tagName ) ) ;
185
+ props . setTagEnabled ( updatedList ) ;
186
+ }
187
+
188
+ return (
189
+ < Stack direction = "column" spacing = { 1 } marginY = { 2 } >
190
+ < Typography variant = "body2" marginBottom = { 1 } >
191
+ Filter by
192
+ </ Typography >
193
+ < FormGroup >
194
+ { props . tagEnabled . map ( ( tag ) => {
195
+ return (
196
+ < FormControlLabel
197
+ control = {
198
+ < Checkbox
199
+ // disabled={
200
+ // registry.registryUrl === 'https://registry.devfile.io'
201
+ // }
202
+ checked = { tag . enabled }
203
+ onChange = { ( _e , checked ) =>
204
+ onCheckboxClick ( tag . tagName , checked )
205
+ }
206
+ />
207
+ }
208
+ label = { tag . tagName }
209
+ key = { tag . tagName }
210
+ />
211
+ ) ;
212
+ } ) }
213
+ </ FormGroup >
214
+ </ Stack >
215
+ ) ;
216
+ }
217
+
168
218
const SelectTemplateProject = React . forwardRef (
169
219
(
170
220
props : {
@@ -399,6 +449,10 @@ export function DevfileSearch(props: DevfileSearchProps) {
399
449
const [ registryEnabled , setRegistryEnabled ] = React . useState <
400
450
{ registryName : string ; registryUrl : string ; enabled : boolean } [ ]
401
451
> ( [ ] ) ;
452
+ const [ devfileTags , setDevfileTags ] = React . useState < string [ ] > ( [ ] ) ;
453
+ const [ tagEnabled , setTagEnabled ] = React . useState <
454
+ { tagName : string ; enabled : boolean } [ ]
455
+ > ( [ ] ) ;
402
456
const [ searchText , setSearchText ] = React . useState ( '' ) ;
403
457
404
458
function respondToMessage ( messageEvent : MessageEvent ) {
@@ -407,6 +461,9 @@ export function DevfileSearch(props: DevfileSearchProps) {
407
461
case 'devfileRegistries' : {
408
462
setDevfileRegistries ( ( _devfileRegistries ) => message . data ) ;
409
463
}
464
+ case 'devfileTags' : {
465
+ setDevfileTags ( ( _devfileTags ) => message . data ) ;
466
+ }
410
467
}
411
468
}
412
469
@@ -422,6 +479,17 @@ export function DevfileSearch(props: DevfileSearchProps) {
422
479
setRegistryEnabled ( ( _ ) => enabledArray ) ;
423
480
} , [ devfileRegistries ] ) ;
424
481
482
+ React . useEffect ( ( ) => {
483
+ const enabledArray = [ ] ;
484
+ for ( let tag of devfileTags ) {
485
+ enabledArray . push ( {
486
+ tagName : tag ,
487
+ enabled : true ,
488
+ } ) ;
489
+ }
490
+ setTagEnabled ( ( _ ) => enabledArray ) ;
491
+ } , [ devfileTags ] ) ;
492
+
425
493
React . useEffect ( ( ) => {
426
494
props . setSelectedDevfile ( selectedDevfile ) ;
427
495
} , [ selectedDevfile ] ) ;
@@ -437,6 +505,10 @@ export function DevfileSearch(props: DevfileSearchProps) {
437
505
window . vscodeApi . postMessage ( { action : 'getDevfileRegistries' } ) ;
438
506
} , [ ] ) ;
439
507
508
+ React . useEffect ( ( ) => {
509
+ window . vscodeApi . postMessage ( { action : 'getDevfileTags' } ) ;
510
+ } , [ ] ) ;
511
+
440
512
React . useEffect ( ( ) => {
441
513
setCurrentPage ( ( _ ) => 1 ) ;
442
514
} , [ registryEnabled , searchText ] ) ;
@@ -445,6 +517,10 @@ export function DevfileSearch(props: DevfileSearchProps) {
445
517
return < LoadScreen title = "Retrieving list of Devfiles" /> ;
446
518
}
447
519
520
+ if ( ! devfileTags ) {
521
+ return < LoadScreen title = "Retrieving list of Devfile Tags" /> ;
522
+ }
523
+
448
524
const activeRegistries = registryEnabled //
449
525
. filter ( ( entry ) => entry . enabled ) //
450
526
. map ( ( entry ) => entry . registryName ) ;
@@ -486,15 +562,36 @@ export function DevfileSearch(props: DevfileSearchProps) {
486
562
< Stack direction = "column" height = "100%" spacing = { 3 } >
487
563
< Typography variant = "h5" > { props . titleText } </ Typography >
488
564
< Stack direction = "row" flexGrow = "1" spacing = { 2 } >
489
- { devfileRegistries . length > 1 && (
490
- < >
491
- < RegistriesPicker
492
- registryEnabled = { registryEnabled }
493
- setRegistryEnabled = { setRegistryEnabled }
494
- />
495
- < Divider orientation = "vertical" />
496
- </ >
497
- ) }
565
+ < Stack direction = "column" sx = { { flexGrow : '1' , height : '100%' , minWidth :'20%' } } spacing = { 0 } >
566
+ { devfileRegistries . length > 1 && (
567
+ < >
568
+ < Stack direction = "row" sx = { { flexGrow : '1' , width : '100%' } } spacing = { 0 } >
569
+ < RegistriesPicker
570
+ registryEnabled = { registryEnabled }
571
+ setRegistryEnabled = { setRegistryEnabled }
572
+ />
573
+ </ Stack >
574
+ < Stack direction = "column" sx = { { flexGrow : '1' , width : '100%' } } spacing = { 0 } marginBottom = { 1 } >
575
+ < Divider orientation = "horizontal" />
576
+ </ Stack >
577
+ </ >
578
+ ) }
579
+ { devfileTags . length > 1 && (
580
+ < >
581
+ < Stack direction = "row" sx = { { flexGrow : '1' , width : '100%' } } spacing = { 0 } >
582
+ < RegistryTagsPicker
583
+ tagEnabled = { tagEnabled }
584
+ setTagEnabled = { setTagEnabled }
585
+ />
586
+ </ Stack >
587
+ </ >
588
+ ) }
589
+ < Stack direction = "column" sx = { { flexGrow : '1' , height : '100%' , width : '100%' } } spacing = { 0 } >
590
+ </ Stack >
591
+ </ Stack >
592
+ < Stack direction = "column" sx = { { flexGrow : '1' , height : '100%' } } spacing = { 3 } >
593
+ < Divider orientation = "vertical" />
594
+ </ Stack >
498
595
< Stack direction = "column" sx = { { flexGrow : '1' , height : '100%' } } spacing = { 3 } >
499
596
< SearchBar
500
597
searchText = { searchText }
0 commit comments