Skip to content

Commit 1b911dd

Browse files
authored
Adds logic to display noMatchingResources for multiple container registry steps (#471)
1 parent fdc6018 commit 1b911dd

File tree

5 files changed

+41
-15
lines changed

5 files changed

+41
-15
lines changed

src/commands/deployImage/imageSource/containerRegistry/RegistryRepositoriesListBaseStep.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,24 @@
55

66
import { AzureWizardPromptStep } from "@microsoft/vscode-azext-utils";
77
import type { QuickPickItem } from "vscode";
8-
import { QuickPicksCache, loadMoreQp } from "../../../../constants";
8+
import { QuickPicksCache, loadMoreQp, noMatchingResourcesQp } from "../../../../constants";
99
import { localize } from "../../../../utils/localize";
1010
import type { IContainerRegistryImageContext } from "./IContainerRegistryImageContext";
1111

1212
export abstract class RegistryRepositoriesListStepBase extends AzureWizardPromptStep<IContainerRegistryImageContext> {
1313
public async prompt(context: IContainerRegistryImageContext): Promise<void> {
1414
const picksCache: QuickPicksCache = { cache: [], next: null };
1515
const placeHolder: string = localize('selectRepo', 'Select a repository');
16-
let result: QuickPickItem;
16+
let result: QuickPickItem | undefined;
1717

1818
do {
19-
result = await context.ui.showQuickPick(this.getPicks(context, picksCache), { placeHolder });
20-
} while (result === loadMoreQp)
19+
if (result === noMatchingResourcesQp) {
20+
// Don't need to store any data since there's only one pick available
21+
await context.ui.showQuickPick([noMatchingResourcesQp], { placeHolder });
22+
} else {
23+
result = await context.ui.showQuickPick(this.getPicks(context, picksCache), { placeHolder });
24+
}
25+
} while (result === noMatchingResourcesQp || result === loadMoreQp)
2126

2227
context.repositoryName = result.label;
2328
}

src/commands/deployImage/imageSource/containerRegistry/acr/AcrListStep.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { ContainerRegistryManagementClient, Registry } from "@azure/arm-con
77
import type { ResourceGroup } from "@azure/arm-resources";
88
import { LocationListStep, ResourceGroupListStep, getResourceGroupFromId, uiUtils } from "@microsoft/vscode-azext-azureutils";
99
import { AzureWizardExecuteStep, AzureWizardPromptStep, IAzureQuickPickItem, ISubscriptionActionContext, IWizardOptions, nonNullProp } from "@microsoft/vscode-azext-utils";
10-
import { ImageSource, acrDomain, currentlyDeployed, quickStartImageName } from "../../../../../constants";
10+
import { ImageSource, acrDomain, currentlyDeployed, noMatchingResources, noMatchingResourcesQp, quickStartImageName } from "../../../../../constants";
1111
import { createContainerRegistryManagementClient } from "../../../../../utils/azureClients";
1212
import { parseImageName } from "../../../../../utils/imageNameUtils";
1313
import { localize } from "../../../../../utils/localize";
@@ -24,7 +24,13 @@ import { SkuListStep } from "./createAcr/SkuListStep";
2424
export class AcrListStep extends AzureWizardPromptStep<IContainerRegistryImageContext> {
2525
public async prompt(context: IContainerRegistryImageContext): Promise<void> {
2626
const placeHolder: string = localize('selectRegistry', 'Select an Azure Container Registry');
27-
context.registry = (await context.ui.showQuickPick(this.getPicks(context), { placeHolder })).data;
27+
28+
let result: Registry | typeof noMatchingResources | undefined;
29+
do {
30+
result = (await context.ui.showQuickPick(this.getPicks(context), { placeHolder })).data;
31+
} while (result === noMatchingResources)
32+
33+
context.registry = result;
2834
}
2935

3036
public shouldPrompt(context: IContainerRegistryImageContext): boolean {
@@ -63,7 +69,7 @@ export class AcrListStep extends AzureWizardPromptStep<IContainerRegistryImageCo
6369
return undefined;
6470
}
6571

66-
public async getPicks(context: IContainerRegistryImageContext): Promise<IAzureQuickPickItem<Registry | undefined>[]> {
72+
public async getPicks(context: IContainerRegistryImageContext): Promise<IAzureQuickPickItem<Registry | typeof noMatchingResources | undefined>[]> {
6773
const registries: Registry[] = await AcrListStep.getRegistries(context);
6874

6975
// Try to suggest a registry only when the user is deploying to a Container App
@@ -86,7 +92,7 @@ export class AcrListStep extends AzureWizardPromptStep<IContainerRegistryImageCo
8692
}
8793
}
8894

89-
const picks: IAzureQuickPickItem<Registry | undefined>[] = [];
95+
const picks: IAzureQuickPickItem<Registry | typeof noMatchingResources | undefined>[] = [];
9096

9197
// The why of `suppressCreate` in a nutshell: https://github.com/microsoft/vscode-azurecontainerapps/issues/78#issuecomment-1090686282
9298
const suppressCreate: boolean = context.imageSource !== ImageSource.RemoteAcrBuild;
@@ -98,6 +104,10 @@ export class AcrListStep extends AzureWizardPromptStep<IContainerRegistryImageCo
98104
});
99105
}
100106

107+
if (!picks.length && !registries.length) {
108+
picks.push(noMatchingResourcesQp);
109+
}
110+
101111
return picks.concat(
102112
registries.map((r) => {
103113
return !!suggestedRegistry && r.loginServer === suggestedRegistry ?

src/commands/deployImage/imageSource/containerRegistry/acr/AcrRepositoriesListStep.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
* Copyright (c) Microsoft Corporation. All rights reserved.
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
5+
56
import { uiUtils } from "@microsoft/vscode-azext-azureutils";
67
import { nonNullValue } from "@microsoft/vscode-azext-utils";
78
import type { QuickPickItem } from "vscode";
8-
import { acrDomain, currentlyDeployed, quickStartImageName } from "../../../../../constants";
9+
import { acrDomain, currentlyDeployed, noMatchingResourcesQp, quickStartImageName } from "../../../../../constants";
910
import { createContainerRegistryClient } from "../../../../../utils/azureClients";
1011
import { parseImageName } from "../../../../../utils/imageNameUtils";
1112
import type { IContainerRegistryImageContext } from "../IContainerRegistryImageContext";
@@ -37,6 +38,10 @@ export class AcrRepositoriesListStep extends RegistryRepositoriesListStepBase {
3738
}
3839
}
3940

41+
if (!repositoryNames.length) {
42+
return [noMatchingResourcesQp];
43+
}
44+
4045
// Preferring 'suppressPersistence: true' over 'priority: highest' to avoid the possibility of a double parenthesis appearing in the description
4146
return repositoryNames.map((rn) => {
4247
return !!suggestedRepository && rn === suggestedRepository ?

src/commands/deployImage/imageSource/containerRegistry/dockerHub/DockerHubContainerRepositoryListStep.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55

66
import { nonNullProp } from "@microsoft/vscode-azext-utils";
77
import type { QuickPickItem } from "vscode";
8-
import { QuickPicksCache, currentlyDeployed, dockerHubDomain, loadMoreQp, quickStartImageName } from "../../../../../constants";
8+
import { QuickPicksCache, currentlyDeployed, dockerHubDomain, loadMoreQp, noMatchingResourcesQp, quickStartImageName } from "../../../../../constants";
99
import { parseImageName } from "../../../../../utils/imageNameUtils";
10-
import { localize } from "../../../../../utils/localize";
1110
import type { IContainerRegistryImageContext } from "../IContainerRegistryImageContext";
1211
import { RegistryRepositoriesListStepBase } from "../RegistryRepositoriesListBaseStep";
1312
import { getLatestContainerAppImage } from "../getLatestContainerImage";
@@ -17,9 +16,8 @@ import type { DockerHubV2Repository } from "./DockerHubV2Types";
1716
export class DockerHubContainerRepositoryListStep extends RegistryRepositoriesListStepBase {
1817
public async getPicks(context: IContainerRegistryImageContext, cachedPicks: QuickPicksCache): Promise<QuickPickItem[]> {
1918
const response = await getReposForNamespace(context, nonNullProp(context, 'dockerHubNamespace'), cachedPicks.next);
20-
2119
if (response.count === 0) {
22-
await context.ui.showWarningMessage(localize('noRepos', 'Unable to find any repositories associated to namespace "{0}"', context.dockerHubNamespace), { modal: true });
20+
return [noMatchingResourcesQp];
2321
}
2422

2523
// Try to suggest a repository only when the user is deploying to a Container App
@@ -43,12 +41,12 @@ export class DockerHubContainerRepositoryListStep extends RegistryRepositoriesLi
4341
}
4442

4543
// Preferring 'suppressPersistence: true' over 'priority: highest' to avoid the possibility of a double parenthesis appearing in the description
46-
const quickPicks: QuickPickItem[] = response.results.map((r) => {
44+
const picks: QuickPickItem[] = response.results.map((r) => {
4745
return !!suggestedRepository && r.name === suggestedRepository ?
4846
{ label: r.name, description: r.description ? `${r.description} ${currentlyDeployed}` : currentlyDeployed, suppressPersistence: true } :
4947
{ label: r.name, description: r.description, suppressPersistence: srExists }
5048
});
51-
cachedPicks.cache.push(...quickPicks);
49+
cachedPicks.cache.push(...picks);
5250

5351
if (response.next) {
5452
cachedPicks.next = response.next;

src/constants.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ export type SupportedRegistries = 'azurecr.io' | 'docker.io';
6969

7070
export const browseItem: IAzureQuickPickItem<undefined> = { label: `$(file-directory) ${localize('browse', 'Browse...')}`, description: '', data: undefined };
7171
export const loadMoreQp: IAzureQuickPickItem = { label: '$(sync) Load More', data: undefined, suppressPersistence: true };
72+
73+
export const noMatchingResources = 'noMatchingResources';
74+
export const noMatchingResourcesQp: IAzureQuickPickItem<typeof noMatchingResources> = {
75+
label: localize('noMatchingResources', 'No matching resources found.'),
76+
description: '',
77+
data: noMatchingResources
78+
};
79+
7280
export type QuickPicksCache = { cache: QuickPickItem[], next: string | null };
7381

7482
export const vscodeFolder: string = '.vscode';

0 commit comments

Comments
 (0)