Skip to content

Commit 00407a6

Browse files
authored
Build component type and version request with single odo call (#1476)
Signed-off-by: Denis Golovin <dgolovin@redhat.com>
1 parent 76d291b commit 00407a6

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

src/openshift/catalog.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,31 @@
33
* Licensed under the MIT License. See LICENSE file in the project root for license information.
44
*-----------------------------------------------------------------------------------------------*/
55

6-
import { Odo, OdoImpl, Command } from "../odo";
7-
import { Platform } from "../util/platform";
6+
import { Odo, OdoImpl, Command } from '../odo';
7+
import { Platform } from '../util/platform';
88

99
export class Catalog {
1010
private static odo: Odo = OdoImpl.Instance;
1111

12+
private componentsJson: any[] = [];
13+
1214
static listComponents(): void {
1315
Catalog.odo.executeInTerminal(Command.listCatalogComponents(), Platform.getUserHomePath());
1416
}
1517

1618
static listServices(): void {
1719
Catalog.odo.executeInTerminal(Command.listCatalogServices(), Platform.getUserHomePath());
1820
}
19-
}
21+
22+
async getComponentNames(): Promise<string[]> {
23+
this.componentsJson = await Catalog.odo.getComponentTypesJson();
24+
return this.componentsJson.map((value) => value.metadata.name);
25+
}
26+
27+
getComponentVersions(componentName: string): string[] {
28+
const component = this.componentsJson.find(
29+
(value) => value.metadata.name === componentName,
30+
);
31+
return component ? component.spec.allTags : [];
32+
}
33+
}

src/openshift/component.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ import { Refs, Ref, Type } from '../util/refs';
1616
import { Delayer } from '../util/async';
1717
import { Platform } from '../util/platform';
1818
import { selectWorkspaceFolder } from '../util/workspace';
19-
2019
import { ToolsConfig } from '../tools';
20+
import { Catalog } from './catalog';
2121

2222
import path = require('path');
2323
import globby = require('globby');
24+
2425
const waitPort = require('wait-port');
2526
const getPort = require('get-port');
2627

@@ -427,12 +428,12 @@ export class Component extends OpenShiftItem {
427428
const componentName = await Component.getName('Component name', componentList, application.getName());
428429

429430
if (!componentName) return null;
430-
431-
const componentTypeName = await window.showQuickPick(Component.odo.getComponentTypes(), {placeHolder: "Component type", ignoreFocusOut: true});
431+
const catalog = new Catalog();
432+
const componentTypeName = await window.showQuickPick(catalog.getComponentNames(), {placeHolder: "Component type", ignoreFocusOut: true});
432433

433434
if (!componentTypeName) return null;
434435

435-
const componentTypeVersion = await window.showQuickPick(Component.odo.getComponentTypeVersions(componentTypeName), {placeHolder: "Component type version", ignoreFocusOut: true});
436+
const componentTypeVersion = await window.showQuickPick(catalog.getComponentVersions(componentTypeName), {placeHolder: "Component type version", ignoreFocusOut: true});
436437

437438
if (!componentTypeVersion) return null;
438439
await Progress.execFunctionWithProgress(`Creating new Component '${componentName}'`, () => Component.odo.createComponentFromFolder(application, componentTypeName, componentTypeVersion, componentName, workspacePath));
@@ -449,12 +450,12 @@ export class Component extends OpenShiftItem {
449450
const componentName = await Component.getName('Component name', componentList, application.getName());
450451

451452
if (!componentName) return null;
452-
453-
const componentTypeName = await window.showQuickPick(Component.odo.getComponentTypes(), {placeHolder: "Component type", ignoreFocusOut: true});
453+
const catalog = new Catalog();
454+
const componentTypeName = await window.showQuickPick(catalog.getComponentNames(), {placeHolder: "Component type", ignoreFocusOut: true});
454455

455456
if (!componentTypeName) return null;
456457

457-
const componentTypeVersion = await window.showQuickPick(Component.odo.getComponentTypeVersions(componentTypeName), {placeHolder: "Component type version", ignoreFocusOut: true});
458+
const componentTypeVersion = await window.showQuickPick(catalog.getComponentVersions(componentTypeName), {placeHolder: "Component type version", ignoreFocusOut: true});
458459

459460
if (!componentTypeVersion) return null;
460461

@@ -494,12 +495,12 @@ export class Component extends OpenShiftItem {
494495
const componentName = await Component.getName('Component name', componentList, application.getName());
495496

496497
if (!componentName) return null;
497-
498-
const componentTypeName = await window.showQuickPick(Component.odo.getComponentTypes(), {placeHolder: "Component type", ignoreFocusOut: true});
498+
const catalog = new Catalog();
499+
const componentTypeName = await window.showQuickPick(catalog.getComponentNames(), {placeHolder: "Component type", ignoreFocusOut: true});
499500

500501
if (!componentTypeName) return null;
501502

502-
const componentTypeVersion = await window.showQuickPick(Component.odo.getComponentTypeVersions(componentTypeName), {placeHolder: "Component type version", ignoreFocusOut: true});
503+
const componentTypeVersion = await window.showQuickPick(catalog.getComponentVersions(componentTypeName), {placeHolder: "Component type version", ignoreFocusOut: true});
503504

504505
if (!componentTypeVersion) return null;
505506

@@ -534,12 +535,12 @@ export class Component extends OpenShiftItem {
534535
const componentName = await Component.getName('Component name', componentList, application.getName());
535536

536537
if (!componentName) return null;
537-
538-
const componentTypeName = await window.showQuickPick(Component.odo.getComponentTypes(), {placeHolder: "Component type", ignoreFocusOut: true});
538+
const catalog = new Catalog();
539+
const componentTypeName = await window.showQuickPick(catalog.getComponentNames(), {placeHolder: "Component type", ignoreFocusOut: true});
539540

540541
if (!componentTypeName) return null;
541542

542-
const componentTypeVersion = await window.showQuickPick(Component.odo.getComponentTypeVersions(componentTypeName), {placeHolder: "Component type version", ignoreFocusOut: true});
543+
const componentTypeVersion = await window.showQuickPick(catalog.getComponentVersions(componentTypeName), {placeHolder: "Component type version", ignoreFocusOut: true});
543544

544545
if (!componentTypeVersion) return null;
545546

0 commit comments

Comments
 (0)