Skip to content

Commit b887b7c

Browse files
authored
Fix starter project list loading form component description and component type quickpick for multiple registries
Fixes #2115 and fixes #2117. Introduces registry name as part of component type quickpick lable. Similar to s2i components the label is formed as <devfile-component-type-name/registry-name> Sorts component types by name of the component. Signed-off-by: Denis Golovin [email protected]
1 parent 4cd138c commit b887b7c

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

src/odo.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ export class OdoImpl implements Odo {
648648
const s2iItems: ComponentTypeAdapter[] = [];
649649

650650
if (compTypesJson?.devfileItems) {
651-
compTypesJson.devfileItems.map((item) => devfileItems.push(new ComponentTypeAdapter(ComponentKind.DEVFILE, item.Name, undefined, item.Description)));
651+
compTypesJson.devfileItems.map((item) => devfileItems.push(new ComponentTypeAdapter(ComponentKind.DEVFILE, item.Name, undefined, item.Description, undefined, item.Registry.Name)));
652652
}
653653

654654
if (compTypesJson?.s2iItems) {

src/odo/componentType.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,13 @@ export class ComponentTypeAdapter implements ComponentType {
123123
public readonly name: string,
124124
public readonly version: string,
125125
public readonly description: string,
126-
public readonly tags?: string) {
126+
public readonly tags?: string,
127+
public readonly registryName?: string) {
128+
127129
}
128130

129131
get label(): string {
130-
const versionSuffix = this.version? `/${this.version}` : '' ;
132+
const versionSuffix = this.version? `/${this.version}` : `/${this.registryName}` ;
131133
return `${this.name}${versionSuffix} (${this.kind})`;
132134
}
133135
}

src/openshift/component.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ import { Command, CommandOption, CommandText } from '../odo/command';
1616
import { Progress } from '../util/progress';
1717
import { CliExitData } from '../cli';
1818
import { Refs, Type } from '../util/refs';
19-
import { Delayer, wait } from '../util/async';
19+
import { Delayer } from '../util/async';
2020
import { Platform } from '../util/platform';
2121
import { selectWorkspaceFolder } from '../util/workspace';
2222
import { ToolsConfig } from '../tools';
2323
import LogViewLoader from '../webview/log/LogViewLoader';
2424
import DescribeViewLoader from '../webview/describe/describeViewLoader';
2525
import { vsCommand, VsCommandError } from '../vscommand';
2626
import { SourceType } from '../odo/config';
27-
import { ComponentKind, ComponentTypeAdapter, DevfileComponentType, ImageStreamTag, isDevfileComponent, isImageStreamTag } from '../odo/componentType';
27+
import { ComponentKind, ComponentTypeAdapter, ComponentTypeDescription, DevfileComponentType, ImageStreamTag, isDevfileComponent, isImageStreamTag } from '../odo/componentType';
2828
import { Url } from '../odo/url';
29-
import { ComponentDescription, StarterProjectDescription } from '../odo/catalog';
29+
import { StarterProjectDescription } from '../odo/catalog';
3030
import { isStarterProject, StarterProject } from '../odo/componentTypeDescription';
3131
import path = require('path');
3232
import globby = require('globby');
@@ -633,13 +633,12 @@ export class Component extends OpenShiftItem {
633633
progressIndicator.busy = true;
634634
progressIndicator.placeholder = 'Loading available Component types';
635635
progressIndicator.show();
636-
await wait(5000);
637636
const componentTypes = await Component.odo.getComponentTypes();
638637
if (componentTypeName) {
639638
componentType = componentTypes.find(type => type.name === componentTypeName && type.kind === componentKind && (!version || type.version === version));
640639
}
641640
if (!componentType) {
642-
componentType = await window.showQuickPick(componentTypes, { placeHolder: 'Select Component type', ignoreFocusOut: true });
641+
componentType = await window.showQuickPick(componentTypes.sort((c1, c2) => c1.label.localeCompare(c2.label)), { placeHolder: 'Select Component type', ignoreFocusOut: true });
643642
} else {
644643
progressIndicator.hide();
645644
}
@@ -659,7 +658,10 @@ export class Component extends OpenShiftItem {
659658
progressIndicator.placeholder = 'Loading Starter Projects for selected Component Type'
660659
progressIndicator.show();
661660
const descr = await Component.odo.execute(Command.describeCatalogComponent(componentType.name));
662-
const starterProjects: StarterProjectDescription[] = Component.odo.loadItems<StarterProjectDescription>(descr,(data:{Data:ComponentDescription})=>data.Data.starterProjects);
661+
const starterProjects: StarterProjectDescription[] = Component.odo.loadItems<StarterProjectDescription>(descr,(data:ComponentTypeDescription[])=> {
662+
const dfCompType = data.find((comp)=>comp.RegistryName === componentType.registryName);
663+
return dfCompType.Devfile.starterProjects
664+
});
663665
progressIndicator.hide();
664666
if(starterProjects?.length && starterProjects?.length > 0) {
665667
const create = await window.showQuickPick(['Yes', 'No'] , {placeHolder: `Initialize Component using ${starterProjects.length === 1 ? '\''.concat(starterProjects[0].name.concat('\' ')) : ''}Starter Project?`});

0 commit comments

Comments
 (0)