Skip to content

Commit 4735645

Browse files
authored
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
1 parent 360a638 commit 4735645

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

src/commands/deployWorkspaceProject/internal/startingConfiguration/DwpManagedEnvironmentListStep.ts

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ import { ResourceGroupListStep, getResourceGroupFromId, uiUtils } from "@microso
99
import { AzureWizardPromptStep, nonNullProp, nonNullValueAndProp, type IAzureQuickPickItem } from "@microsoft/vscode-azext-utils";
1010
import { createContainerAppsAPIClient } from "../../../../utils/azureClients";
1111
import { localize } from "../../../../utils/localize";
12+
import { type DeploymentConfigurationSettings } from "../../settings/DeployWorkspaceProjectSettingsV2";
13+
import { dwpSettingUtilsV2 } from "../../settings/dwpSettingUtilsV2";
1214
import { type DeployWorkspaceProjectInternalContext } from "../DeployWorkspaceProjectInternalContext";
1315

16+
const recommendedPickDescription: string = localize('recommended', '(Recommended)');
1417
export class DwpManagedEnvironmentListStep extends AzureWizardPromptStep<DeployWorkspaceProjectInternalContext> {
1518
public async prompt(context: DeployWorkspaceProjectInternalContext): Promise<void> {
1619
const placeHolder: string = localize('selectManagedEnvironment', 'Select a container apps environment');
@@ -21,8 +24,13 @@ export class DwpManagedEnvironmentListStep extends AzureWizardPromptStep<DeployW
2124
return;
2225
}
2326

27+
await this.setRecommendedPicks(context, picks);
28+
const pick = await context.ui.showQuickPick(picks, { placeHolder, suppressPersistence: true });
29+
context.telemetry.properties.usedRecommendedEnv = isRecommendedPick(pick) ? 'true' : 'false';
30+
context.telemetry.properties.recommendedEnvCount =
31+
String(picks.reduce((count, pick) => count + (isRecommendedPick(pick) ? 1 : 0), 0));
2432

25-
const managedEnvironment: ManagedEnvironment | undefined = (await context.ui.showQuickPick(picks, { placeHolder })).data;
33+
const managedEnvironment: ManagedEnvironment | undefined = pick.data;
2634
if (!managedEnvironment) {
2735
// User is choosing to create a new managed environment
2836
return;
@@ -66,4 +74,40 @@ export class DwpManagedEnvironmentListStep extends AzureWizardPromptStep<DeployW
6674
context.resourceGroup = resourceGroups.find(rg => rg.name === getResourceGroupFromId(nonNullProp(managedEnvironment, 'id')));
6775
context.managedEnvironment = managedEnvironment;
6876
}
77+
78+
private async setRecommendedPicks(context: DeployWorkspaceProjectInternalContext, picks: IAzureQuickPickItem<ManagedEnvironment | undefined>[]): Promise<void> {
79+
const deploymentConfigurations: DeploymentConfigurationSettings[] | undefined = await dwpSettingUtilsV2.getWorkspaceDeploymentConfigurations(nonNullProp(context, 'rootFolder'));
80+
if (!deploymentConfigurations?.length) {
81+
return;
82+
}
83+
84+
const client = await createContainerAppsAPIClient(context);
85+
for (const config of deploymentConfigurations) {
86+
try {
87+
if (config.resourceGroup && config.containerApp) {
88+
const containerApp = await client.containerApps.get(config.resourceGroup, config.containerApp);
89+
const recommendedPick = picks.find(p => p.data?.id === containerApp.managedEnvironmentId);
90+
if (recommendedPick) {
91+
recommendedPick.description = recommendedPickDescription;
92+
}
93+
}
94+
}
95+
catch (these_hands) {
96+
// ignore the error and continue
97+
}
98+
}
99+
100+
// sort the picks by recommendation
101+
picks.sort((a, b) => {
102+
if (isRecommendedPick(a)) {
103+
return -1;
104+
} else if (isRecommendedPick(b)) {
105+
return 1;
106+
} else {
107+
return 0;
108+
}
109+
});
110+
}
69111
}
112+
113+
const isRecommendedPick = (pick: IAzureQuickPickItem<ManagedEnvironment | undefined>): boolean => pick.description === recommendedPickDescription;

src/telemetry/deployWorkspaceProjectTelemetryProps.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ export interface DeployWorkspaceProjectInternalTelemetryProps extends AzdTelemet
3131
hasNewSettings?: 'true' | 'false'; // ShouldSaveDeploySettingsPromptStep
3232
shouldSaveDeploySettings?: 'true' | 'false'; // ShouldSaveDeploySettingsPromptStep
3333
didSaveSettings?: 'true' | 'false'; // DeployWorkspaceProjectSaveSettingsStep - we swallow errors here, so log the outcome just in case
34+
35+
// Recommended managed environments
36+
recommendedEnvCount?: string; // number casted to string
37+
usedRecommendedEnv?: 'true' | 'false';
3438
}
3539

3640
export interface DeployWorkspaceProjectNotificationTelemetryProps {

0 commit comments

Comments
 (0)