Skip to content

Commit 99cb268

Browse files
msivasubramaniaandgolovin
authored andcommitted
handled error case if no devfile registry available
Signed-off-by: msivasubramaniaan <msivasub@redhat.com>
1 parent 47c2296 commit 99cb268

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

src/registriesView.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,16 @@ export class ComponentTypesView implements TreeDataProvider<ComponentType> {
7373
return {
7474
label: element.name,
7575
contextValue: ContextType.DEVFILE_REGISTRY,
76-
tooltip: `Devfile Registry\nName: ${element.name}\nURL: ${element.name}`,
76+
tooltip: `Devfile Registry\nName: ${element.name}\nURL: ${element.url}`,
7777
collapsibleState: TreeItemCollapsibleState.None,
7878
iconPath: new vscode.ThemeIcon('note')
7979
};
8080
}
8181

8282
addRegistry(newRegistry: Registry): void {
83+
if(!this.registries){
84+
this.registries = [];
85+
}
8386
this.registries.push(newRegistry);
8487
this.refresh(false);
8588
this.reveal(newRegistry);
@@ -243,7 +246,7 @@ export class ComponentTypesView implements TreeDataProvider<ComponentType> {
243246
if (!validator.matches(trimmedValue, '^[a-zA-Z0-9]+$')) {
244247
return 'Registry name can have only alphabet characters and numbers';
245248
}
246-
if (registries.find((registry) => registry.name !== registryContext?.name && registry.name === value)) {
249+
if (registries?.find((registry) => registry.name !== registryContext?.name && registry.name === value)) {
247250
return `Registry name '${value}' is already used`;
248251
}
249252
},
@@ -261,7 +264,7 @@ export class ComponentTypesView implements TreeDataProvider<ComponentType> {
261264
if (!validator.isURL(trimmedValue)) {
262265
return 'Entered URL is invalid';
263266
}
264-
if (registries.find((registry) => registry.name !== registryContext?.name && registry.url === value)) {
267+
if (registries?.find((registry) => registry.name !== registryContext?.name && registry.url === value)) {
265268
return `Registry with entered URL '${value}' already exists`;
266269
}
267270
},
@@ -289,7 +292,7 @@ export class ComponentTypesView implements TreeDataProvider<ComponentType> {
289292
*/
290293

291294
if (registryContext) {
292-
const notChangedRegisty = registries.find((registry) => registry.name === regName && registry.url === regURL && registry.secure === (secure === 'Yes'));
295+
const notChangedRegisty = registries?.find((registry) => registry.name === regName && registry.url === regURL && registry.secure === (secure === 'Yes'));
293296
if (notChangedRegisty) {
294297
return null;
295298
}

src/webview/devfile-registry/registryViewLoader.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,18 +132,27 @@ export default class RegistryViewLoader {
132132

133133
function getAllComponents(eventActionName: string, url?: string, error?: string) {
134134
let registries = ComponentTypesView.instance.getListOfRegistries();
135-
if (url && url.length > 0) {
136-
registries = registries.filter((registry: Registry) => registry.url === url);
137-
}
138-
const componentDescriptions = ComponentTypesView.instance.getCompDescriptions();
139-
panel?.webview.postMessage(
140-
{
141-
action: eventActionName,
142-
compDescriptions: Array.from(componentDescriptions),
143-
registries: registries,
144-
errorMessage: error
135+
if (!registries) {
136+
panel?.webview.postMessage(
137+
{
138+
action: eventActionName,
139+
errorMessage: 'No Devfile registries configured'
140+
}
141+
);
142+
} else {
143+
if (url && url.length > 0) {
144+
registries = registries.filter((registry: Registry) => registry.url === url);
145145
}
146-
);
146+
const componentDescriptions = ComponentTypesView.instance.getCompDescriptions();
147+
panel?.webview.postMessage(
148+
{
149+
action: eventActionName,
150+
compDescriptions: Array.from(componentDescriptions),
151+
registries: registries,
152+
errorMessage: error
153+
}
154+
);
155+
}
147156
}
148157

149158
ComponentTypesView.instance.subject.subscribe((value: string) => {

0 commit comments

Comments
 (0)