Skip to content

Commit

Permalink
Add account and tenant to ids when using tree item state
Browse files Browse the repository at this point in the history
  • Loading branch information
alexweininger committed Jan 6, 2025
1 parent 1468f6f commit 1fd0407
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/commands/createResourceGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 { createAzureIdPrefix } from '../tree/azure/idPrefix';
import { createActivityContext } from '../utils/activityUtils';
import { localize } from '../utils/localize';

Expand Down Expand Up @@ -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(`${createAzureIdPrefix(subscription)}/subscriptions/${subscription.subscriptionId}`);
}
5 changes: 3 additions & 2 deletions src/commands/deleteResourceGroup/v2/deleteResourceGroupV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 { createAzureIdPrefix } from '../../../tree/azure/idPrefix';
import { createActivityContext } from '../../../utils/activityUtils';
import { createResourceClient } from '../../../utils/azureClients';
import { localize } from '../../../utils/localize';
Expand Down Expand Up @@ -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(`${createAzureIdPrefix(rg.subscription)}${rg.id}`, localize('deleting', 'Deleting...'), async () => {
const wizard = new AzureWizard<DeleteResourceGroupContext>({
subscription: createSubscriptionContext(subscription),
resourceGroupToDelete: rg.name,
Expand All @@ -123,7 +124,7 @@ async function deleteResourceGroups(context: IActionContext, subscription: Azure
});

await wizard.execute();
ext.azureTreeState.notifyChildrenChanged(`/subscriptions/${rg.subscription.subscriptionId}`);
ext.azureTreeState.notifyChildrenChanged(`${createAzureIdPrefix(rg.subscription)}/subscriptions/${rg.subscription.subscriptionId}`);
});
}
}
5 changes: 5 additions & 0 deletions src/tree/TreeItemState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -51,6 +53,9 @@ export class TreeItemStateStore implements vscode.Disposable {
});
}

/**
* @param id id needs to include the account and tenant id
*/
async runWithTemporaryDescription<T = void>(id: string, description: string, callback: () => Promise<T>): Promise<T> {
let result: T;
this.update(id, { ...this.getState(id), temporaryDescription: description, spinner: true });
Expand Down

0 comments on commit 1fd0407

Please sign in to comment.