diff --git a/src/commands/createResourceGroup.ts b/src/commands/createResourceGroup.ts index a118a4a1..41d6eae9 100644 --- a/src/commands/createResourceGroup.ts +++ b/src/commands/createResourceGroup.ts @@ -9,6 +9,7 @@ import { window } from 'vscode'; import { AzureSubscription } from '../../api/src/index'; import { ext } from '../extensionVariables'; import { SubscriptionItem } from '../tree/azure/SubscriptionItem'; +import { getAccountAndTenantPrefix } from '../tree/azure/idPrefix'; import { createActivityContext } from '../utils/activityUtils'; import { localize } from '../utils/localize'; @@ -37,5 +38,5 @@ export async function createResourceGroup(context: IActionContext, node?: Subscr if (!wizardContext.suppressNotification) { void window.showInformationMessage(localize('createdRg', 'Created resource group "{0}".', newResourceGroupName)); } - ext.azureTreeState.notifyChildrenChanged(`/subscriptions/${subscription.subscriptionId}`); + ext.azureTreeState.notifyChildrenChanged(`${getAccountAndTenantPrefix(subscription)}/subscriptions/${subscription.subscriptionId}`); } diff --git a/src/commands/deleteResourceGroup/v2/deleteResourceGroupV2.ts b/src/commands/deleteResourceGroup/v2/deleteResourceGroupV2.ts index c0f98a5f..5b27150b 100644 --- a/src/commands/deleteResourceGroup/v2/deleteResourceGroupV2.ts +++ b/src/commands/deleteResourceGroup/v2/deleteResourceGroupV2.ts @@ -10,6 +10,7 @@ import { AzureResource, AzureSubscription } from '../../../../api/src/index'; import { createResourceGroup } from '../../../api/DefaultAzureResourceProvider'; import { ext } from '../../../extensionVariables'; import { isResourceGroupGroupingItem, ResourceGroupGroupingItem } from '../../../tree/azure/grouping/ResourceGroupGroupingItem'; +import { getAccountAndTenantPrefix } from '../../../tree/azure/idPrefix'; import { createActivityContext } from '../../../utils/activityUtils'; import { createResourceClient } from '../../../utils/azureClients'; import { localize } from '../../../utils/localize'; @@ -111,7 +112,7 @@ async function deleteResourceGroups(context: IActionContext, subscription: Azure } } - void ext.azureTreeState.runWithTemporaryDescription(rg.id, localize('deleting', 'Deleting...'), async () => { + void ext.azureTreeState.runWithTemporaryDescription(`${getAccountAndTenantPrefix(rg.subscription)}${rg.id}`, localize('deleting', 'Deleting...'), async () => { const wizard = new AzureWizard({ subscription: createSubscriptionContext(subscription), resourceGroupToDelete: rg.name, @@ -123,7 +124,7 @@ async function deleteResourceGroups(context: IActionContext, subscription: Azure }); await wizard.execute(); - ext.azureTreeState.notifyChildrenChanged(`/subscriptions/${rg.subscription.subscriptionId}`); + ext.azureTreeState.notifyChildrenChanged(`${getAccountAndTenantPrefix(rg.subscription)}/subscriptions/${rg.subscription.subscriptionId}`); }); } } diff --git a/src/tree/TreeItemState.ts b/src/tree/TreeItemState.ts index f32bdf48..888ca368 100644 --- a/src/tree/TreeItemState.ts +++ b/src/tree/TreeItemState.ts @@ -25,6 +25,8 @@ export class TreeItemStateStore implements vscode.Disposable { /** * Notify a resource that its children have changed. + * + * @param id id needs to include the account and tenant id */ notifyChildrenChanged(id: string): void { this.onDidUpdateStateEmitter.fire(id); @@ -51,6 +53,9 @@ export class TreeItemStateStore implements vscode.Disposable { }); } + /** + * @param id id needs to include the account and tenant id + */ async runWithTemporaryDescription(id: string, description: string, callback: () => Promise): Promise { let result: T; this.update(id, { ...this.getState(id), temporaryDescription: description, spinner: true }); diff --git a/src/tree/azure/AzureResourceItem.ts b/src/tree/azure/AzureResourceItem.ts index c84e5285..58586fcf 100644 --- a/src/tree/azure/AzureResourceItem.ts +++ b/src/tree/azure/AzureResourceItem.ts @@ -11,7 +11,7 @@ import { createPortalUrl } from '../../utils/v2/createPortalUrl'; import { BranchDataItemCache } from '../BranchDataItemCache'; import { BranchDataItemOptions, BranchDataItemWrapper } from '../BranchDataItemWrapper'; import { ResourceGroupsItem } from '../ResourceGroupsItem'; -import { createAzureIdPrefix } from './idPrefix'; +import { getAccountAndTenantPrefix } from './idPrefix'; export class AzureResourceItem extends BranchDataItemWrapper { constructor( @@ -28,7 +28,7 @@ export class AzureResourceItem extends BranchDataItemWr } override readonly portalUrl: Uri; - readonly id = `${createAzureIdPrefix(this.resource.subscription)}${this.resource.id}`; + readonly id = `${getAccountAndTenantPrefix(this.resource.subscription)}${this.resource.id}`; readonly tagsModel = new ResourceTags(this.resource); override async getParent(): Promise { @@ -59,6 +59,6 @@ export function createResourceItemFactory(itemCache: Br itemCache.createOrGetItem( branchItem, () => new AzureResourceItem(resource, branchItem, branchDataProvider, itemCache, parent, options), - `${createAzureIdPrefix(resource.subscription)}${resource.id}`, + `${getAccountAndTenantPrefix(resource.subscription)}${resource.id}`, ); } diff --git a/src/tree/azure/SubscriptionItem.ts b/src/tree/azure/SubscriptionItem.ts index da8599ab..a71a54cf 100644 --- a/src/tree/azure/SubscriptionItem.ts +++ b/src/tree/azure/SubscriptionItem.ts @@ -13,7 +13,7 @@ import { createPortalUrl } from "../../utils/v2/createPortalUrl"; import { ResourceGroupsItem } from "../ResourceGroupsItem"; import { ResourceGroupsTreeContext } from "../ResourceGroupsTreeContext"; import { AzureResourceGroupingManager } from "./grouping/AzureResourceGroupingManager"; -import { createAzureIdPrefix } from "./idPrefix"; +import { getAccountAndTenantPrefix } from "./idPrefix"; export class SubscriptionItem implements ResourceGroupsItem { constructor( @@ -29,7 +29,7 @@ export class SubscriptionItem implements ResourceGroupsItem { ...subscription }; - this.id = `${createAzureIdPrefix(this.subscription)}/subscriptions/${subscription.subscriptionId}`; + this.id = `${getAccountAndTenantPrefix(this.subscription)}/subscriptions/${subscription.subscriptionId}`; this.description = description ? description : ''; this.portalUrl = createPortalUrl(this.subscription, `/subscriptions/${this.subscription.subscriptionId}`); diff --git a/src/tree/azure/grouping/GroupingItem.ts b/src/tree/azure/grouping/GroupingItem.ts index f498a78b..48016356 100644 --- a/src/tree/azure/grouping/GroupingItem.ts +++ b/src/tree/azure/grouping/GroupingItem.ts @@ -17,7 +17,7 @@ import { ResourceGroupsItem } from '../../ResourceGroupsItem'; import { ResourceGroupsTreeContext } from '../../ResourceGroupsTreeContext'; import { BranchDataProviderFactory } from '../AzureResourceBranchDataProviderManager'; import { ResourceItemFactory } from '../AzureResourceItem'; -import { createAzureIdPrefix } from '../idPrefix'; +import { getAccountAndTenantPrefix } from '../idPrefix'; import { GroupingItemFactoryOptions } from './GroupingItemFactory'; export class GroupingItem implements ResourceGroupsItem { @@ -57,7 +57,7 @@ export class GroupingItem implements ResourceGroupsItem { } : undefined; if (this.context?.subscription) { - this.id = `${createAzureIdPrefix(this.context?.subscription)}/subscriptions/${this.context?.subscriptionContext.subscriptionId}/groupings/${this.label}`; + this.id = `${getAccountAndTenantPrefix(this.context?.subscription)}/subscriptions/${this.context?.subscriptionContext.subscriptionId}/groupings/${this.label}`; } else { // favorites groups don't always have a subscription this.id = `/groupings/${this.label}`; @@ -122,7 +122,7 @@ export class GroupingItem implements ResourceGroupsItem { data: resource.raw }, // prefix child items with the account and tenant id - idPrefix: createAzureIdPrefix(resource.subscription), + idPrefix: getAccountAndTenantPrefix(resource.subscription), }; items.push(this.resourceItemFactory(resource, resourceItem, branchDataProvider, this, options)); diff --git a/src/tree/azure/grouping/ResourceGroupGroupingItem.ts b/src/tree/azure/grouping/ResourceGroupGroupingItem.ts index 4956ea9b..4d8e3e7b 100644 --- a/src/tree/azure/grouping/ResourceGroupGroupingItem.ts +++ b/src/tree/azure/grouping/ResourceGroupGroupingItem.ts @@ -12,7 +12,7 @@ import { ITagsModel, ResourceTags } from "../../../commands/tags/TagFileSystem"; import { canFocusContextValue, showHiddenTypesSettingKey } from "../../../constants"; import { settingUtils } from "../../../utils/settingUtils"; import { createPortalUrl } from "../../../utils/v2/createPortalUrl"; -import { createAzureIdPrefix } from "../idPrefix"; +import { getAccountAndTenantPrefix } from "../idPrefix"; import { GroupingItem, GroupingItemOptions } from "./GroupingItem"; import { GroupingItemFactoryOptions } from "./GroupingItemFactory"; @@ -36,7 +36,7 @@ export class ResourceGroupGroupingItem extends GroupingItem { ...this.resourceGroup.subscription, ...createSubscriptionContext(resourceGroup.subscription), }; - this.id = `${createAzureIdPrefix(this.subscription)}${resourceGroup.id}`; + this.id = `${getAccountAndTenantPrefix(this.subscription)}${resourceGroup.id}`; this.tagsModel = new ResourceTags(resourceGroup); this.contextValues.push('hasPortalUrl', 'azureResourceGroup', canFocusContextValue); } diff --git a/src/tree/azure/idPrefix.ts b/src/tree/azure/idPrefix.ts index 538c5582..614caaa6 100644 --- a/src/tree/azure/idPrefix.ts +++ b/src/tree/azure/idPrefix.ts @@ -1,5 +1,8 @@ import { AzureSubscription } from "api/src/resources/azure"; -export function createAzureIdPrefix(subscription: AzureSubscription): string { +/** + * @returns `/accounts//tenants/` + */ +export function getAccountAndTenantPrefix(subscription: AzureSubscription): string { return `/accounts/${subscription.account?.id}/tenants/${subscription.tenantId}`; }