diff --git a/src/commands/createContainerApp/ContainerAppListStep.ts b/src/commands/createContainerApp/ContainerAppListStep.ts index af0ff68cd..7f8eb7adb 100644 --- a/src/commands/createContainerApp/ContainerAppListStep.ts +++ b/src/commands/createContainerApp/ContainerAppListStep.ts @@ -5,7 +5,7 @@ import { type ContainerApp, type ContainerAppsAPIClient } from "@azure/arm-appcontainers"; import { LocationListStep, parseAzureResourceId, ResourceGroupListStep, uiUtils } from "@microsoft/vscode-azext-azureutils"; -import { AzureWizardPromptStep, nonNullProp, type AzureWizardExecuteStep, type IAzureQuickPickItem, type IWizardOptions } from "@microsoft/vscode-azext-utils"; +import { AzureWizardPromptStep, nonNullProp, nonNullValueAndProp, type AzureWizardExecuteStep, type ConfirmationViewProperty, type IAzureQuickPickItem, type IWizardOptions } from "@microsoft/vscode-azext-utils"; import { containerAppProvider, containerAppResourceType } from "../../constants"; import { ContainerAppItem } from "../../tree/ContainerAppItem"; import { createContainerAppsAPIClient } from "../../utils/azureClients"; @@ -59,6 +59,14 @@ export class ContainerAppListStep extends A return !context.containerApp && !context.newContainerAppName; } + public confirmationViewProperty(context: T): ConfirmationViewProperty { + return { + name: localize('containerApp', 'Container App'), + value: nonNullValueAndProp(context.containerApp, 'name'), + contextPropertyName: 'containerApp', + } + } + private async getPicks(context: T): Promise[]> { const client: ContainerAppsAPIClient = await createContainerAppsAPIClient(context); @@ -72,7 +80,7 @@ export class ContainerAppListStep extends A } if (context.managedEnvironment) { - containerApps = containerApps.filter(ca => ca.managedEnvironmentId === context.managedEnvironment.id); + containerApps = containerApps.filter(ca => ca.managedEnvironmentId === context.managedEnvironment?.id); } return containerApps.map(ca => { diff --git a/src/commands/createManagedEnvironment/ManagedEnvironmentListStep.ts b/src/commands/createManagedEnvironment/ManagedEnvironmentListStep.ts index 5377b32e9..61e5528d0 100644 --- a/src/commands/createManagedEnvironment/ManagedEnvironmentListStep.ts +++ b/src/commands/createManagedEnvironment/ManagedEnvironmentListStep.ts @@ -7,7 +7,7 @@ import { type ContainerAppsAPIClient, type ManagedEnvironment } from "@azure/arm import { type Workspace } from "@azure/arm-operationalinsights"; import { type ResourceGroup } from "@azure/arm-resources"; import { getResourceGroupFromId, LocationListStep, ResourceGroupListStep, uiUtils } from "@microsoft/vscode-azext-azureutils"; -import { AzureWizardPromptStep, nonNullProp, type AzureWizardExecuteStep, type IAzureQuickPickItem, type ISubscriptionActionContext, type IWizardOptions } from "@microsoft/vscode-azext-utils"; +import { AzureWizardPromptStep, nonNullProp, nonNullValueAndProp, type AzureWizardExecuteStep, type ConfirmationViewProperty, type IAzureQuickPickItem, type ISubscriptionActionContext, type IWizardOptions } from "@microsoft/vscode-azext-utils"; import { logAnalyticsProvider, logAnalyticsResourceType, managedEnvironmentProvider, managedEnvironmentResourceType } from "../../constants"; import { createContainerAppsAPIClient } from "../../utils/azureClients"; import { localize } from "../../utils/localize"; @@ -57,6 +57,14 @@ export class ManagedEnvironmentListStep { const client: ContainerAppsAPIClient = await createContainerAppsAPIClient(context); diff --git a/src/commands/deployContainerApp/deployContainerApp.ts b/src/commands/deployContainerApp/deployContainerApp.ts index cb89de1e1..cd2bb8c49 100644 --- a/src/commands/deployContainerApp/deployContainerApp.ts +++ b/src/commands/deployContainerApp/deployContainerApp.ts @@ -5,6 +5,7 @@ import { KnownActiveRevisionsMode } from "@azure/arm-appcontainers"; import { AzureWizard, CopilotUserInput, createSubscriptionContext, nonNullProp, type AzureWizardPromptStep, type IActionContext, type ISubscriptionActionContext, type ISubscriptionContext } from "@microsoft/vscode-azext-utils"; +import { type AzureSubscription } from "@microsoft/vscode-azureresources-api"; import { ImageSource } from "../../constants"; import { type ContainerAppItem } from "../../tree/ContainerAppItem"; import { createActivityContext } from "../../utils/activityUtils"; @@ -14,9 +15,11 @@ import { getVerifyProvidersStep } from "../../utils/getVerifyProvidersStep"; import { localize } from "../../utils/localize"; import { pickContainerApp } from "../../utils/pickItem/pickContainerApp"; import { OpenConfirmationViewStep } from "../../webviews/OpenConfirmationViewStep"; -import { OpenLoadingViewStep } from "../../webviews/OpenLoadingViewStep"; +import { openLoadingViewPanel } from "../../webviews/OpenLoadingViewStep"; import { CommandAttributes } from "../CommandAttributes"; import { ContainerAppOverwriteConfirmStep } from "../ContainerAppOverwriteConfirmStep"; +import { ContainerAppListStep } from "../createContainerApp/ContainerAppListStep"; +import { ManagedEnvironmentListStep } from "../createManagedEnvironment/ManagedEnvironmentListStep"; import { deployWorkspaceProject } from "../deployWorkspaceProject/deployWorkspaceProject"; import { type DeployWorkspaceProjectResults } from "../deployWorkspaceProject/getDeployWorkspaceProjectResults"; import { editContainerCommandName } from "../editContainer/editContainer"; @@ -45,30 +48,59 @@ export async function deployContainerApp(context: IActionContext, node?: Contain return await deployWorkspaceProject(context, item); } - const wizardContext: ContainerAppDeployContext = { - ...subscriptionActionContext, - ...await createActivityContext({ withChildren: true }), - subscription: item.subscription, - containerApp: item.containerApp, - managedEnvironment: await getManagedEnvironmentFromContainerApp(subscriptionActionContext, item.containerApp), - imageSource, - activityAttributes: CommandAttributes.DeployContainerAppContainerRegistry, - }; - - if (isAzdExtensionInstalled()) { - wizardContext.telemetry.properties.isAzdExtensionInstalled = 'true'; + return await deployContainerAppInternal(subscriptionActionContext, item, imageSource); +} + +export async function deployContainerAppInternal(context: ISubscriptionActionContext, node?: ContainerAppItem, imageSource?: ImageSource, subscription?: AzureSubscription): Promise { + if (isCopilotUserInput(context)) { + await openLoadingViewPanel(context); + } + + const promptSteps: AzureWizardPromptStep[] = []; + + if (!node) { + promptSteps.push(new ManagedEnvironmentListStep(), new ContainerAppListStep()); + } + + let wizardContext: ContainerAppDeployContext = {} as ContainerAppDeployContext; + + if (node && imageSource) { + // If this command gets re run we only want the internal portion of the command to run, so we set the callbackid + context.callbackId = 'containerApps.deployContainerAppInternal'; + wizardContext = { + ...context, + ...await createActivityContext({ withChildren: true }), + subscription: node.subscription, + containerApp: node.containerApp, + managedEnvironment: await getManagedEnvironmentFromContainerApp(context, node.containerApp), + imageSource, + activityAttributes: { + ...CommandAttributes.DeployContainerAppContainerRegistry, + subscription: node.subscription, + }, + }; + + if (isAzdExtensionInstalled()) { + wizardContext.telemetry.properties.isAzdExtensionInstalled = 'true'; + } + wizardContext.telemetry.properties.revisionMode = node.containerApp.revisionsMode; + } else if (subscription) { + wizardContext = { + ...context, + ...await createActivityContext({ withChildren: true }), + subscription: subscription, + //at the moment we are only supporting re run with container registry image source + imageSource: ImageSource.ContainerRegistry + }; } - wizardContext.telemetry.properties.revisionMode = item.containerApp.revisionsMode; const confirmationViewTitle: string = localize('summary', 'Summary'); - let confirmationViewDescription: string = localize('viewDescription', 'Please select an input you would like to change. Note: Any input proceeding the changed input will need to change as well'); + let confirmationViewDescription: string = localize('viewDescription', 'Please select an input you would like to change. Note: Any input preceding the changed input will need to change as well'); let confirmationViewTabTitle: string = localize('deployContainerAppTabTitle', 'Summary - Deploy Image to Container App'); let title: string = localize('deployContainerAppTitle', 'Deploy image to container app'); - const promptSteps: AzureWizardPromptStep[] = []; - if (wizardContext.ui instanceof CopilotUserInput) { - promptSteps.push(new OpenLoadingViewStep()); - confirmationViewDescription = localize('viewDescription', 'Please review AI generated inputs and select any you would like to modify. Note: Any input proceeding the modified input will need to change as well'); + if (isCopilotUserInput(wizardContext)) { + confirmationViewDescription = localize('viewDescription', 'Please review AI generated inputs and select any you would like to modify. Note: Any input preceding the modified input will need to change as well'); confirmationViewTabTitle = localize('deployContainerAppTabTitle', 'Summary - Deploy Image to Container App using Copilot'); title = localize('deployContainerAppWithCopilotTitle', 'Deploy image to container app using copilot'); } @@ -105,3 +137,7 @@ async function promptImageSource(context: ISubscriptionActionContext): Promise extends AzureWizardPromptStep { diff --git a/src/webviews/OpenLoadingViewStep.ts b/src/webviews/OpenLoadingViewStep.ts index c706e5965..d05d3daef 100644 --- a/src/webviews/OpenLoadingViewStep.ts +++ b/src/webviews/OpenLoadingViewStep.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.md in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { AzureWizardPromptStep, type IActionContext } from "@microsoft/vscode-azext-utils"; +import { AzureWizardPromptStep, runGenericPromptStep, type IActionContext } from "@microsoft/vscode-azext-utils"; import * as vscode from 'vscode'; import { localize } from "../utils/localize"; import { LoadingViewController } from "./LoadingViewController"; @@ -20,3 +20,11 @@ export class OpenLoadingViewStep extends AzureWizardPr return true; } } + +export async function openLoadingViewPanel(context: IActionContext): Promise { + const promptSteps: AzureWizardPromptStep[] = [new OpenLoadingViewStep()]; + + return await runGenericPromptStep(context, { + promptSteps + }); +}