@@ -16,12 +16,16 @@ import {
1616} from 'vscode' ;
1717import { getInstance , Odo , OdoImpl } from './odo' ;
1818import {
19+ ComponentTypeDescription ,
20+ DevfileComponentType ,
1921 Registry ,
2022} from './odo/componentType' ;
2123import { StarterProject } from './odo/componentTypeDescription' ;
2224import { vsCommand , VsCommandError } from './vscommand' ;
2325import validator from 'validator' ;
24- import RegistryViewLoader from './webview/devfile-registry/registryViewLoader' ;
26+ import { Command } from './odo/command' ;
27+ import { CliExitData } from './cli' ;
28+ import { Subject } from 'rxjs' ;
2529
2630type ComponentType = Registry ;
2731
@@ -45,6 +49,8 @@ export class ComponentTypesView implements TreeDataProvider<ComponentType> {
4549
4650 readonly odo : Odo = getInstance ( ) ;
4751 private registries : Registry [ ] ;
52+ private readonly compDescriptions : Set < ComponentTypeDescription > = new Set < ComponentTypeDescription > ( ) ;
53+ public subject : Subject < string > = new Subject < string > ( ) ;
4854
4955 createTreeView ( id : string ) : TreeView < ComponentType > {
5056 if ( ! this . treeView ) {
@@ -97,6 +103,47 @@ export class ComponentTypesView implements TreeDataProvider<ComponentType> {
97103 return this . registries ;
98104 }
99105
106+ public getCompDescriptions ( ) : Set < ComponentTypeDescription > {
107+ return this . compDescriptions ;
108+ }
109+
110+ public getListOfRegistries ( ) : Registry [ ] {
111+ return this . registries ;
112+ }
113+
114+ public getAllComponents ( ) : void {
115+ let isError = false ;
116+ this . compDescriptions . clear ( ) ;
117+ void getInstance ( ) . getCompTypesJson ( ) . then ( async ( devFileComponentTypes : DevfileComponentType [ ] ) => {
118+ const components = new Set < string > ( devFileComponentTypes . map ( ( devFileComponentType : DevfileComponentType ) => devFileComponentType . Name ) ) ;
119+ await this . getRegistries ( ) ;
120+ components . forEach ( ( compName : string ) => {
121+ getInstance ( ) . execute ( Command . describeCatalogComponent ( compName ) ) . then ( ( componentDesc : CliExitData ) => {
122+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
123+ const out : ComponentTypeDescription [ ] = JSON . parse ( componentDesc . stdout ) ;
124+ out . forEach ( ( component ) => {
125+ // eslint-disable-next-line max-nested-callbacks
126+ component . Devfile ?. starterProjects ?. map ( ( starter : StarterProject ) => {
127+ starter . typeName = compName ;
128+ } ) ;
129+ this . compDescriptions . add ( component ) ;
130+ } ) ;
131+ if ( devFileComponentTypes . length === this . compDescriptions . size ) {
132+ this . subject . next ( 'refresh' ) ;
133+ }
134+ } ) . catch ( ( ) => {
135+ isError = true ;
136+ } ) . finally ( ( ) => {
137+ if ( isError && ! this . subject . closed ) {
138+ this . subject . next ( 'refresh' ) ;
139+ }
140+ } ) ;
141+ } ) ;
142+ } ) . catch ( ( ) => {
143+ this . subject . next ( 'error' ) ;
144+ } ) ;
145+ }
146+
100147 // eslint-disable-next-line class-methods-use-this
101148 async getChildren ( parent : ComponentType ) : Promise < ComponentType [ ] > {
102149 let children : ComponentType [ ] = [ ] ;
@@ -227,8 +274,8 @@ export class ComponentTypesView implements TreeDataProvider<ComponentType> {
227274 let token : string ;
228275 if ( secure === 'Yes' ) {
229276 token = await window . showInputBox ( {
230- placeHolder : 'Token to access the registry' ,
231- validateInput : ( value ) => value ?. trim ( ) . length > 0 ? undefined : 'Token cannot be empty'
277+ placeHolder : 'Token to access the registry' ,
278+ validateInput : ( value ) => value ?. trim ( ) . length > 0 ? undefined : 'Token cannot be empty'
232279 } ) ;
233280 if ( ! token ) return null ;
234281 }
@@ -238,17 +285,17 @@ export class ComponentTypesView implements TreeDataProvider<ComponentType> {
238285 */
239286
240287 if ( registryContext ) {
241- const notChangedRegisty = registries . find ( ( registry ) => registry . Name === regName && registry . URL === regURL && registry . Secure === ( secure === 'Yes' ) ) ;
242- if ( notChangedRegisty ) {
243- return null ;
244- }
245- await vscode . commands . executeCommand ( 'openshift.componentTypesView.registry.remove' , registryContext , true ) ;
288+ const notChangedRegisty = registries . find ( ( registry ) => registry . Name === regName && registry . URL === regURL && registry . Secure === ( secure === 'Yes' ) ) ;
289+ if ( notChangedRegisty ) {
290+ return null ;
291+ }
292+ await vscode . commands . executeCommand ( 'openshift.componentTypesView.registry.remove' , registryContext , true ) ;
246293 }
247294
248295 const newRegistry = await OdoImpl . Instance . addRegistry ( regName , regURL , token ) ;
249296 ComponentTypesView . instance . addRegistry ( newRegistry ) ;
250297
251- RegistryViewLoader . refresh ( ) ;
298+ ComponentTypesView . instance . getAllComponents ( ) ;
252299 }
253300
254301 @vsCommand ( 'openshift.componentTypesView.registry.remove' )
@@ -261,7 +308,9 @@ export class ComponentTypesView implements TreeDataProvider<ComponentType> {
261308 if ( yesNo === 'Yes' ) {
262309 await OdoImpl . Instance . removeRegistry ( registry . Name ) ;
263310 ComponentTypesView . instance . removeRegistry ( registry ) ;
264- RegistryViewLoader . refresh ( ) ;
311+ if ( ! isEdit ) {
312+ ComponentTypesView . instance . getAllComponents ( ) ;
313+ }
265314 }
266315 }
267316
@@ -274,9 +323,4 @@ export class ComponentTypesView implements TreeDataProvider<ComponentType> {
274323 public static async openRegistryWebSite ( registry : Registry ) : Promise < void > {
275324 await commands . executeCommand ( 'vscode.open' , Uri . parse ( registry . URL ) ) ;
276325 }
277-
278- @vsCommand ( 'openshift.componentTypesView.registry.openInView' )
279- public static async openRegistryInWebview ( ) : Promise < void > {
280- await RegistryViewLoader . loadView ( 'Devfile Registry' ) ;
281- }
282326}
0 commit comments