Find previously deployed to managed environment and recommend them (#669)

* Find previously deployed to managed environment and recommend them

* Small fixes

* Add parens

* Small fix

* PR feedback
This commit is contained in:
Nathan 2024-04-04 10:55:17 -07:00 коммит произвёл GitHub
Родитель 360a638ed2
Коммит 473564550c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
2 изменённых файлов: 49 добавлений и 1 удалений

Просмотреть файл

@ -9,8 +9,11 @@ import { ResourceGroupListStep, getResourceGroupFromId, uiUtils } from "@microso
import { AzureWizardPromptStep, nonNullProp, nonNullValueAndProp, type IAzureQuickPickItem } from "@microsoft/vscode-azext-utils";
import { createContainerAppsAPIClient } from "../../../../utils/azureClients";
import { localize } from "../../../../utils/localize";
import { type DeploymentConfigurationSettings } from "../../settings/DeployWorkspaceProjectSettingsV2";
import { dwpSettingUtilsV2 } from "../../settings/dwpSettingUtilsV2";
import { type DeployWorkspaceProjectInternalContext } from "../DeployWorkspaceProjectInternalContext";
const recommendedPickDescription: string = localize('recommended', '(Recommended)');
export class DwpManagedEnvironmentListStep extends AzureWizardPromptStep<DeployWorkspaceProjectInternalContext> {
public async prompt(context: DeployWorkspaceProjectInternalContext): Promise<void> {
const placeHolder: string = localize('selectManagedEnvironment', 'Select a container apps environment');
@ -21,8 +24,13 @@ export class DwpManagedEnvironmentListStep extends AzureWizardPromptStep<DeployW
return;
}
await this.setRecommendedPicks(context, picks);
const pick = await context.ui.showQuickPick(picks, { placeHolder, suppressPersistence: true });
context.telemetry.properties.usedRecommendedEnv = isRecommendedPick(pick) ? 'true' : 'false';
context.telemetry.properties.recommendedEnvCount =
String(picks.reduce((count, pick) => count + (isRecommendedPick(pick) ? 1 : 0), 0));
const managedEnvironment: ManagedEnvironment | undefined = (await context.ui.showQuickPick(picks, { placeHolder })).data;
const managedEnvironment: ManagedEnvironment | undefined = pick.data;
if (!managedEnvironment) {
// User is choosing to create a new managed environment
return;
@ -66,4 +74,40 @@ export class DwpManagedEnvironmentListStep extends AzureWizardPromptStep<DeployW
context.resourceGroup = resourceGroups.find(rg => rg.name === getResourceGroupFromId(nonNullProp(managedEnvironment, 'id')));
context.managedEnvironment = managedEnvironment;
}
private async setRecommendedPicks(context: DeployWorkspaceProjectInternalContext, picks: IAzureQuickPickItem<ManagedEnvironment | undefined>[]): Promise<void> {
const deploymentConfigurations: DeploymentConfigurationSettings[] | undefined = await dwpSettingUtilsV2.getWorkspaceDeploymentConfigurations(nonNullProp(context, 'rootFolder'));
if (!deploymentConfigurations?.length) {
return;
}
const client = await createContainerAppsAPIClient(context);
for (const config of deploymentConfigurations) {
try {
if (config.resourceGroup && config.containerApp) {
const containerApp = await client.containerApps.get(config.resourceGroup, config.containerApp);
const recommendedPick = picks.find(p => p.data?.id === containerApp.managedEnvironmentId);
if (recommendedPick) {
recommendedPick.description = recommendedPickDescription;
}
}
}
catch (these_hands) {
// ignore the error and continue
}
}
// sort the picks by recommendation
picks.sort((a, b) => {
if (isRecommendedPick(a)) {
return -1;
} else if (isRecommendedPick(b)) {
return 1;
} else {
return 0;
}
});
}
}
const isRecommendedPick = (pick: IAzureQuickPickItem<ManagedEnvironment | undefined>): boolean => pick.description === recommendedPickDescription;

Просмотреть файл

@ -31,6 +31,10 @@ export interface DeployWorkspaceProjectInternalTelemetryProps extends AzdTelemet
hasNewSettings?: 'true' | 'false'; // ShouldSaveDeploySettingsPromptStep
shouldSaveDeploySettings?: 'true' | 'false'; // ShouldSaveDeploySettingsPromptStep
didSaveSettings?: 'true' | 'false'; // DeployWorkspaceProjectSaveSettingsStep - we swallow errors here, so log the outcome just in case
// Recommended managed environments
recommendedEnvCount?: string; // number casted to string
usedRecommendedEnv?: 'true' | 'false';
}
export interface DeployWorkspaceProjectNotificationTelemetryProps {