Skip to content

Commit 21a154e

Browse files
committed
merge main
2 parents 65bbce6 + 66eba91 commit 21a154e

File tree

5 files changed

+50
-28
lines changed

5 files changed

+50
-28
lines changed

package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@
105105
"title": "%azureResourceGroups.logIn%",
106106
"category": "Azure"
107107
},
108+
{
109+
"command": "azureTenantsView.addAccount",
110+
"title": "%azureTenantsView.addAccount%",
111+
"category": "Azure",
112+
"icon": "$(add)"
113+
},
108114
{
109115
"command": "azureResourceGroups.selectSubscriptions",
110116
"title": "%azureResourceGroups.selectSubscriptions%",
@@ -403,6 +409,11 @@
403409
"command": "azureTenantsView.configureSovereignCloud",
404410
"when": "view == azureTenantsView",
405411
"group": "navigation@2"
412+
},
413+
{
414+
"command": "azureTenantsView.addAccount",
415+
"when": "view == azureTenantsView",
416+
"group": "navigation@1"
406417
}
407418
],
408419
"view/item/context": [
@@ -522,6 +533,10 @@
522533
{
523534
"command": "azureResourceGroups.installExtension",
524535
"when": "never"
536+
},
537+
{
538+
"command": "azureTenantsView.addAccount",
539+
"when": "never"
525540
}
526541
],
527542
"azureResourceGroups.groupBy": [

package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"azureResourceGroups.cloudShellPowerShell": "Azure Cloud Shell (PowerShell)",
44
"azureResourceGroups.uploadToCloudShell": "Upload to Cloud Shell",
55
"azureResourceGroups.logIn": "Sign In",
6+
"azureTenantsView.addAccount": "Add account",
67
"azureResourceGroups.signInToTenant": "Sign in to Tenant (Directory)...",
78
"azureResourceGroups.selectSubscriptions": "Select Subscriptions...",
89
"azureResourceGroups.createResourceGroup": "Create Resource Group...",

src/commands/registerCommands.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export function registerCommands(): void {
8080
registerCommand('azureResourceGroups.unfocusGroup', unfocusGroup);
8181

8282
registerCommand('azureResourceGroups.logIn', (context: IActionContext) => logIn(context));
83+
registerCommand('azureTenantsView.addAccount', (context: IActionContext) => logIn(context));
8384
registerCommand('azureResourceGroups.selectSubscriptions', (context: IActionContext, options: SelectSubscriptionOptions) => selectSubscriptions(context, options));
8485
registerCommand('azureResourceGroups.signInToTenant', async () => signInToTenant(await ext.subscriptionProviderFactory()));
8586

src/tree/tenants/TenantResourceTreeDataProvider.ts

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { AzureSubscriptionProvider, getConfiguredAuthProviderId } from '@microsoft/vscode-azext-azureauth';
7-
import { nonNullProp, nonNullValueAndProp } from '@microsoft/vscode-azext-utils';
7+
import { callWithTelemetryAndErrorHandling, IActionContext, nonNullProp, nonNullValueAndProp } from '@microsoft/vscode-azext-utils';
88
import { ResourceModelBase } from 'api/src';
99
import * as vscode from 'vscode';
1010
import { TenantResourceProviderManager } from '../../api/ResourceProviderManagers';
@@ -43,36 +43,39 @@ export class TenantResourceTreeDataProvider extends ResourceTreeDataProviderBase
4343
}
4444

4545
async onGetChildren(element?: ResourceGroupsItem | undefined): Promise<ResourceGroupsItem[] | null | undefined> {
46-
if (element) {
47-
return await element.getChildren();
48-
} else {
49-
const subscriptionProvider = await getAzureSubscriptionProvider(this);
50-
const children: ResourceGroupsItem[] = await OnGetChildrenBase(subscriptionProvider);
46+
return await callWithTelemetryAndErrorHandling('azureTenantsView.getChildren', async (context: IActionContext) => {
47+
if (element) {
48+
return await element.getChildren();
49+
} else {
50+
const subscriptionProvider = await getAzureSubscriptionProvider(this);
51+
const children: ResourceGroupsItem[] = await OnGetChildrenBase(subscriptionProvider);
5152

52-
if (children.length === 0) {
53-
const accounts = await vscode.authentication.getAccounts(getConfiguredAuthProviderId());
54-
for (const account of accounts) {
55-
const tenants = await subscriptionProvider.getTenants(account);
56-
const tenantItems: ResourceGroupsItem[] = [];
57-
for await (const tenant of tenants) {
58-
const isSignedIn = await subscriptionProvider.isSignedIn(nonNullProp(tenant, 'tenantId'), account);
59-
tenantItems.push(new TenantTreeItem(tenant, account, {
60-
contextValue: isSignedIn ? 'tenantName' : 'tenantNameNotSignedIn',
61-
checkboxState: (!isSignedIn || isTenantFilteredOut(nonNullProp(tenant, 'tenantId'), account.id)) ?
62-
vscode.TreeItemCheckboxState.Unchecked : vscode.TreeItemCheckboxState.Checked,
63-
description: tenant.tenantId
53+
if (children.length === 0) {
54+
const accounts = await vscode.authentication.getAccounts(getConfiguredAuthProviderId());
55+
context.telemetry.properties.accountCount = accounts.length.toString();
56+
for (const account of accounts) {
57+
const tenants = await subscriptionProvider.getTenants(account);
58+
const tenantItems: ResourceGroupsItem[] = [];
59+
for await (const tenant of tenants) {
60+
const isSignedIn = await subscriptionProvider.isSignedIn(nonNullProp(tenant, 'tenantId'), account);
61+
tenantItems.push(new TenantTreeItem(tenant, account, {
62+
contextValue: isSignedIn ? 'tenantName' : 'tenantNameNotSignedIn',
63+
checkboxState: (!isSignedIn || isTenantFilteredOut(nonNullProp(tenant, 'tenantId'), account.id)) ?
64+
vscode.TreeItemCheckboxState.Unchecked : vscode.TreeItemCheckboxState.Checked,
65+
description: tenant.tenantId
66+
}));
67+
}
68+
69+
children.push(new GenericItem(nonNullValueAndProp(account, 'label'), {
70+
children: tenantItems,
71+
iconPath: new vscode.ThemeIcon('account'),
72+
contextValue: 'accountName',
73+
collapsibleState: vscode.TreeItemCollapsibleState.Expanded,
6474
}));
6575
}
66-
67-
children.push(new GenericItem(nonNullValueAndProp(account, 'label'), {
68-
children: tenantItems,
69-
iconPath: new vscode.ThemeIcon('account'),
70-
contextValue: 'accountName',
71-
collapsibleState: vscode.TreeItemCollapsibleState.Expanded,
72-
}));
7376
}
77+
return children;
7478
}
75-
return children;
76-
}
79+
});
7780
}
7881
}

src/tree/tenants/registerTenantTree.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,16 @@ export function registerTenantTree(context: vscode.ExtensionContext, options: Re
5050
return tenantResourceTreeDataProvider;
5151
}
5252

53-
async function updateTenantsSetting(_context: IActionContext, tenants: vscode.TreeCheckboxChangeEvent<TenantTreeItem>) {
53+
async function updateTenantsSetting(context: IActionContext, tenants: vscode.TreeCheckboxChangeEvent<TenantTreeItem>) {
5454
const unselectedTenants = getUnselectedTenants();
5555
const unselectedTenantsSet = new Set(unselectedTenants);
5656

5757
for (const [tenantTreeItem, state] of tenants.items) {
5858
if (state === vscode.TreeItemCheckboxState.Unchecked) {
59+
context.telemetry.properties.uncheckedTenant = 'true';
5960
unselectedTenantsSet.add(getKeyForTenant(tenantTreeItem.tenantId, tenantTreeItem.account.id));
6061
} else if (state === vscode.TreeItemCheckboxState.Checked) {
62+
context.telemetry.properties.checkedTenant = 'true';
6163
const treeItem = await tenantTreeItem.getTreeItem();
6264
if (treeItem?.contextValue === 'tenantNameNotSignedIn') {
6365
await vscode.commands.executeCommand('azureTenantsView.signInToTenant', tenantTreeItem);

0 commit comments

Comments
 (0)