Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
20 changes: 11 additions & 9 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,9 +142,11 @@ export async function activate(extensionContext: ExtensionContext): Promise<any>
OdoImpl.Instance.loadWorkspaceComponents(event);
});

OdoImpl.Instance.loadWorkspaceComponents(null);
await ComponentTypesView.instance.getAllComponents().then(() => {
Comment thread
msivasubramaniaan marked this conversation as resolved.
Outdated
OdoImpl.Instance.loadWorkspaceComponents(null);
Comment thread
msivasubramaniaan marked this conversation as resolved.
Outdated

startTelemetry(extensionContext);
startTelemetry(extensionContext);
});

return {
verifyBundledBinaries,
Expand Down
1 change: 0 additions & 1 deletion src/odo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,6 @@ export class OdoImpl implements Odo {
if (devFileComponents) {
devFileComponents.map((item) => devfileItems.push(new ComponentTypeAdapter(item.Name, undefined, item.Description, undefined, item.Registry.Name)));
}

return devfileItems;
}

Expand Down
69 changes: 60 additions & 9 deletions src/registriesView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ 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';

type ComponentType = Registry;

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

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

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

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

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

public async getAllComponents(): Promise<boolean> {
return new Promise<boolean>((resolve) => {
const compDescs: Set<ComponentTypeDescription> = new Set<ComponentTypeDescription>();
void getInstance().getCompTypesJson().then(async (devFileComponentTypes: DevfileComponentType[]) => {
const components = new Set<string>();
Comment thread
msivasubramaniaan marked this conversation as resolved.
Outdated
getInstance().getComponentTypesOfJSON(devFileComponentTypes).map((comp) => {
components.add(comp.name);
});
await this.getRegistries();
Array.from(components).map((compName: string) => {
Comment thread
msivasubramaniaan marked this conversation as resolved.
Outdated
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);
});
if (devFileComponentTypes.length === compDescs.size) {
this.compDescriptions.clear();
this.compDescriptions = compDescs;
resolve(true);
Comment thread
msivasubramaniaan marked this conversation as resolved.
Outdated
}
}).catch(() => {
this.compDescriptions.clear();
resolve(true);
});
});
});
});
}

// eslint-disable-next-line class-methods-use-this
async getChildren(parent: ComponentType): Promise<ComponentType[]> {
let children: ComponentType[] = [];
Expand Down Expand Up @@ -227,8 +274,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 +285,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();
await ComponentTypesView.instance.getAllComponents().then(() =>
RegistryViewLoader.refresh()
);
}

@vsCommand('openshift.componentTypesView.registry.remove')
Expand All @@ -261,7 +310,9 @@ export class ComponentTypesView implements TreeDataProvider<ComponentType> {
if (yesNo === 'Yes') {
await OdoImpl.Instance.removeRegistry(registry.Name);
ComponentTypesView.instance.removeRegistry(registry);
RegistryViewLoader.refresh();
await ComponentTypesView.instance.getAllComponents().then(() =>
RegistryViewLoader.refresh()
);
}
}

Expand Down
59 changes: 14 additions & 45 deletions src/webview/devfile-registry/registryViewLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,12 @@ 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';

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 +111,21 @@ 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) => {
panel.webview.postMessage(
{
action: eventActionName,
error: '500: Internal Server Error, Please try later'
}
);
});
});
});
const registries = ComponentTypesView.instance.getListOfRegistries();
const componentDescriptions = ComponentTypesView.instance.getCompDescriptions();
panel.webview.postMessage(
{
action: eventActionName,
compDescriptions: Array.from(componentDescriptions),
registries: registries
}
);
}