Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function migrateFromOdo018(): void {
}
}

async function verifyBundledBinaries(): Promise<{odoPath: string, ocPath: string}> {
async function verifyBundledBinaries(): Promise<{ odoPath: string, ocPath: string }> {
return {
odoPath: await ToolsConfig.detect('odo'),
ocPath: await ToolsConfig.detect('oc'),
Expand All @@ -63,8 +63,8 @@ export async function activate(extensionContext: ExtensionContext): Promise<any>
migrateFromOdo018();
Cluster.extensionContext = extensionContext;
TokenStore.extensionContext = extensionContext;
const crcStatusItem = window.createStatusBarItem(StatusBarAlignment.Left);
crcStatusItem.command = 'openshift.explorer.stopCluster';
const crcStatusItem = window.createStatusBarItem(StatusBarAlignment.Left);
crcStatusItem.command = 'openshift.explorer.stopCluster';
const disposable = [
...(await registerCommands(
'./k8s/route',
Expand Down Expand Up @@ -127,10 +127,10 @@ export async function activate(extensionContext: ExtensionContext): Promise<any>
});

function updateStatusBarItem(statusBarItem: StatusBarItem, text: string): void {
if (!workspace.getConfiguration('openshiftConnector').get('crcBinaryLocation')) {
statusBarItem.hide();
return;
}
if (!workspace.getConfiguration('openshiftConnector').get('crcBinaryLocation')) {
statusBarItem.hide();
return;
}
statusBarItem.text = `$(debug-stop) ${text}`;
statusBarItem.show();
}
Expand All @@ -142,6 +142,8 @@ export async function activate(extensionContext: ExtensionContext): Promise<any>
OdoImpl.Instance.loadWorkspaceComponents(event);
});

void ComponentTypesView.instance.getAllComponents();

OdoImpl.Instance.loadWorkspaceComponents(null);

startTelemetry(extensionContext);
Expand Down
11 changes: 0 additions & 11 deletions src/odo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,6 @@ export interface Odo {
getApplicationChildren(application: OpenShiftObject): Promise<OpenShiftObject[]>;
getComponents(application: OpenShiftObject, condition?: (value: OpenShiftObject) => boolean): Promise<OpenShiftObject[]>;
getCompTypesJson():Promise<DevfileComponentType[]>;
getComponentTypesOfJSON(devFileComponents: DevfileComponentType[]):ComponentTypeAdapter[];
getComponentTypes(): Promise<ComponentTypeAdapter[]>;
getComponentChildren(component: OpenShiftObject): Promise<OpenShiftObject[]>;
getRoutes(component: OpenShiftObject): Promise<OpenShiftObject[]>;
Expand Down Expand Up @@ -645,16 +644,6 @@ export class OdoImpl implements Odo {
return compTypesJson?.items;
}

public getComponentTypesOfJSON(devFileComponents: DevfileComponentType[]): ComponentType[] {
const devfileItems: ComponentTypeAdapter[] = [];

if (devFileComponents) {
devFileComponents.map((item) => devfileItems.push(new ComponentTypeAdapter(item.Name, undefined, item.Description, undefined, item.Registry.Name)));
}

return devfileItems;
}

public async getComponentTypes(): Promise<ComponentType[]> {
// if kc is produced, KUBECONFIG env var is empty or pointing

Expand Down
74 changes: 65 additions & 9 deletions src/registriesView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ import {
} from 'vscode';
import { getInstance, Odo, OdoImpl } from './odo';
import {
ComponentTypeDescription,
DevfileComponentType,
Registry,
} from './odo/componentType';
import { StarterProject } from './odo/componentTypeDescription';
import { vsCommand, VsCommandError } from './vscommand';
import validator from 'validator';
import RegistryViewLoader from './webview/devfile-registry/registryViewLoader';
import { Command } from './odo/command';
import { CliExitData } from './cli';
import { Subject } from 'rxjs';

type ComponentType = Registry;

Expand All @@ -45,6 +50,8 @@ export class ComponentTypesView implements TreeDataProvider<ComponentType> {

readonly odo: Odo = getInstance();
private registries: Registry[];
private readonly compDescriptions: Set<ComponentTypeDescription> = new Set<ComponentTypeDescription>();
public readonly subject: Subject<ComponentTypeDescription | string> = new Subject<ComponentTypeDescription | string>();

createTreeView(id: string): TreeView<ComponentType> {
if (!this.treeView) {
Expand Down Expand Up @@ -97,6 +104,49 @@ export class ComponentTypesView implements TreeDataProvider<ComponentType> {
return this.registries;
}

public getCompDescriptions(): Set<ComponentTypeDescription> {
return this.compDescriptions;
}

public setComponentTypeDesc(value: ComponentTypeDescription): void {
this.compDescriptions.add(value);
}

public getListOfRegistries(): Registry[] {
return this.registries;
}

public getAllComponents(): void {
ComponentTypesView.instance.subject.subscribe((compDesc: ComponentTypeDescription) => {
ComponentTypesView.instance.setComponentTypeDesc(compDesc);
});
const compDescs: Set<ComponentTypeDescription> = new Set<ComponentTypeDescription>();
void getInstance().getCompTypesJson().then(async (devFileComponentTypes: DevfileComponentType[]) => {
Comment thread
msivasubramaniaan marked this conversation as resolved.
const components = new Set<string>(devFileComponentTypes.map((devFileComponentType: DevfileComponentType) => devFileComponentType.Name));
await this.getRegistries();
components.forEach((compName: string) => {
getInstance().execute(Command.describeCatalogComponent(compName)).then((componentDesc: CliExitData) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const out: ComponentTypeDescription[] = JSON.parse(componentDesc.stdout);
out.forEach((component) => {
// eslint-disable-next-line max-nested-callbacks
component.Devfile?.starterProjects?.map((starter: StarterProject) => {
starter.typeName = compName;
});
compDescs.add(component);
this.subject.next(component);
});
if (devFileComponentTypes.length === compDescs.size) {
this.subject.next('Done');
}
}).catch(() => {
this.subject.complete();
this.subject.unsubscribe();
});
});
});
}

// eslint-disable-next-line class-methods-use-this
async getChildren(parent: ComponentType): Promise<ComponentType[]> {
let children: ComponentType[] = [];
Expand Down Expand Up @@ -227,8 +277,8 @@ export class ComponentTypesView implements TreeDataProvider<ComponentType> {
let token: string;
if (secure === 'Yes') {
token = await window.showInputBox({
placeHolder: 'Token to access the registry',
validateInput: (value) => value?.trim().length > 0 ? undefined : 'Token cannot be empty'
placeHolder: 'Token to access the registry',
validateInput: (value) => value?.trim().length > 0 ? undefined : 'Token cannot be empty'
});
if (!token) return null;
}
Expand All @@ -238,17 +288,19 @@ export class ComponentTypesView implements TreeDataProvider<ComponentType> {
*/

if (registryContext) {
const notChangedRegisty = registries.find((registry) => registry.Name === regName && registry.URL === regURL && registry.Secure === (secure === 'Yes'));
if (notChangedRegisty) {
return null;
}
await vscode.commands.executeCommand('openshift.componentTypesView.registry.remove', registryContext, true);
const notChangedRegisty = registries.find((registry) => registry.Name === regName && registry.URL === regURL && registry.Secure === (secure === 'Yes'));
if (notChangedRegisty) {
return null;
}
await vscode.commands.executeCommand('openshift.componentTypesView.registry.remove', registryContext, true);
}

const newRegistry = await OdoImpl.Instance.addRegistry(regName, regURL, token);
ComponentTypesView.instance.addRegistry(newRegistry);

RegistryViewLoader.refresh();
ComponentTypesView.instance.compDescriptions.clear();
ComponentTypesView.instance.getAllComponents();
RegistryViewLoader.refresh()
Comment thread
msivasubramaniaan marked this conversation as resolved.
Outdated
}

@vsCommand('openshift.componentTypesView.registry.remove')
Expand All @@ -261,7 +313,11 @@ export class ComponentTypesView implements TreeDataProvider<ComponentType> {
if (yesNo === 'Yes') {
await OdoImpl.Instance.removeRegistry(registry.Name);
ComponentTypesView.instance.removeRegistry(registry);
RegistryViewLoader.refresh();
if (!isEdit) {
ComponentTypesView.instance.compDescriptions.clear();
ComponentTypesView.instance.getAllComponents();
RegistryViewLoader.refresh();
Comment thread
msivasubramaniaan marked this conversation as resolved.
Outdated
}
}
}

Expand Down
68 changes: 28 additions & 40 deletions src/webview/devfile-registry/registryViewLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@ import * as vscode from 'vscode';
import * as path from 'path';
import * as fs from 'fs';
import { ExtenisonID } from '../../util/constants';
import { getInstance } from '../../odo';
import { Command } from '../../odo/command';
import { stringify } from 'yaml';
import { ComponentTypesView } from '../../registriesView';
import { StarterProject } from '../../odo/componentTypeDescription';
import { DevfileComponentType } from '../../odo/componentType';
import { ComponentTypesView } from '../../registriesView'
import { vsCommand } from '../../vscommand';
import { ExtCommandTelemetryEvent } from '../../telemetry';
import { ComponentTypeDescription } from '../../odo/componentType';
import { isString } from 'lodash';

let panel: vscode.WebviewPanel;
let compDescriptions = new Set<any>();

async function devfileRegistryViewerMessageListener(event: any): Promise<any> {
let starterProject = event.selectedProject;
Expand Down Expand Up @@ -116,47 +113,38 @@ export default class RegistryViewLoader {
}

static refresh(): void {
if(panel) {
panel.webview.postMessage({action: 'loadingComponents' });
getAllComponents('getAllComponents');
}
if (panel) {
panel.webview.postMessage({ action: 'loadingComponents' });
getAllComponents('getAllComponents');
}
}
}

function getAllComponents(eventActionName: string) {
compDescriptions.clear();
getInstance().getCompTypesJson().then(async (devFileComponentTypes: DevfileComponentType[]) => {
const components = new Set<string>();
getInstance().getComponentTypesOfJSON(devFileComponentTypes).map((comp) => {
components.add(comp.name);
});
const registries = await ComponentTypesView.instance.getRegistries();
Array.from(components).map(async (compName: string) => {
getInstance().execute(Command.describeCatalogComponent(compName)).then((componentDesc) => {
const out = JSON.parse(componentDesc.stdout);
out.forEach((component) => {
component.Devfile?.starterProjects?.map((starter: StarterProject) => {
starter.typeName = compName;
});
compDescriptions.add(component);
});
if (devFileComponentTypes.length === compDescriptions.size) {
panel.webview.postMessage(
{
action: eventActionName,
compDescriptions: Array.from(compDescriptions),
registries: registries
}
);
}
}).catch((reason) => {
const registries = ComponentTypesView.instance.getListOfRegistries();
const componentDescriptions = ComponentTypesView.instance.getCompDescriptions();
if (componentDescriptions.size === 0) {
const components: ComponentTypeDescription[] = [];
ComponentTypesView.instance.subject.subscribe((componentDescription: ComponentTypeDescription | string) => {
if (!isString(componentDescription)) {
components.push(componentDescription);
} else {
panel.webview.postMessage(
{
action: eventActionName,
error: '500: Internal Server Error, Please try later'
compDescriptions: components,
registries: registries
}
);
});
});
});
}
})
} else {
panel.webview.postMessage(
{
action: eventActionName,
compDescriptions: Array.from(componentDescriptions),
registries: registries
}
);
}
}