-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathpickContainerApp.ts
More file actions
65 lines (57 loc) · 2.89 KB
/
pickContainerApp.ts
File metadata and controls
65 lines (57 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { parseAzureResourceId } from "@microsoft/vscode-azext-azureutils";
import { AzureResourceQuickPickWizardContext, AzureWizardPromptStep, ContextValueQuickPickStep, IActionContext, QuickPickWizardContext, nonNullProp, runQuickPickWizard } from "@microsoft/vscode-azext-utils";
import { ext } from "../../extensionVariables";
import { ContainerAppItem, ContainerAppModel } from "../../tree/ContainerAppItem";
import { localize } from "../localize";
import type { PickItemOptions } from "./PickItemOptions";
import { getPickEnvironmentSteps } from "./pickEnvironment";
export function getPickContainerAppStep(containerAppName?: string | RegExp): AzureWizardPromptStep<AzureResourceQuickPickWizardContext> {
let containerAppFilter: RegExp | undefined;
if (containerAppName) {
containerAppFilter = containerAppName instanceof RegExp ? containerAppName : new RegExp(`^${containerAppName}$`);
} else {
containerAppFilter = ContainerAppItem.contextValueRegExp;
}
return new ContextValueQuickPickStep(ext.rgApiV2.resources.azureResourceTreeDataProvider, {
contextValueFilter: { include: containerAppFilter },
skipIfOne: !!containerAppName,
}, {
placeHolder: localize('selectContainerApp', 'Select a container app'),
noPicksMessage: localize('noContainerApps', 'Selected container apps environment has no apps'),
});
}
export function getPickContainerAppSteps(): AzureWizardPromptStep<AzureResourceQuickPickWizardContext>[] {
return [
...getPickEnvironmentSteps(),
getPickContainerAppStep()
];
}
export async function pickContainerApp(context: IActionContext, options?: PickItemOptions): Promise<ContainerAppItem> {
const promptSteps: AzureWizardPromptStep<QuickPickWizardContext>[] = [
...getPickContainerAppSteps()
];
return await runQuickPickWizard(context, {
promptSteps,
title: options?.title,
showLoadingPrompt: options?.showLoadingPrompt
});
}
export async function pickContainerAppWithoutPrompt(
context: IActionContext,
containerApp: ContainerAppModel,
options?: PickItemOptions
): Promise<ContainerAppItem> {
const environmentName: string = parseAzureResourceId(nonNullProp(containerApp, 'environmentId')).resourceName;
return await runQuickPickWizard(context, {
promptSteps: [
...getPickEnvironmentSteps(true /** skipIfOne */, environmentName),
getPickContainerAppStep(containerApp.name)
],
title: options?.title,
showLoadingPrompt: options?.showLoadingPrompt
});
}