Skip to content

Commit

Permalink
Random fixes and changes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexweininger committed Nov 18, 2024
1 parent c93270e commit 9f2a7d6
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/commands/registerCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { signInToTenant } from '@microsoft/vscode-azext-azureauth';
import { AzExtTreeItem, IActionContext, isAzExtTreeItem, openUrl, registerCommand, registerErrorHandler, registerReportIssueCommand } from '@microsoft/vscode-azext-utils';
import { commands } from 'vscode';
import { AuthenticationSessionAccountInformation, commands } from 'vscode';
import { uploadFileToCloudShell } from '../cloudConsole/uploadFileToCloudShell';
import { ext } from '../extensionVariables';
import { BranchDataItemWrapper } from '../tree/BranchDataItemWrapper';
Expand Down Expand Up @@ -70,8 +70,8 @@ export function registerCommands(): void {
ext.actions.refreshTenantTree(node);
});

registerCommand('azureTenant.signInToTenant', async (_context, node: TenantTreeItem) => {
await (await ext.subscriptionProviderFactory()).signIn(node.tenantId);
registerCommand('azureTenant.signInToTenant', async (_context, node: TenantTreeItem, account?: AuthenticationSessionAccountInformation) => {
await (await ext.subscriptionProviderFactory()).signIn(node.tenantId, account);
ext.actions.refreshTenantTree(node);
});

Expand Down
15 changes: 15 additions & 0 deletions src/tree/GenericItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ export interface GenericItemOptions {
readonly iconPath?: TreeItemIconPath;
readonly description?: string;
readonly collapsibleState?: vscode.TreeItemCollapsibleState;
readonly checkboxState?: vscode.TreeItemCheckboxState | {
/**
* The {@link TreeItemCheckboxState} of the tree item
*/
readonly state: vscode.TreeItemCheckboxState;
/**
* A tooltip for the checkbox
*/
readonly tooltip?: string;
/**
* Accessibility information used when screen readers interact with this checkbox
*/
readonly accessibilityInformation?: vscode.AccessibilityInformation;
};
}

export class GenericItem implements ResourceGroupsItem {
Expand All @@ -41,6 +55,7 @@ export class GenericItem implements ResourceGroupsItem {
treeItem.description = this.options?.description;
treeItem.contextValue = this.options?.contextValue;
treeItem.iconPath = this.options?.iconPath;
treeItem.checkboxState = this.options?.checkboxState;

return treeItem;
}
Expand Down
5 changes: 3 additions & 2 deletions src/tree/tenants/TenantResourceTreeDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class TenantResourceTreeDataProvider extends ResourceTreeDataProviderBase
const tenantItems: ResourceGroupsItem[] = [];
for await (const tenant of tenants) {
const isSignedIn = await subscriptionProvider.isSignedIn(nonNullProp(tenant, 'tenantId'), account);
tenantItems.push(new TenantTreeItem(nonNullProp(tenant, 'displayName'), nonNullProp(tenant, 'tenantId'), nonNullProp(account, 'id'), {
tenantItems.push(new TenantTreeItem(nonNullProp(tenant, 'displayName'), nonNullProp(tenant, 'tenantId'), account, {
contextValue: isSignedIn ? 'tenantName' : 'tenantNameNotSignedIn',
checkboxState: (!(isSignedIn) || this.checkUnselectedTenants(nonNullProp(tenant, 'tenantId'))) ?
vscode.TreeItemCheckboxState.Unchecked : vscode.TreeItemCheckboxState.Checked, // Make sure tenants which are not signed in are unchecked
Expand All @@ -68,7 +68,8 @@ export class TenantResourceTreeDataProvider extends ResourceTreeDataProviderBase
children: tenantItems,
iconPath: new vscode.ThemeIcon('account'),
contextValue: 'accountName',
collapsibleState: vscode.TreeItemCollapsibleState.Expanded
collapsibleState: vscode.TreeItemCollapsibleState.Expanded,
checkboxState: vscode.TreeItemCheckboxState.Checked,
}));
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/tree/tenants/TenantTreeItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ export interface TenantItemOptions extends GenericItemOptions {
}

export class TenantTreeItem implements ResourceGroupsItem {
constructor(public readonly label: string, public tenantId: string, public account: string, private readonly options?: TenantItemOptions) {
constructor(public readonly label: string, public tenantId: string, public readonly account: vscode.AuthenticationSessionAccountInformation, private readonly options?: TenantItemOptions) {
}

readonly id: string = this.tenantId;
readonly accountId: string = this.account
readonly accountId = this.account.id;

getChildren(): vscode.ProviderResult<ResourceGroupsItem[]> {
return this.options?.children;
Expand Down
23 changes: 14 additions & 9 deletions src/tree/tenants/registerTenantTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,25 @@ export function registerTenantTree(context: vscode.ExtensionContext, options: Re
}

async function updateTenantsSetting(_context: IActionContext, tenants: vscode.TreeCheckboxChangeEvent<TenantTreeItem>) {
const unselectedTenants = ext.context.globalState.get<string[]>('unselectedTenants') || [];
const state = ext.context.globalState.get<string[]>('unselectedTenants');
const unselectedTenants = new Set(state ?? []);

for (const item of tenants.items) {
if (item[1] === vscode.TreeItemCheckboxState.Unchecked) {
unselectedTenants.push(`${item[0].id}/${item[0].accountId}`);
} else if (item[1] === vscode.TreeItemCheckboxState.Checked) {
const treeItem = await item[0].getTreeItem();
for (const [tenantTreeItem, state] of tenants.items) {
if (state === vscode.TreeItemCheckboxState.Unchecked) {
unselectedTenants.add(getKeyForTenant(tenantTreeItem));
} else if (state === vscode.TreeItemCheckboxState.Checked) {
const treeItem = await tenantTreeItem.getTreeItem();
if (treeItem?.contextValue === 'tenantNameNotSignedIn') {
await vscode.commands.executeCommand('azureTenant.signInToTenant', item[0]);
await vscode.commands.executeCommand('azureTenant.signInToTenant', tenantTreeItem,);
ext.actions.refreshTenantTree();
}
unselectedTenants.splice(unselectedTenants.indexOf(item[0].id), 1);
unselectedTenants.delete(getKeyForTenant(tenantTreeItem));
}
}

await ext.context.globalState.update('unselectedTenants', unselectedTenants);
await ext.context.globalState.update('unselectedTenants', Array.from(unselectedTenants));
}

export function getKeyForTenant(tenant: { id: string, accountId: string }): string {
return `${tenant.id}/${tenant.accountId}`;
}

0 comments on commit 9f2a7d6

Please sign in to comment.