Skip to content

Commit

Permalink
Show only registry node in registrys view
Browse files Browse the repository at this point in the history
This PR related to redhat-developer#2417.

Signed-off-by: Denis Golovin dgolovin@redhat.com
  • Loading branch information
dgolovin committed May 12, 2022
1 parent 822b503 commit f22107b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 161 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@
},
{
"id": "openshiftComponentTypesView",
"name": "Component Types"
"name": "Registries"
},
{
"id": "openshiftWatchView",
Expand Down
169 changes: 9 additions & 160 deletions src/componentTypesView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,15 @@ import {
TreeItemCollapsibleState,
commands,
} from 'vscode';
import * as path from 'path';
import { CliExitData } from './cli';
import { getInstance, Odo, OdoImpl } from './odo';
import { Command } from './odo/command';
import {
ComponentTypeDescription,
ComponentTypesJson,
DevfileComponentType,
isDevfileComponent,
isRegistry,
Registry,
} from './odo/componentType';
import { isStarterProject, StarterProject } from './odo/componentTypeDescription';
import { vsCommand, VsCommandError } from './vscommand';
import { Platform } from './util/platform';
import { vsCommand } from './vscommand';
import validator from 'validator';

type ComponentType = DevfileComponentType | StarterProject | Registry;
type ComponentType = Registry;

export enum ContextType {
DEVFILE_COMPONENT_TYPE = 'devfileComponentType',
Expand Down Expand Up @@ -72,77 +63,12 @@ export class ComponentTypesView implements TreeDataProvider<ComponentType> {

// eslint-disable-next-line class-methods-use-this
getTreeItem(element: ComponentType): TreeItem | Thenable<TreeItem> {
if (isRegistry(element)) {
return {
label: element.Name,
contextValue: ContextType.DEVFILE_REGISTRY,
tooltip: `Devfile Registry\nName: ${element.Name}\nURL: ${element.URL}`,
collapsibleState: TreeItemCollapsibleState.Collapsed,
};
}
if (isStarterProject(element)) {
return {
label: element.name,
contextValue: ContextType.DEVFILE_STARTER_PROJECT,
tooltip: `Starter Project\nName: ${element.name}\nDescription: ${
element.description ? element.description : 'n/a'
}`,
description: element.description,
iconPath: {
dark: Uri.file(
path.join(
__dirname,
'..',
'..',
'images',
'component',
'start-project-dark.png',
),
),
light: Uri.file(
path.join(
__dirname,
'..',
'..',
'images',
'component',
'start-project-light.png',
),
),
},
};
}
return {
label: `${element.DisplayName}`,
contextValue: ContextType.DEVFILE_COMPONENT_TYPE,
iconPath: {
dark: Uri.file(
path.join(
__dirname,
'..',
'..',
'images',
'component',
'component-type-dark.png',
),
),
light: Uri.file(
path.join(
__dirname,
'..',
'..',
'images',
'component',
'component-type-light.png',
),
),
},
tooltip: `Component Type\nName: ${element.Name}\nKind: devfile\nDescription: ${
element.Description ? element.Description : 'n/a'
}`,
description: element.Description,
collapsibleState: TreeItemCollapsibleState.Collapsed,
};
return {
label: element.Name,
contextValue: ContextType.DEVFILE_REGISTRY,
tooltip: `Devfile Registry\nName: ${element.Name}\nURL: ${element.URL}`,
collapsibleState: TreeItemCollapsibleState.None,
};
}

public loadItems<I, O>(result: CliExitData, fetch: (data: I) => O[]): O[] {
Expand Down Expand Up @@ -179,45 +105,10 @@ export class ComponentTypesView implements TreeDataProvider<ComponentType> {

// eslint-disable-next-line class-methods-use-this
async getChildren(parent: ComponentType): Promise<ComponentType[]> {
let children: ComponentType[];
const addEnv = this.odo.getKubeconfigEnv();
let children: ComponentType[] = [];
if (!parent) {
this.registries = await this.getRegistries();
children = this.registries;
} else if (isRegistry(parent)) {
const result = await this.odo.execute(
Command.listCatalogComponentsJson(),
Platform.getUserHomePath(),
true,
addEnv,
);
children = this.loadItems<ComponentTypesJson, DevfileComponentType>(
result,
(data) => data.items,
);
children = children.filter(
(element: DevfileComponentType) => element.Registry.Name === parent.Name,
);
} else if (isDevfileComponent(parent)) {
const result: CliExitData = await this.odo.execute(
Command.describeCatalogComponent(parent.Name),
Platform.getUserHomePath(),
true,
addEnv,
);
const descriptions = this.loadItems<
ComponentTypeDescription[],
ComponentTypeDescription
>(result, (data) => data);
const description = descriptions.find(
(element) =>
element.RegistryName === parent.Registry.Name &&
element.Devfile.metadata.name === parent.Name,
);
children = description?.Devfile?.starterProjects.map((starter: StarterProject) => {
starter.typeName = parent.Name;
return starter;
});
}
return children;
}
Expand All @@ -243,48 +134,6 @@ export class ComponentTypesView implements TreeDataProvider<ComponentType> {
ComponentTypesView.instance.refresh();
}

public static getSampleRepositoryUrl(element: StarterProject): string {
const url = Object.values(element.git.remotes).find((prop) => typeof prop === 'string');
return url;
}

@vsCommand('openshift.componentType.openStarterProjectRepository')
public static async openRepositoryURL(element: StarterProject): Promise<void | string> {
const url: string = ComponentTypesView.getSampleRepositoryUrl(element);
if (url) {
try {
await commands.executeCommand('vscode.open', Uri.parse(url, true));
} catch (err) {
// TODO: report actual url only for default odo repository
throw new VsCommandError(
err.toString(),
'Unable to open s`ample project repository',
);
}
} else {
return 'Cannot find sample project repository url';
}
}

@vsCommand('openshift.componentType.cloneStarterProjectRepository')
public static async cloneRepository(element: StarterProject): Promise<void | string> {
const url: string = ComponentTypesView.getSampleRepositoryUrl(element);
if (url) {
try {
Uri.parse(url);
await commands.executeCommand('git.clone', url);
} catch (err) {
// TODO: report actual url only for default odo repository
throw new VsCommandError(
err.toString(),
'Unable to clone sample project repository',
);
}
} else {
return 'Cannot find sample project repository url';
}
}

@vsCommand('openshift.componentTypesView.registry.add')
public static async addRegistryCmd(): Promise<void> {
// ask for registry
Expand Down

0 comments on commit f22107b

Please sign in to comment.