-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathQuickPickAzureSubscriptionStep.ts
More file actions
63 lines (51 loc) · 3.05 KB
/
QuickPickAzureSubscriptionStep.ts
File metadata and controls
63 lines (51 loc) · 3.05 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
import { AzureResourceQuickPickWizardContext, AzureSubscriptionQuickPickOptions, SkipIfOneQuickPickOptions } from '../../../index';
import { GenericQuickPickStepWithCommands } from '../GenericQuickPickStepWithCommands';
import { PickFilter } from '../PickFilter';
import { ResourceGroupsItem, SubscriptionItem } from './tempTypes';
export class QuickPickAzureSubscriptionStep extends GenericQuickPickStepWithCommands<AzureResourceQuickPickWizardContext, SkipIfOneQuickPickOptions> {
protected readonly pickFilter: PickFilter;
public constructor(tdp: vscode.TreeDataProvider<ResourceGroupsItem>, options?: AzureSubscriptionQuickPickOptions) {
super(tdp, {
...options,
skipIfOne: true, // Subscription is always skip-if-one
}, {
placeHolder: vscode.l10n.t('Select subscription'),
noPicksMessage: vscode.l10n.t('No subscriptions found'),
});
this.pickFilter = new AzureSubscriptionPickFilter(options?.selectBySubscriptionId);
}
protected override async promptInternal(wizardContext: AzureResourceQuickPickWizardContext): Promise<SubscriptionItem> {
const pickedSubscription = await super.promptInternal(wizardContext) as SubscriptionItem;
// TODO
wizardContext.subscription = pickedSubscription.subscription;
try {
// it's possible that if subscription is not set on AzExtTreeItems, an error is thrown
// see https://github.com/microsoft/vscode-azuretools/blob/cc1feb3a819dd503eb59ebcc1a70051d4e9a3432/utils/src/tree/AzExtTreeItem.ts#L154
wizardContext.telemetry.properties.subscriptionId = pickedSubscription.subscription.subscriptionId;
} catch (e) {
// we don't want to block execution just because we can't set the telemetry property
// see https://github.com/microsoft/vscode-azureresourcegroups/issues/1081
}
return pickedSubscription;
}
}
class AzureSubscriptionPickFilter implements PickFilter {
private readonly subscriptionId?: string;
constructor(subscriptionId?: string) {
// Always ensure we are storing the subscriptionId, not the full subscription path
this.subscriptionId = subscriptionId?.split('/').pop();
}
isFinalPick(_treeItem: vscode.TreeItem): boolean {
// Subscription is never a direct pick
return false;
}
isAncestorPick(_treeItem: vscode.TreeItem, element: SubscriptionItem): boolean {
// All nodes at this level are always subscription nodes
return this.subscriptionId ? element.subscription.subscriptionId === this.subscriptionId : true;
}
}