diff --git a/package-lock.json b/package-lock.json index c678ad2c..2c325e2d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,7 +26,7 @@ }, "devDependencies": { "@microsoft/eslint-config-azuretools": "^0.2.2", - "@microsoft/vscode-azext-dev": "^2.0.0", + "@microsoft/vscode-azext-dev": "^2.0.4", "@types/fs-extra": "^8.1.1", "@types/gulp": "^4.0.8", "@types/mocha": "^8.2.2", @@ -609,9 +609,9 @@ } }, "node_modules/@microsoft/vscode-azext-dev": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@microsoft/vscode-azext-dev/-/vscode-azext-dev-2.0.0.tgz", - "integrity": "sha512-fnj7UqLAHgLgLewPixzU4s20W+cEFHdLQ0CXsgCDdwQ2zw8ToyB9bn9HGr93UfWvQtktCPaPDgUmwXWpdd9ocg==", + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/@microsoft/vscode-azext-dev/-/vscode-azext-dev-2.0.4.tgz", + "integrity": "sha512-+XZenjPrfsEc3OPMOdPBVCgPsTvx6h1BVItf5mUoRC3lfN3Gv8OZF80VIETnC9Gj5nB+9nDpQWDzj9V/+2ZS/g==", "dev": true, "dependencies": { "assert": "^2.0.0", @@ -11876,9 +11876,9 @@ } }, "@microsoft/vscode-azext-dev": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@microsoft/vscode-azext-dev/-/vscode-azext-dev-2.0.0.tgz", - "integrity": "sha512-fnj7UqLAHgLgLewPixzU4s20W+cEFHdLQ0CXsgCDdwQ2zw8ToyB9bn9HGr93UfWvQtktCPaPDgUmwXWpdd9ocg==", + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/@microsoft/vscode-azext-dev/-/vscode-azext-dev-2.0.4.tgz", + "integrity": "sha512-+XZenjPrfsEc3OPMOdPBVCgPsTvx6h1BVItf5mUoRC3lfN3Gv8OZF80VIETnC9Gj5nB+9nDpQWDzj9V/+2ZS/g==", "dev": true, "requires": { "assert": "^2.0.0", diff --git a/package.json b/package.json index c171b1d5..d72dbfc0 100644 --- a/package.json +++ b/package.json @@ -199,7 +199,7 @@ }, "devDependencies": { "@microsoft/eslint-config-azuretools": "^0.2.2", - "@microsoft/vscode-azext-dev": "^2.0.0", + "@microsoft/vscode-azext-dev": "^2.0.4", "@types/fs-extra": "^8.1.1", "@types/gulp": "^4.0.8", "@types/mocha": "^8.2.2", diff --git a/src/commands/AzureWizardActivityOutputExecuteStep.ts b/src/commands/AzureWizardActivityOutputExecuteStep.ts new file mode 100644 index 00000000..ab9e9dcc --- /dev/null +++ b/src/commands/AzureWizardActivityOutputExecuteStep.ts @@ -0,0 +1,67 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { activityFailContext, activityFailIcon, activityProgressContext, activityProgressIcon, activitySuccessContext, activitySuccessIcon, AzureWizardExecuteStep, createUniversallyUniqueContextValue, GenericParentTreeItem, GenericTreeItem, type ExecuteActivityOutput, type IActionContext } from "@microsoft/vscode-azext-utils"; + +export abstract class AzureWizardActivityOutputExecuteStep extends AzureWizardExecuteStep { + protected abstract getSuccessString(context: T): string; + protected abstract getProgressString(context: T): string; + protected abstract getFailString(context: T): string; + abstract stepName: string; + + public createSuccessOutput(context: T): ExecuteActivityOutput { + return createExecuteActivityOutput(context, { + activityStatus: 'Success', + label: this.getSuccessString(context), + stepName: this.stepName + }); + } + + public createProgressOutput(context: T): ExecuteActivityOutput { + return createExecuteActivityOutput(context, { + activityStatus: 'Progress', + label: this.getProgressString(context), + stepName: this.stepName + }); + } + + public createFailOutput(context: T): ExecuteActivityOutput { + return createExecuteActivityOutput(context, { + activityStatus: 'Fail', + label: this.getFailString(context), + stepName: this.stepName + }); + } + +} + +function createExecuteActivityOutput(context: IActionContext, options: { + stepName: string + activityStatus: 'Success' | 'Fail' | 'Progress', + label: string +}): ExecuteActivityOutput { + const activityContext = options.activityStatus === 'Success' ? activitySuccessContext : options.activityStatus === 'Fail' ? activityFailContext : activityProgressContext; + const contextValue = createUniversallyUniqueContextValue([`nsgCreateStep${options.activityStatus}Item`, activityContext]); + const label = options.label; + const iconPath = options.activityStatus === 'Success' ? activitySuccessIcon : options.activityStatus === 'Fail' ? activityFailIcon : activityProgressIcon; + + const item = options.activityStatus === 'Fail' ? + // there is logic that will automatically tack on error items as children if thrown in that step so return a parent tree item + new GenericParentTreeItem(undefined, { + contextValue, + label, + iconPath + }) : + new GenericTreeItem(undefined, { + contextValue, + label, + iconPath + }); + + return { + item, + message: options.label + } +} diff --git a/src/commands/createVirtualMachine/NetworkInterfaceCreateStep.ts b/src/commands/createVirtualMachine/NetworkInterfaceCreateStep.ts index 15965833..1897b0d5 100644 --- a/src/commands/createVirtualMachine/NetworkInterfaceCreateStep.ts +++ b/src/commands/createVirtualMachine/NetworkInterfaceCreateStep.ts @@ -5,15 +5,17 @@ import { type NetworkInterface, type NetworkManagementClient, type PublicIPAddress, type Subnet } from '@azure/arm-network'; import { LocationListStep, type AzExtLocation } from '@microsoft/vscode-azext-azureutils'; -import { AzureWizardExecuteStep, nonNullProp, nonNullValueAndProp } from "@microsoft/vscode-azext-utils"; +import { nonNullProp, nonNullValueAndProp } from "@microsoft/vscode-azext-utils"; import { type Progress } from "vscode"; import { ext } from '../../extensionVariables'; import { localize } from '../../localize'; import { createNetworkClient } from '../../utils/azureClients'; +import { AzureWizardActivityOutputExecuteStep } from '../AzureWizardActivityOutputExecuteStep'; import { type IVirtualMachineWizardContext } from './IVirtualMachineWizardContext'; -export class NetworkInterfaceCreateStep extends AzureWizardExecuteStep { +export class NetworkInterfaceCreateStep extends AzureWizardActivityOutputExecuteStep { public priority: number = 250; + stepName: string = 'networkInterfaceCreateStep'; public async execute(context: IVirtualMachineWizardContext, progress: Progress<{ message?: string | undefined; increment?: number | undefined }>): Promise { const networkClient: NetworkManagementClient = await createNetworkClient(context); @@ -33,15 +35,15 @@ export class NetworkInterfaceCreateStep extends AzureWizardExecuteStep { +export class NetworkSecurityGroupCreateStep extends AzureWizardActivityOutputExecuteStep { public priority: number = 220; + stepName: string = 'nsgCreateStep'; public async execute(context: IVirtualMachineWizardContext, progress: Progress<{ message?: string | undefined; increment?: number | undefined }>): Promise { const networkClient: NetworkManagementClient = await createNetworkClient(context); @@ -43,10 +45,24 @@ export class NetworkSecurityGroupCreateStep extends AzureWizardExecuteStep { +export class PublicIpCreateStep extends AzureWizardActivityOutputExecuteStep { public priority: number = 210; + stepName: string = 'publicIpCreateStep'; public async execute(context: IVirtualMachineWizardContext, progress: Progress<{ message?: string | undefined; increment?: number | undefined }>): Promise { const networkClient: NetworkManagementClient = await createNetworkClient(context); @@ -34,9 +36,8 @@ export class PublicIpCreateStep extends AzureWizardExecuteStep { +export class SubnetCreateStep extends AzureWizardActivityOutputExecuteStep { public priority: number = 240; + private _subnetName: string = 'default'; + stepName: string = 'subnetCreateStep'; public async execute(context: IVirtualMachineWizardContext, progress: Progress<{ message?: string | undefined; increment?: number | undefined }>): Promise { const networkClient: NetworkManagementClient = await createNetworkClient(context); @@ -20,21 +23,30 @@ export class SubnetCreateStep extends AzureWizardExecuteStep { +export class VirtualMachineCreateStep extends AzureWizardActivityOutputExecuteStep { public priority: number = 260; + stepName: string = 'virtualMachineCreateStep'; public async execute(context: IVirtualMachineWizardContext, progress: Progress<{ message?: string | undefined; increment?: number | undefined }>): Promise { const newLocation = await LocationListStep.getLocation(context, undefined, true); @@ -68,7 +70,6 @@ export class VirtualMachineCreateStep extends AzureWizardExecuteStep { + void window.showInformationMessage(this.getSuccessString(context), viewOutput).then(async (result: MessageItem | undefined) => { await callWithTelemetryAndErrorHandling('postCreateVM', async (c: IActionContext) => { c.telemetry.properties.dialogResult = result?.title; if (result === viewOutput) { @@ -104,4 +103,18 @@ export class VirtualMachineCreateStep extends AzureWizardExecuteStep { +export class VirtualNetworkCreateStep extends AzureWizardActivityOutputExecuteStep { public priority: number = 230; + stepName: string = 'virtualNetworkCreateStep'; public async execute(context: IVirtualMachineWizardContext, progress: Progress<{ message?: string | undefined; increment?: number | undefined }>): Promise { const networkClient: NetworkManagementClient = await createNetworkClient(context); @@ -27,16 +29,31 @@ export class VirtualNetworkCreateStep extends AzureWizardExecuteStep { +export class DeleteVirtualMachineStep extends AzureWizardActivityOutputExecuteStep { public priority: number = 100; + stepName: string = 'deleteVirtualMachineStep'; public async execute(context: IDeleteChildImplContext, progress: Progress<{ message?: string | undefined; increment?: number | undefined; }>): Promise { @@ -59,4 +61,16 @@ export class DeleteVirtualMachineStep extends AzureWizardExecuteStep(wizardContext, { diff --git a/src/utils/activityUtils.ts b/src/utils/activityUtils.ts index 12f68986..d1b417c2 100644 --- a/src/utils/activityUtils.ts +++ b/src/utils/activityUtils.ts @@ -7,9 +7,10 @@ import { type ExecuteActivityContext } from "@microsoft/vscode-azext-utils"; import { ext } from "../extensionVariables"; import { getWorkspaceSetting } from "../vsCodeConfig/settings"; -export async function createActivityContext(): Promise { +export async function createActivityContext(withChildren?: boolean): Promise { return { registerActivity: async (activity) => ext.rgApi.registerActivity(activity), suppressNotification: await getWorkspaceSetting('suppressActivityNotifications', undefined, 'azureResourceGroups'), + activityChildren: withChildren ? [] : undefined }; }