Skip to content

Commit

Permalink
Improve Registry Experience & Simplify Context Values (#4076)
Browse files Browse the repository at this point in the history
* added implementation

* added comments

* use RegistryQuickPickStep for everything

* fix regex

* fix viewproperties context value package json

* remove unnecessary method

* added back necessary logic

* Commit current progress

* Commit current progress

* adjust package.json

* fix azure typo

* preserve existing additional context value

* make regex more robust

---------

Co-authored-by: Brandon Waterloo [MSFT] <[email protected]>
  • Loading branch information
alexyaang and bwateratmsft authored Sep 19, 2023
1 parent d3da812 commit fbceb92
Show file tree
Hide file tree
Showing 25 changed files with 218 additions and 124 deletions.
11 changes: 6 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 13 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@
},
{
"command": "vscode-docker.registries.azure.deleteRegistry",
"when": "view == dockerRegistries && viewItem =~ /azureContainerRegistry/i",
"when": "view == dockerRegistries && viewItem =~ /azure;.*commonregistry/i",
"group": "regs_reg_2_destructive@1"
},
{
Expand All @@ -477,7 +477,7 @@
},
{
"command": "vscode-docker.registries.azure.deleteRepository",
"when": "view == dockerRegistries && viewItem =~ /azureContainerRepository/i",
"when": "view == dockerRegistries && viewItem =~ /azure;.*commonrepository/i",
"group": "regs_repo_2_destructive@1"
},
{
Expand All @@ -492,7 +492,7 @@
},
{
"command": "vscode-docker.registries.copyImageDigest",
"when": "view == dockerRegistries && viewItem =~ /registryV2Tag/i",
"when": "view == dockerRegistries && viewItem =~ /commontag/i && !(viewItem =~ /commontag;.*dockerhub/i)",
"group": "regs_tag_1_general@3"
},
{
Expand All @@ -507,42 +507,42 @@
},
{
"command": "vscode-docker.registries.azure.untagImage",
"when": "view == dockerRegistries && viewItem =~ /azureContainerTag/i",
"when": "view == dockerRegistries && viewItem =~ /azure;.*commontag/i",
"group": "regs_tag_2_destructive@1"
},
{
"command": "vscode-docker.registries.deleteImage",
"when": "view == dockerRegistries && viewItem =~ /commontag/i && !(viewItem =~ /(githubRegistryTag|dockerHubTag)/i)",
"when": "view == dockerRegistries && viewItem =~ /commontag/i && !(viewItem =~ /commontag;.*(dockerhub|github)/i)",
"group": "regs_tag_2_destructive@2"
},
{
"command": "vscode-docker.registries.disconnectRegistry",
"when": "view == dockerRegistries && viewItem =~ /commonregistryroot/i && !(viewItem =~ /genericRegistryV2Root/i)",
"when": "view == dockerRegistries && viewItem =~ /commonregistryroot/i && !(viewItem =~ /commonregistryroot;.*generic/i)",
"group": "regs_yyy_destructive@1"
},
{
"command": "vscode-docker.registries.genericV2.removeTrackedRegistry",
"when": "view == dockerRegistries && viewItem =~ /genericRegistryV2Registry/i",
"when": "view == dockerRegistries && viewItem =~ /commonregistry;.*generic/i",
"group": "regs_yyy_destructive@1"
},
{
"command": "vscode-docker.registries.genericV2.addTrackedRegistry",
"when": "view == dockerRegistries && viewItem =~ /genericRegistryV2Root/i",
"when": "view == dockerRegistries && viewItem =~ /commonregistryroot;.*generic/i",
"group": "regs_yyy_destructive@1"
},
{
"command": "vscode-docker.registries.azure.openInPortal",
"when": "view == dockerRegistries && viewItem =~ /(azuresubscription|azureContainerRegistry|azureContainerRepository)/i",
"when": "view == dockerRegistries && viewItem =~ /azuresubscription|azure;.*(commonregistry|commonrepository)/i",
"group": "regs_zzz_common@1"
},
{
"command": "vscode-docker.registries.dockerHub.openInBrowser",
"when": "view == dockerRegistries && viewItem =~ /(dockerHubRegistry|dockerHubRepository|dockerHubTag)/i",
"when": "view == dockerRegistries && viewItem =~ /(commonregistry|commonrepository|commontag);.*dockerhub/i",
"group": "regs_zzz_common@1"
},
{
"command": "vscode-docker.registries.azure.viewProperties",
"when": "view == dockerRegistries && viewItem =~ /azureContainerRegistry/i",
"when": "view == dockerRegistries && viewItem =~ /azure;.*commonregistry/i",
"group": "regs_zzz_common@2"
},
{
Expand All @@ -557,12 +557,7 @@
},
{
"command": "vscode-docker.registries.refresh",
"when": "view == dockerRegistries && viewItem =~ /.*;.*;(Repository|Registry|RegistryProvider);/",
"group": "regs_zzz_common@9"
},
{
"command": "vscode-docker.registries.refresh",
"when": "view == dockerRegistries && viewItem =~ /azure(Subscription|Tasks|Task|RunsWithoutTask)$/",
"when": "view == dockerRegistries && viewItem =~ /commonregistry|commonregistryroot|commonrepository/",
"group": "regs_zzz_common@9"
},
{
Expand Down Expand Up @@ -3001,7 +2996,7 @@
"@microsoft/vscode-azext-azureappservice": "~2.0",
"@microsoft/vscode-azext-azureauth": "^1.1.2",
"@microsoft/vscode-azext-azureutils": "^2.0.0",
"@microsoft/vscode-azext-utils": "^2.0.0",
"@microsoft/vscode-azext-utils": "file:../vscode-azuretools/utils/microsoft-vscode-azext-utils-2.1.1.tgz",
"@microsoft/vscode-container-client": "^0.1.0",
"@microsoft/vscode-docker-registries": "file:../vscode-docker-extensibility/packages/vscode-docker-registries/microsoft-vscode-docker-registries-0.1.0.tgz",
"dayjs": "^1.11.7",
Expand Down
16 changes: 12 additions & 4 deletions src/commands/images/pushImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
* Licensed under the MIT License. See LICENSE.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { IActionContext, NoResourceFoundError, contextValueExperience } from '@microsoft/vscode-azext-utils';
import { IActionContext, NoResourceFoundError } from '@microsoft/vscode-azext-utils';
import { parseDockerLikeImageName } from '@microsoft/vscode-container-client';
import { CommonRegistry } from '@microsoft/vscode-docker-registries';
import * as vscode from 'vscode';
import { ext } from '../../extensionVariables';
import { TaskCommandRunnerFactory } from '../../runtimes/runners/TaskCommandRunnerFactory';
import { ImageTreeItem } from '../../tree/images/ImageTreeItem';
import { UnifiedRegistryItem } from '../../tree/registries/UnifiedRegistryTreeDataProvider';
import { registryExperience } from '../../utils/registryExperience';
import { addImageTaggingTelemetry, tagImage } from './tagImage';

export async function pushImage(context: IActionContext, node: ImageTreeItem | undefined): Promise<void> {
Expand All @@ -31,7 +32,7 @@ export async function pushImage(context: IActionContext, node: ImageTreeItem | u
// If the prompt setting is true, we'll ask; if not we'll assume Docker Hub.
if (prompt) {
try {
connectedRegistry = await contextValueExperience(context, ext.registriesTree, { include: ['commonregistry'] });
connectedRegistry = await registryExperience<CommonRegistry>(context, { contextValueFilter: { include: [/commonregistry/i] } });
} catch (error) {
if (error instanceof NoResourceFoundError) {
// Do nothing, move on without a selected registry
Expand All @@ -42,7 +43,14 @@ export async function pushImage(context: IActionContext, node: ImageTreeItem | u
}
} else {
// Try to find a connected Docker Hub registry (primarily for login credentials)
connectedRegistry = await contextValueExperience(context, ext.dockerHubRegistryDataProvider, { include: ['dockerHubRegistry'] });
connectedRegistry = await registryExperience<CommonRegistry>(
context,
{
registryFilter: { include: [ext.dockerHubRegistryDataProvider.label] },
contextValueFilter: { include: /commonregistry/i },
skipIfOne: true
}
);
}
} else {
// The registry to push to is determinate. If there's a connected registry in the tree view, we'll try to find it, to perform login ahead of time.
Expand Down Expand Up @@ -84,7 +92,7 @@ async function tryGetConnectedRegistryForPath(context: IActionContext, baseImage
let matchedRegistry = allRegistries.find((registry) => registry.wrappedItem.baseUrl.authority === baseImageNameInfo.registry);

if (!matchedRegistry) {
matchedRegistry = await contextValueExperience(context, ext.registriesTree, { include: ['commonregistry'] });
matchedRegistry = await registryExperience<CommonRegistry>(context, { contextValueFilter: { include: [/commonregistry/i] } });
}

return matchedRegistry;
Expand Down
14 changes: 10 additions & 4 deletions src/commands/registries/azure/createAzureRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,30 @@
* Licensed under the MIT License. See LICENSE.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { AzureWizard, IActionContext, contextValueExperience, createSubscriptionContext, nonNullProp } from '@microsoft/vscode-azext-utils';
import { AzureWizard, IActionContext, createSubscriptionContext, nonNullProp } from '@microsoft/vscode-azext-utils';
import { l10n, window } from 'vscode';
import { ext } from '../../../extensionVariables';
import { AzureSubscriptionRegistryItem } from '../../../tree/registries/Azure/AzureRegistryDataProvider';
import { AzureRegistryCreateStep } from '../../../tree/registries/Azure/createWizard/AzureRegistryCreateStep';
import { AzureRegistryNameStep } from '../../../tree/registries/Azure/createWizard/AzureRegistryNameStep';
import { AzureRegistrySkuStep } from '../../../tree/registries/Azure/createWizard/AzureRegistrySkuStep';
import { IAzureRegistryWizardContext } from '../../../tree/registries/Azure/createWizard/IAzureRegistryWizardContext';
import { UnifiedRegistryItem, isUnifiedRegistryItem } from '../../../tree/registries/UnifiedRegistryTreeDataProvider';
import { UnifiedRegistryItem } from '../../../tree/registries/UnifiedRegistryTreeDataProvider';
import { getAzExtAzureUtils } from '../../../utils/lazyPackages';
import { registryExperience } from '../../../utils/registryExperience';

export async function createAzureRegistry(context: IActionContext, node?: UnifiedRegistryItem<AzureSubscriptionRegistryItem>): Promise<void> {

if (!node) {
node = await contextValueExperience(context, ext.azureRegistryDataProvider, { include: 'azuresubscription' });
node = await registryExperience<AzureSubscriptionRegistryItem>(context,
{
contextValueFilter: { include: /azuresubscription/i },
registryFilter: { include: [ext.azureRegistryDataProvider.label] }
}
);
}

const registryItem = isUnifiedRegistryItem(node) ? node.wrappedItem : node;
const registryItem = node.wrappedItem;

const subscriptionContext = createSubscriptionContext(registryItem.subscription);
const wizardContext: IAzureRegistryWizardContext = {
Expand Down
8 changes: 6 additions & 2 deletions src/commands/registries/azure/deleteAzureRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@
* Licensed under the MIT License. See LICENSE.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { DialogResponses, IActionContext, contextValueExperience } from '@microsoft/vscode-azext-utils';
import { DialogResponses, IActionContext } from '@microsoft/vscode-azext-utils';
import { ProgressLocation, l10n, window } from 'vscode';
import { ext } from '../../../extensionVariables';
import { AzureRegistry, AzureRegistryDataProvider } from '../../../tree/registries/Azure/AzureRegistryDataProvider';
import { UnifiedRegistryItem } from '../../../tree/registries/UnifiedRegistryTreeDataProvider';
import { registryExperience } from '../../../utils/registryExperience';

export async function deleteAzureRegistry(context: IActionContext, node?: UnifiedRegistryItem<AzureRegistry>): Promise<void> {
if (!node) {
// we can't pass in the azure tree provider because it's not a UnifiedRegistryItem and we need the provider to delete
node = await contextValueExperience(context, ext.registriesTree, { include: 'azureContainerRegistry' });
node = await registryExperience<AzureRegistry>(context, {
contextValueFilter: { include: /commonregistry/i },
registryFilter: { include: [ext.azureRegistryDataProvider.label] }
});
}

const registryName = node.wrappedItem.label;
Expand Down
8 changes: 6 additions & 2 deletions src/commands/registries/azure/deleteAzureRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@
* Licensed under the MIT License. See LICENSE.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { DialogResponses, IActionContext, contextValueExperience } from '@microsoft/vscode-azext-utils';
import { DialogResponses, IActionContext } from '@microsoft/vscode-azext-utils';
import { ProgressLocation, l10n, window } from 'vscode';
import { ext } from '../../../extensionVariables';
import { AzureRegistryDataProvider, AzureRepository } from '../../../tree/registries/Azure/AzureRegistryDataProvider';
import { UnifiedRegistryItem } from '../../../tree/registries/UnifiedRegistryTreeDataProvider';
import { registryExperience } from '../../../utils/registryExperience';

export async function deleteAzureRepository(context: IActionContext, node?: UnifiedRegistryItem<AzureRepository>): Promise<void> {
if (!node) {
// we can't pass in the azure tree provider because it's not a UnifiedRegistryItem and we need the provider to delete
node = await contextValueExperience(context, ext.registriesTree, { include: 'azureContainerRepository' });
node = await registryExperience<AzureRepository>(context, {
contextValueFilter: { include: /commonrepository/i },
registryFilter: { include: [ext.azureRegistryDataProvider.label] }
});
}

const confirmDelete = l10n.t('Are you sure you want to delete repository "{0}" and its associated images?', node.wrappedItem.label);
Expand Down
6 changes: 3 additions & 3 deletions src/commands/registries/azure/deployImageToAca.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
* Licensed under the MIT License. See LICENSE.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { contextValueExperience, IActionContext, nonNullProp, UserCancelledError } from '@microsoft/vscode-azext-utils';
import { IActionContext, nonNullProp, UserCancelledError } from '@microsoft/vscode-azext-utils';
import { parseDockerLikeImageName } from '@microsoft/vscode-container-client';
import { CommonRegistry, CommonTag, isDockerHubRegistry, LoginInformation } from '@microsoft/vscode-docker-registries';
import * as semver from 'semver';
import * as vscode from 'vscode';
import { ext } from '../../../extensionVariables';
import { isAzureRegistry } from '../../../tree/registries/Azure/AzureRegistryDataProvider';
import { getFullImageNameFromRegistryTagItem } from '../../../tree/registries/registryTreeUtils';
import { UnifiedRegistryItem } from '../../../tree/registries/UnifiedRegistryTreeDataProvider';
import { installExtension } from '../../../utils/installExtension';
import { registryExperience } from '../../../utils/registryExperience';
import { addImageTaggingTelemetry } from '../../images/tagImage';

const acaExtensionId = 'ms-azuretools.vscode-azurecontainerapps';
Expand All @@ -35,7 +35,7 @@ export async function deployImageToAca(context: IActionContext, node?: UnifiedRe
}

if (!node) {
node = await contextValueExperience(context, ext.registriesTree, { include: 'commontag' });
node = await registryExperience<CommonTag>(context, { contextValueFilter: { include: /commontag/i } });
}

const commandOptions: Partial<DeployImageToAcaOptionsContract> = {
Expand Down
Loading

0 comments on commit fbceb92

Please sign in to comment.