From e5036277091f3faa6d4f5dce2560bd4ba12abc2a Mon Sep 17 00:00:00 2001 From: Megan Mott Date: Fri, 6 Dec 2024 10:16:59 -0800 Subject: [PATCH 1/5] add telemetry and sign in button --- package.json | 15 +++++ package.nls.json | 1 + src/commands/registerCommands.ts | 1 + .../tenants/TenantResourceTreeDataProvider.ts | 57 ++++++++++--------- src/tree/tenants/registerTenantTree.ts | 2 + 5 files changed, 49 insertions(+), 27 deletions(-) diff --git a/package.json b/package.json index d9cae39e..1203f193 100644 --- a/package.json +++ b/package.json @@ -105,6 +105,12 @@ "title": "%azureResourceGroups.logIn%", "category": "Azure" }, + { + "command": "azureResourceGroups.logInButton", + "title": "%azureResourceGroups.logInButton%", + "category": "Azure", + "icon": "$(sign-in)" + }, { "command": "azureResourceGroups.selectSubscriptions", "title": "%azureResourceGroups.selectSubscriptions%", @@ -392,6 +398,11 @@ "submenu": "azureWorkspaceCreate", "when": "view == azureWorkspace", "group": "navigation@1" + }, + { + "command": "azureResourceGroups.logInButton", + "when": "view == azureTenantsView", + "group": "navigation@1" } ], "view/item/context": [ @@ -511,6 +522,10 @@ { "command": "azureResourceGroups.installExtension", "when": "never" + }, + { + "command": "azureResourceGroups.logInButton", + "when": "never" } ], "azureResourceGroups.groupBy": [ diff --git a/package.nls.json b/package.nls.json index e9f88088..d87b4940 100644 --- a/package.nls.json +++ b/package.nls.json @@ -3,6 +3,7 @@ "azureResourceGroups.cloudShellPowerShell": "Azure Cloud Shell (PowerShell)", "azureResourceGroups.uploadToCloudShell": "Upload to Cloud Shell", "azureResourceGroups.logIn": "Sign In", + "azureResourceGroups.logInButton": "Sign In", "azureResourceGroups.signInToTenant": "Sign in to Tenant (Directory)...", "azureResourceGroups.selectSubscriptions": "Select Subscriptions...", "azureResourceGroups.createResourceGroup": "Create Resource Group...", diff --git a/src/commands/registerCommands.ts b/src/commands/registerCommands.ts index 6436b10a..6e982d69 100644 --- a/src/commands/registerCommands.ts +++ b/src/commands/registerCommands.ts @@ -79,6 +79,7 @@ export function registerCommands(): void { registerCommand('azureResourceGroups.unfocusGroup', unfocusGroup); registerCommand('azureResourceGroups.logIn', (context: IActionContext) => logIn(context)); + registerCommand('azureResourceGroups.logInButton', (context: IActionContext) => logIn(context)); registerCommand('azureResourceGroups.selectSubscriptions', (context: IActionContext, options: SelectSubscriptionOptions) => selectSubscriptions(context, options)); registerCommand('azureResourceGroups.signInToTenant', async () => signInToTenant(await ext.subscriptionProviderFactory())); diff --git a/src/tree/tenants/TenantResourceTreeDataProvider.ts b/src/tree/tenants/TenantResourceTreeDataProvider.ts index 74aae739..4003c052 100644 --- a/src/tree/tenants/TenantResourceTreeDataProvider.ts +++ b/src/tree/tenants/TenantResourceTreeDataProvider.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { AzureSubscriptionProvider, getConfiguredAuthProviderId } from '@microsoft/vscode-azext-azureauth'; -import { nonNullProp, nonNullValueAndProp } from '@microsoft/vscode-azext-utils'; +import { callWithTelemetryAndErrorHandling, IActionContext, nonNullProp, nonNullValueAndProp } from '@microsoft/vscode-azext-utils'; import { ResourceModelBase } from 'api/src'; import * as vscode from 'vscode'; import { TenantResourceProviderManager } from '../../api/ResourceProviderManagers'; @@ -43,36 +43,39 @@ export class TenantResourceTreeDataProvider extends ResourceTreeDataProviderBase } async onGetChildren(element?: ResourceGroupsItem | undefined): Promise { - if (element) { - return await element.getChildren(); - } else { - const subscriptionProvider = await getAzureSubscriptionProvider(this); - const children: ResourceGroupsItem[] = await OnGetChildrenBase(subscriptionProvider); + return await callWithTelemetryAndErrorHandling('tenantResourceTreeDataProvider.onGetChildren', async (context: IActionContext) => { + if (element) { + return await element.getChildren(); + } else { + const subscriptionProvider = await getAzureSubscriptionProvider(this); + const children: ResourceGroupsItem[] = await OnGetChildrenBase(subscriptionProvider); - if (children.length === 0) { - const accounts = await vscode.authentication.getAccounts(getConfiguredAuthProviderId()); - for (const account of accounts) { - const tenants = await subscriptionProvider.getTenants(account); - const tenantItems: ResourceGroupsItem[] = []; - for await (const tenant of tenants) { - const isSignedIn = await subscriptionProvider.isSignedIn(nonNullProp(tenant, 'tenantId'), account); - tenantItems.push(new TenantTreeItem(tenant, account, { - contextValue: isSignedIn ? 'tenantName' : 'tenantNameNotSignedIn', - checkboxState: (!isSignedIn || isTenantFilteredOut(nonNullProp(tenant, 'tenantId'), account.id)) ? - vscode.TreeItemCheckboxState.Unchecked : vscode.TreeItemCheckboxState.Checked, - description: tenant.tenantId + if (children.length === 0) { + const accounts = await vscode.authentication.getAccounts(getConfiguredAuthProviderId()); + context.telemetry.properties.accountCount = accounts.length.toString(); + for (const account of accounts) { + const tenants = await subscriptionProvider.getTenants(account); + const tenantItems: ResourceGroupsItem[] = []; + for await (const tenant of tenants) { + const isSignedIn = await subscriptionProvider.isSignedIn(nonNullProp(tenant, 'tenantId'), account); + tenantItems.push(new TenantTreeItem(tenant, account, { + contextValue: isSignedIn ? 'tenantName' : 'tenantNameNotSignedIn', + checkboxState: (!isSignedIn || isTenantFilteredOut(nonNullProp(tenant, 'tenantId'), account.id)) ? + vscode.TreeItemCheckboxState.Unchecked : vscode.TreeItemCheckboxState.Checked, + description: tenant.tenantId + })); + } + + children.push(new GenericItem(nonNullValueAndProp(account, 'label'), { + children: tenantItems, + iconPath: new vscode.ThemeIcon('account'), + contextValue: 'accountName', + collapsibleState: vscode.TreeItemCollapsibleState.Expanded, })); } - - children.push(new GenericItem(nonNullValueAndProp(account, 'label'), { - children: tenantItems, - iconPath: new vscode.ThemeIcon('account'), - contextValue: 'accountName', - collapsibleState: vscode.TreeItemCollapsibleState.Expanded, - })); } + return children; } - return children; - } + }); } } diff --git a/src/tree/tenants/registerTenantTree.ts b/src/tree/tenants/registerTenantTree.ts index 61b39e3a..65450b62 100644 --- a/src/tree/tenants/registerTenantTree.ts +++ b/src/tree/tenants/registerTenantTree.ts @@ -56,8 +56,10 @@ async function updateTenantsSetting(_context: IActionContext, tenants: vscode.Tr for (const [tenantTreeItem, state] of tenants.items) { if (state === vscode.TreeItemCheckboxState.Unchecked) { + _context.telemetry.properties.uncheckedTenant = 'true'; unselectedTenantsSet.add(getKeyForTenant(tenantTreeItem.tenantId, tenantTreeItem.account.id)); } else if (state === vscode.TreeItemCheckboxState.Checked) { + _context.telemetry.properties.checkedTenant = 'true'; const treeItem = await tenantTreeItem.getTreeItem(); if (treeItem?.contextValue === 'tenantNameNotSignedIn') { await vscode.commands.executeCommand('azureTenantsView.signInToTenant', tenantTreeItem); From ae8212eef2d12b635416ee4b20014796f5ad3880 Mon Sep 17 00:00:00 2001 From: Megan Mott Date: Fri, 6 Dec 2024 10:57:50 -0800 Subject: [PATCH 2/5] small changes --- package.json | 2 +- src/tree/tenants/registerTenantTree.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 1203f193..22b7ee17 100644 --- a/package.json +++ b/package.json @@ -400,7 +400,7 @@ "group": "navigation@1" }, { - "command": "azureResourceGroups.logInButton", + "command": "azureTenantsView.logInButton", "when": "view == azureTenantsView", "group": "navigation@1" } diff --git a/src/tree/tenants/registerTenantTree.ts b/src/tree/tenants/registerTenantTree.ts index 65450b62..25ad4e0d 100644 --- a/src/tree/tenants/registerTenantTree.ts +++ b/src/tree/tenants/registerTenantTree.ts @@ -50,16 +50,16 @@ export function registerTenantTree(context: vscode.ExtensionContext, options: Re return tenantResourceTreeDataProvider; } -async function updateTenantsSetting(_context: IActionContext, tenants: vscode.TreeCheckboxChangeEvent) { +async function updateTenantsSetting(context: IActionContext, tenants: vscode.TreeCheckboxChangeEvent) { const unselectedTenants = getUnselectedTenants(); const unselectedTenantsSet = new Set(unselectedTenants); for (const [tenantTreeItem, state] of tenants.items) { if (state === vscode.TreeItemCheckboxState.Unchecked) { - _context.telemetry.properties.uncheckedTenant = 'true'; + context.telemetry.properties.uncheckedTenant = 'true'; unselectedTenantsSet.add(getKeyForTenant(tenantTreeItem.tenantId, tenantTreeItem.account.id)); } else if (state === vscode.TreeItemCheckboxState.Checked) { - _context.telemetry.properties.checkedTenant = 'true'; + context.telemetry.properties.checkedTenant = 'true'; const treeItem = await tenantTreeItem.getTreeItem(); if (treeItem?.contextValue === 'tenantNameNotSignedIn') { await vscode.commands.executeCommand('azureTenantsView.signInToTenant', tenantTreeItem); From 3f8080ce1356b54e9714cbde753ae7cadb6a808e Mon Sep 17 00:00:00 2001 From: Megan Mott Date: Fri, 6 Dec 2024 11:01:40 -0800 Subject: [PATCH 3/5] change name --- src/tree/tenants/TenantResourceTreeDataProvider.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tree/tenants/TenantResourceTreeDataProvider.ts b/src/tree/tenants/TenantResourceTreeDataProvider.ts index 4003c052..744e3cb3 100644 --- a/src/tree/tenants/TenantResourceTreeDataProvider.ts +++ b/src/tree/tenants/TenantResourceTreeDataProvider.ts @@ -43,7 +43,7 @@ export class TenantResourceTreeDataProvider extends ResourceTreeDataProviderBase } async onGetChildren(element?: ResourceGroupsItem | undefined): Promise { - return await callWithTelemetryAndErrorHandling('tenantResourceTreeDataProvider.onGetChildren', async (context: IActionContext) => { + return await callWithTelemetryAndErrorHandling('azureTenantsView.getChildren', async (context: IActionContext) => { if (element) { return await element.getChildren(); } else { From 38671a8d707d6080c5990efcc548f73a888d3e95 Mon Sep 17 00:00:00 2001 From: Megan Mott Date: Fri, 6 Dec 2024 12:04:11 -0800 Subject: [PATCH 4/5] change to plus and change name --- package.json | 8 ++++---- package.nls.json | 2 +- src/commands/registerCommands.ts | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 6da1360b..99287b6f 100644 --- a/package.json +++ b/package.json @@ -106,10 +106,10 @@ "category": "Azure" }, { - "command": "azureResourceGroups.logInButton", - "title": "%azureResourceGroups.logInButton%", + "command": "azureTenantsView.logInButton", + "title": "%azureTenantsView.logInButton%", "category": "Azure", - "icon": "$(sign-in)" + "icon": "$(add)" }, { "command": "azureResourceGroups.selectSubscriptions", @@ -524,7 +524,7 @@ "when": "never" }, { - "command": "azureResourceGroups.logInButton", + "command": "azureTenantsView.logInButton", "when": "never" } ], diff --git a/package.nls.json b/package.nls.json index d87b4940..a5d7889e 100644 --- a/package.nls.json +++ b/package.nls.json @@ -3,7 +3,7 @@ "azureResourceGroups.cloudShellPowerShell": "Azure Cloud Shell (PowerShell)", "azureResourceGroups.uploadToCloudShell": "Upload to Cloud Shell", "azureResourceGroups.logIn": "Sign In", - "azureResourceGroups.logInButton": "Sign In", + "azureTenantsView.logInButton": "Sign In", "azureResourceGroups.signInToTenant": "Sign in to Tenant (Directory)...", "azureResourceGroups.selectSubscriptions": "Select Subscriptions...", "azureResourceGroups.createResourceGroup": "Create Resource Group...", diff --git a/src/commands/registerCommands.ts b/src/commands/registerCommands.ts index 6e982d69..e6438809 100644 --- a/src/commands/registerCommands.ts +++ b/src/commands/registerCommands.ts @@ -79,7 +79,7 @@ export function registerCommands(): void { registerCommand('azureResourceGroups.unfocusGroup', unfocusGroup); registerCommand('azureResourceGroups.logIn', (context: IActionContext) => logIn(context)); - registerCommand('azureResourceGroups.logInButton', (context: IActionContext) => logIn(context)); + registerCommand('azureTenantsView.logInButton', (context: IActionContext) => logIn(context)); registerCommand('azureResourceGroups.selectSubscriptions', (context: IActionContext, options: SelectSubscriptionOptions) => selectSubscriptions(context, options)); registerCommand('azureResourceGroups.signInToTenant', async () => signInToTenant(await ext.subscriptionProviderFactory())); From b786c17e23f503fa212b489df5239b758f2cf998 Mon Sep 17 00:00:00 2001 From: Megan Mott Date: Fri, 6 Dec 2024 13:45:30 -0800 Subject: [PATCH 5/5] change to addAccount --- package.json | 8 ++++---- package.nls.json | 2 +- src/commands/registerCommands.ts | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 99287b6f..803e9fb2 100644 --- a/package.json +++ b/package.json @@ -106,8 +106,8 @@ "category": "Azure" }, { - "command": "azureTenantsView.logInButton", - "title": "%azureTenantsView.logInButton%", + "command": "azureTenantsView.addAccount", + "title": "%azureTenantsView.addAccount%", "category": "Azure", "icon": "$(add)" }, @@ -400,7 +400,7 @@ "group": "navigation@1" }, { - "command": "azureTenantsView.logInButton", + "command": "azureTenantsView.addAccount", "when": "view == azureTenantsView", "group": "navigation@1" } @@ -524,7 +524,7 @@ "when": "never" }, { - "command": "azureTenantsView.logInButton", + "command": "azureTenantsView.addAccount", "when": "never" } ], diff --git a/package.nls.json b/package.nls.json index a5d7889e..e544f7e2 100644 --- a/package.nls.json +++ b/package.nls.json @@ -3,7 +3,7 @@ "azureResourceGroups.cloudShellPowerShell": "Azure Cloud Shell (PowerShell)", "azureResourceGroups.uploadToCloudShell": "Upload to Cloud Shell", "azureResourceGroups.logIn": "Sign In", - "azureTenantsView.logInButton": "Sign In", + "azureTenantsView.addAccount": "Add account", "azureResourceGroups.signInToTenant": "Sign in to Tenant (Directory)...", "azureResourceGroups.selectSubscriptions": "Select Subscriptions...", "azureResourceGroups.createResourceGroup": "Create Resource Group...", diff --git a/src/commands/registerCommands.ts b/src/commands/registerCommands.ts index e6438809..e3fa93bf 100644 --- a/src/commands/registerCommands.ts +++ b/src/commands/registerCommands.ts @@ -79,7 +79,7 @@ export function registerCommands(): void { registerCommand('azureResourceGroups.unfocusGroup', unfocusGroup); registerCommand('azureResourceGroups.logIn', (context: IActionContext) => logIn(context)); - registerCommand('azureTenantsView.logInButton', (context: IActionContext) => logIn(context)); + registerCommand('azureTenantsView.addAccount', (context: IActionContext) => logIn(context)); registerCommand('azureResourceGroups.selectSubscriptions', (context: IActionContext, options: SelectSubscriptionOptions) => selectSubscriptions(context, options)); registerCommand('azureResourceGroups.signInToTenant', async () => signInToTenant(await ext.subscriptionProviderFactory()));