Skip to content

Commit c39e174

Browse files
vrubezhnydatho7561
authored andcommitted
Fix Devfile Registry editor views for cases where the current Devfile Registry is removed
This will show an error instead of Devfile search form, a Devfile selection dialog, etc. and will ask if a user wants to close the view when the current Devfile Registry is removed. Signed-off-by: Victor Rubezhny <vrubezhny@redhat.com>
1 parent 2ebce38 commit c39e174

File tree

3 files changed

+51
-10
lines changed

3 files changed

+51
-10
lines changed

src/webview/common/devfileSearch.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { DevfileData, DevfileInfo, DevfileRegistryInfo } from '../../devfile-reg
3737
import { TemplateProjectIdentifier } from '../common/devfile';
3838
import { DevfileExplanation } from './devfileExplanation';
3939
import { DevfileListItem } from './devfileListItem';
40+
import { ErrorPage } from './errorPage';
4041
import { LoadScreen } from './loading';
4142
import { vsDarkCodeMirrorTheme, vsLightCodeMirrorTheme } from './vscode-theme';
4243

@@ -648,13 +649,15 @@ export function DevfileSearch(props: DevfileSearchProps) {
648649
const [searchText, setSearchText] = React.useState('');
649650

650651
const [showMore, setShowMore] = React.useState(false);
652+
const [createComponentErrorMessage, setCreateComponentErrorMessage] = React.useState('');
651653

652654
function respondToMessage(messageEvent: MessageEvent) {
653655
const message = messageEvent.data as Message;
654656
switch (message.action) {
655657
case 'devfileRegistries': {
656658
setDevfileRegistries((_devfileRegistries) => message.data);
657659
setDevfileInfos((_devfileInfos) => []);
660+
setSelectedDevfileInfo((_unused) => undefined);
658661
setSomeDevfileInfoRetrieved(_unused => false);
659662
window.vscodeApi.postMessage({ action: 'getDevfileInfos' });
660663
break;
@@ -672,6 +675,11 @@ export function DevfileSearch(props: DevfileSearchProps) {
672675
setDevfileTags((_devfileTags) => message.data);
673676
break;
674677
}
678+
case 'createComponentFailed': {
679+
setSomeDevfileInfoRetrieved(_unused => true);
680+
setCreateComponentErrorMessage(message.data);
681+
break;
682+
}
675683
default:
676684
break;
677685
}
@@ -758,6 +766,18 @@ export function DevfileSearch(props: DevfileSearchProps) {
758766
return <LoadScreen title="Retrieving list of Devfile Tags..." />;
759767
}
760768

769+
if (createComponentErrorMessage) {
770+
return (
771+
<>
772+
<Stack direction="column" height="100%" spacing={0.5}>
773+
<ErrorPage
774+
message={`${createComponentErrorMessage}`}
775+
/>
776+
</Stack>
777+
</>
778+
);
779+
}
780+
761781
const activeRegistries = registryEnabled //
762782
.filter((entry) => entry.enabled) //
763783
.map((entry) => entry.registryName);

src/webview/create-component/createComponentLoader.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export default class CreateComponentLoader {
8787
void sendUpdatedRegistries(CreateComponentLoader.panel);
8888
});
8989

90-
const capabiliiesySubscription = ComponentTypesView.instance.subject.subscribe(() => {
90+
const capabilitiesSubscription = ComponentTypesView.instance.subject.subscribe(() => {
9191
sendUpdatedCapabilities(CreateComponentLoader.panel);
9292
});
9393

@@ -98,7 +98,7 @@ export default class CreateComponentLoader {
9898
panel.onDidDispose(() => {
9999
void sendTelemetry('newComponentClosed');
100100
tagsSubscription.unsubscribe();
101-
capabiliiesySubscription.unsubscribe();
101+
capabilitiesSubscription.unsubscribe();
102102
registriesSubscription.unsubscribe();
103103
colorThemeDisposable.dispose();
104104
messageHandlerDisposable.dispose();

src/webview/devfile-registry/registryViewLoader.ts

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,39 @@ export default class RegistryViewLoader {
166166
return vscode.extensions.getExtension(ExtensionID).extensionPath
167167
}
168168

169+
private static doUpdateRegistries() {
170+
void sendUpdatedRegistries(RegistryViewLoader.panel).then((registries) => {
171+
if (RegistryViewLoader.url) { // Update title if registry name for the URL provided has changed
172+
const registryName = registries.find((registry) => registry.url === RegistryViewLoader.url)?.name;
173+
if (registryName) {
174+
RegistryViewLoader.panel.title = `Devfile Registry - ${registryName}`;
175+
} else {
176+
void RegistryViewLoader.panel.webview.postMessage({
177+
action: 'createComponentFailed',
178+
data: `No Devfile registries available for ${RegistryViewLoader.url}`
179+
});
180+
void vscode.window.showErrorMessage(
181+
`
182+
No Devfile registry available.
183+
Do you want to close the '${RegistryViewLoader.panel.title}' view?
184+
`,
185+
'Yes', 'No')
186+
.then((answer) => {
187+
if (answer === 'Yes') {
188+
void RegistryViewLoader.closeRegistryInWebview();
189+
}
190+
});
191+
}
192+
}
193+
})
194+
}
195+
169196
static async loadView(title: string, url?: string): Promise<vscode.WebviewPanel> {
170197
const localResourceRoot = vscode.Uri.file(path.join(RegistryViewLoader.extensionPath, 'out', 'devfile-registry', 'app'));
171198
if (RegistryViewLoader.panel) {
172199
if (RegistryViewLoader.url !== url) {
173200
RegistryViewLoader.url = url;
201+
RegistryViewLoader.doUpdateRegistries();
174202
}
175203
// If we already have a panel, show it in the target column
176204
RegistryViewLoader.panel.reveal(vscode.ViewColumn.One);
@@ -187,14 +215,7 @@ export default class RegistryViewLoader {
187215
const messageDisposable = RegistryViewLoader.panel.webview.onDidReceiveMessage(devfileRegistryViewerMessageListener);
188216

189217
const registriesSubscription = ComponentTypesView.instance.subject.subscribe(() => {
190-
void sendUpdatedRegistries(RegistryViewLoader.panel).then((registries) => {
191-
if (RegistryViewLoader.url) { // Update title if registry name for the URL provided has changed
192-
const registryName = registries.find((registry) => registry.url === RegistryViewLoader.url)?.name;
193-
if (registryName) {
194-
RegistryViewLoader.panel.title = `Devfile Registry - ${registryName}`;
195-
}
196-
}
197-
})
218+
RegistryViewLoader.doUpdateRegistries();
198219
});
199220

200221
const capabiliiesySubscription = ComponentTypesView.instance.subject.subscribe(() => {

0 commit comments

Comments
 (0)