Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@
"onCommand:openshift.component.watch.terminate",
"onCommand:openshift.component.watch.showLog",
"onCommand:openshift.component.deployRootWorkspaceFolder",
"onCommand:openshift.componentTypesView.registry.closeView",
"onCommand:openshift.catalog.listComponents",
"onCommand:openshift.catalog.listServices",
"onCommand:openshift.url.create",
Expand Down Expand Up @@ -873,6 +874,11 @@
"title": "Remove",
"category": "OpenSift"
},
{
"command": "openshift.componentTypesView.registry.edit",
"title": "Edit",
"category": "OpenSift"
},
{
"command": "openshift.componentTypesView.registry.openInBrowser",
"title": "Open in Browser",
Expand Down Expand Up @@ -1159,6 +1165,10 @@
"command": "openshift.componentTypesView.registry.remove",
"when": "false"
},
{
"command": "openshift.componentTypesView.registry.edit",
"when": "false"
},
{
"command": "openshift.componentTypesView.registry.openInView",
"when": "false"
Expand Down Expand Up @@ -1549,6 +1559,11 @@
"command": "openshift.component.revealInExplorer",
"when": "view == openshiftComponentsView && viewItem == openshift.component"
},
{
"command": "openshift.componentTypesView.registry.edit",
"when": "view == openshiftComponentTypesView && viewItem == devfileRegistry && viewItem != DefaultdevfileRegistry",
"group": "1@0"
},
{
"command": "openshift.componentTypesView.registry.remove",
"when": "view == openshiftComponentTypesView && viewItem == devfileRegistry && viewItem != DefaultdevfileRegistry",
Expand Down
55 changes: 40 additions & 15 deletions src/componentTypesView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright (c) Red Hat, Inc. All rights reserved.
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*-----------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';
import {
TreeDataProvider,
TreeItem,
Expand Down Expand Up @@ -87,8 +87,12 @@ export class ComponentTypesView implements TreeDataProvider<ComponentType> {
}

public async getRegistries(): Promise<Registry[]> {
if (!this.registries) {
this.registries = await this.odo.getRegistries();
try {
if (!this.registries) {
this.registries = await this.odo.getRegistries();
}
} catch (err) {
this.registries = [];
}
return this.registries;
}
Expand Down Expand Up @@ -145,7 +149,7 @@ export class ComponentTypesView implements TreeDataProvider<ComponentType> {
// TODO: report actual url only for default odo repository
throw new VsCommandError(
err.toString(),
'Unable to open s`ample project repository',
'Unable to open sample project repository',
);
}
} else {
Expand Down Expand Up @@ -173,21 +177,22 @@ export class ComponentTypesView implements TreeDataProvider<ComponentType> {
}

@vsCommand('openshift.componentTypesView.registry.add')
public static async addRegistryCmd(): Promise<void> {
public static async addRegistryCmd(registryContext: Registry): Promise<void> {
// ask for registry
const registries = await ComponentTypesView.instance.getRegistries();
const regName = await window.showInputBox({
prompt: 'Provide registry name to display in the view',
value: registryContext?.Name,
prompt: registryContext ? 'Edit registry name' : 'Provide registry name to display in the view',
Comment thread
msivasubramaniaan marked this conversation as resolved.
placeHolder: 'Registry Name',
validateInput: async (value) => {
validateInput: (value) => {
const trimmedValue = value.trim();
if (trimmedValue.length === 0) {
return 'Registry name cannot be empty';
}
if (!validator.matches(trimmedValue, '^[a-zA-Z0-9]+$')) {
return 'Registry name can have only alphabet characters and numbers';
}
const registries = await ComponentTypesView.instance.getRegistries();
if (registries.find((registry) => registry.Name === value)) {
if (registries.find((registry) => registry.Name !== registryContext?.Name && registry.Name === value)) {
return `Registry name '${value}' is already used`;
}
},
Expand All @@ -197,15 +202,15 @@ export class ComponentTypesView implements TreeDataProvider<ComponentType> {

const regURL = await window.showInputBox({
ignoreFocusOut: true,
prompt: 'Provide registry URL to display in the view',
value: registryContext?.URL,
prompt: registryContext ? 'Edit registry URL' : 'Provide registry URL to display in the view',
placeHolder: 'Registry URL',
validateInput: async (value) => {
validateInput: (value) => {
const trimmedValue = value.trim();
if (!validator.isURL(trimmedValue)) {
return 'Entered URL is invalid';
}
const registries = await ComponentTypesView.instance.getRegistries();
if (registries.find((registry) => registry.URL === value)) {
if (registries.find((registry) => registry.Name !== registryContext?.Name && registry.URL === value)) {
return `Registry with entered URL '${value}' already exists`;
}
},
Expand All @@ -225,23 +230,43 @@ export class ComponentTypesView implements TreeDataProvider<ComponentType> {
if (!token) return null;
}

/**
* For edit, remove the existing registry
*/

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 newRegistry = await OdoImpl.Instance.addRegistry(regName, regURL, token);
ComponentTypesView.instance.addRegistry(newRegistry);

RegistryViewLoader.refresh();
}

@vsCommand('openshift.componentTypesView.registry.remove')
public static async removeRegistry(registry: Registry): Promise<void> {
const yesNo = await window.showInformationMessage(
public static async removeRegistry(registry: Registry, isEdit?: boolean): Promise<void> {
const yesNo = isEdit ? 'Yes' : await window.showInformationMessage(
`Remove registry '${registry.Name}'?`,
'Yes',
'No',
);
if (yesNo === 'Yes') {
await OdoImpl.Instance.removeRegistry(registry.Name);
ComponentTypesView.instance.removeRegistry(registry);
RegistryViewLoader.refresh();
}
}

@vsCommand('openshift.componentTypesView.registry.edit')
public static async editRegistry(registry: Registry): Promise<void> {
await vscode.commands.executeCommand('openshift.componentTypesView.registry.add', registry);
}

@vsCommand('openshift.componentTypesView.registry.openInBrowser')
public static async openRegistryWebSite(registry: Registry): Promise<void> {
await commands.executeCommand('vscode.open', Uri.parse(registry.URL));
Expand Down
3 changes: 2 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ export async function activate(extensionContext: ExtensionContext): Promise<any>
'./k8s/console',
'./oc',
'./componentTypesView',
'./componentsView'
'./componentsView',
'./webview/devfile-registry/registryViewLoader'
)),
commands.registerCommand('clusters.openshift.useProject', (context) =>
commands.executeCommand('extension.vsKubernetesUseNamespace', context),
Expand Down
6 changes: 5 additions & 1 deletion src/webview/devfile-registry/app/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,12 @@ export const Home: React.FC<DefaultProps> = ({ }) => {
setCompDescriptions(message.data.compDescriptions);
setRegistries(message.data.registries);
setFilteredcompDescriptions(getFilteredCompDesc(message.data.registries, message.data.compDescriptions, searchValue));

}
} else if (message.data.action === 'loadingComponents') {
setError('');
setFilteredcompDescriptions([]);
setCompDescriptions([]);
setSearchValue('');
}
});
});
Expand Down
89 changes: 53 additions & 36 deletions src/webview/devfile-registry/registryViewLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { stringify } from 'yaml';
import { ComponentTypesView } from '../../componentTypesView';
import { StarterProject } from '../../odo/componentTypeDescription';
import { DevfileComponentType } from '../../odo/componentType';
import { vsCommand } from '../../vscommand';

let panel: vscode.WebviewPanel;
let compDescriptions = new Set<any>();
Expand All @@ -20,41 +21,7 @@ async function devfileRegistryViewerMessageListener(event: any): Promise<any> {
let starterProject = event.selectedProject;
switch (event?.action) {
case 'getAllComponents':
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: event.action,
compDescriptions: Array.from(compDescriptions),
registries: registries
}
);
}
}).catch((reason) => {
panel.webview.postMessage(
{
action: event.action,
error: '500: Internal Server Error, Please try later'
}
);
});
});
});
getAllComponents(event.action);
break;
case 'getYAML':
const yaml = stringify(event.data, { indent: 4 });
Expand Down Expand Up @@ -85,7 +52,6 @@ async function devfileRegistryViewerMessageListener(event: any): Promise<any> {
break;
}
}

export default class RegistryViewLoader {
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
static get extensionPath() {
Expand All @@ -98,6 +64,7 @@ export default class RegistryViewLoader {
if (panel) {
// If we already have a panel, show it in the target column
panel.reveal(vscode.ViewColumn.One);
getAllComponents('getAllComponents');
} else {
panel = vscode.window.createWebviewPanel('devFileRegistryView', title, vscode.ViewColumn.One, {
enableScripts: true,
Expand Down Expand Up @@ -135,4 +102,54 @@ export default class RegistryViewLoader {
.replace('%BASE_URL%', `${reactAppUri}`)
.replace('<!-- meta http-equiv="Content-Security-Policy" -->', meta);
}

@vsCommand('openshift.componentTypesView.registry.closeView')
static async closeRegistryInWebview(): Promise<void> {
panel?.dispose();
}

static refresh(): void {
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'
}
);
});
});
});
}