diff --git a/src/tree/ResourceTreeDataProviderBase.ts b/src/tree/ResourceTreeDataProviderBase.ts index f7d1c4ae..3b1bc7a1 100644 --- a/src/tree/ResourceTreeDataProviderBase.ts +++ b/src/tree/ResourceTreeDataProviderBase.ts @@ -102,7 +102,6 @@ export abstract class ResourceTreeDataProviderBase extends vscode.Disposable imp async findItemById(id: string): Promise { let element: ResourceGroupsItem | undefined = undefined; - outerLoop: while (true) { const children: ResourceGroupsItem[] | null | undefined = await this.getChildren(element); @@ -124,7 +123,9 @@ export abstract class ResourceTreeDataProviderBase extends vscode.Disposable imp } protected isAncestorOf(element: ResourceGroupsItem, id: string): boolean { - return id.toLowerCase().startsWith(element.id.toLowerCase() + '/'); + // remove accounts//tenant/ from the beginning of the id + const elementId = element.id.replace(/\/accounts\/[^/]+\/tenants\/[^/]+\//i, '/').toLowerCase() + '/'; + return id.toLowerCase().startsWith(elementId); } protected abstract onGetChildren(element?: ResourceGroupsItem | undefined): Promise; diff --git a/src/tree/azure/SubscriptionItem.ts b/src/tree/azure/SubscriptionItem.ts index 89da52e4..180ddeaf 100644 --- a/src/tree/azure/SubscriptionItem.ts +++ b/src/tree/azure/SubscriptionItem.ts @@ -28,7 +28,7 @@ export class SubscriptionItem implements ResourceGroupsItem { ...subscription }; - this.id = `/subscriptions/${subscription.subscriptionId}/${subscription.tenantId}/${nonNullValueAndProp(subscription.account, 'id')}`; + this.id = `/accounts/${nonNullValueAndProp(subscription.account, 'id')}/tenants/${subscription.tenantId}/subscriptions/${subscription.subscriptionId}`; this.description = description ? description : ''; this.portalUrl = createPortalUrl(this.subscription, this.id); diff --git a/test/api/subscription.test.ts b/test/api/subscription.test.ts index f5403117..2f972078 100644 --- a/test/api/subscription.test.ts +++ b/test/api/subscription.test.ts @@ -19,16 +19,19 @@ suite('SubscriptionItem tests', async () => { test('Tree should show a subscription item for each Azure subscription', async () => { const { mockResources, subscriptionItems } = await mockResourcesAndGetSubscriptionItems(); mockResources.subscriptions.forEach((subscription) => { - assert.ok(subscriptionItems?.find((node) => node.id === subscription.id)); + assert.ok( + subscriptionItems?.find((node) => node.subscription.subscriptionId === subscription.subscriptionId), + `Subscription ${subscription.id} not found in the tree. Found: ${subscriptionItems.map((node) => node.subscription.subscriptionId).join(', ')}` + ); }); assert.strictEqual(subscriptionItems.length, mockResources.subscriptions.length, `There should be ${mockResources.subscriptions.length} subscription nodes. Found ${subscriptionItems.length}.`); }); - test('SubscriptionItem.id should be in the "/subscriptions/" format', async () => { + test('SubscriptionItem.id should be in the "/accounts//tenants//subscriptions/" format', async () => { const { subscriptionItems } = await mockResourcesAndGetSubscriptionItems(); subscriptionItems.forEach((subscriptionItem) => { - assert.match(subscriptionItem.id, /^\/subscriptions\/([0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12})/i); + assert.match(subscriptionItem.id, /^\/accounts\/[^/]+\/tenants\/[^/]+\/subscriptions\/([0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12})/i); }); });