From 6848740549f465dc7aba6b6a2521aac05bcf2eea Mon Sep 17 00:00:00 2001 From: alexweininger Date: Thu, 2 Jan 2025 14:36:29 -0500 Subject: [PATCH 1/3] Handle extra slashes --- src/tree/ResourceTreeDataProviderBase.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tree/ResourceTreeDataProviderBase.ts b/src/tree/ResourceTreeDataProviderBase.ts index 1245a133..ae6a45a6 100644 --- a/src/tree/ResourceTreeDataProviderBase.ts +++ b/src/tree/ResourceTreeDataProviderBase.ts @@ -134,5 +134,5 @@ export abstract class ResourceTreeDataProviderBase extends vscode.Disposable imp } function removePrefix(id: string): string { - return id.replace(/\/accounts\/.+\/tenants\/[^/]+\//i, '/') + return id.replace(/\/accounts\/.+\/tenants\/[^/]+\/+/i, '/') } From 632030707e0a648461fb557fe186741c3b79d825 Mon Sep 17 00:00:00 2001 From: alexweininger Date: Fri, 3 Jan 2025 11:54:24 -0500 Subject: [PATCH 2/3] Fixup --- src/tree/BranchDataItemWrapper.ts | 17 +++++++++++++---- src/tree/ResourceTreeDataProviderBase.ts | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/tree/BranchDataItemWrapper.ts b/src/tree/BranchDataItemWrapper.ts index 6b9bae97..0a58d7a1 100644 --- a/src/tree/BranchDataItemWrapper.ts +++ b/src/tree/BranchDataItemWrapper.ts @@ -50,7 +50,7 @@ export class BranchDataItemWrapper implements ResourceGroupsItem, Wrapper { } else { this.id = this.branchItem.id ?? this?.options?.defaultId ?? uuidv4(); } - this.id = this.options?.idPrefix ? `${this.options.idPrefix}/${this.id}` : this.id; + this.id = createBranchItemId(this.id, this.options?.idPrefix); } public readonly id: string; @@ -123,10 +123,19 @@ export class BranchDataItemWrapper implements ResourceGroupsItem, Wrapper { export type BranchDataItemFactory = (branchItem: ResourceModelBase, branchDataProvider: BranchDataProvider, options?: BranchDataItemOptions) => BranchDataItemWrapper; export function createBranchDataItemFactory(itemCache: BranchDataItemCache): BranchDataItemFactory { - return (branchItem, branchDataProvider, options) => - itemCache.createOrGetItem( + return (branchItem, branchDataProvider, options) => { + return itemCache.createOrGetItem( branchItem, () => new BranchDataItemWrapper(branchItem, branchDataProvider, itemCache, options), - `${options?.idPrefix ?? ''}${branchItem.id}`, + createBranchItemId(branchItem.id, options?.idPrefix), ) + } +} + +function createBranchItemId(id?: string, prefix?: string): string { + if (prefix?.endsWith('/') && id?.startsWith('/')) { + return `${prefix}${id.substring(1)}`; + } else { + return `${prefix ?? ''}${id}`; + } } diff --git a/src/tree/ResourceTreeDataProviderBase.ts b/src/tree/ResourceTreeDataProviderBase.ts index ae6a45a6..1245a133 100644 --- a/src/tree/ResourceTreeDataProviderBase.ts +++ b/src/tree/ResourceTreeDataProviderBase.ts @@ -134,5 +134,5 @@ export abstract class ResourceTreeDataProviderBase extends vscode.Disposable imp } function removePrefix(id: string): string { - return id.replace(/\/accounts\/.+\/tenants\/[^/]+\/+/i, '/') + return id.replace(/\/accounts\/.+\/tenants\/[^/]+\//i, '/') } From 738b054f2ad3e890b7aebbbf189e4837edea1487 Mon Sep 17 00:00:00 2001 From: alexweininger Date: Fri, 3 Jan 2025 11:55:13 -0500 Subject: [PATCH 3/3] Fixup --- src/tree/BranchDataItemWrapper.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/tree/BranchDataItemWrapper.ts b/src/tree/BranchDataItemWrapper.ts index 0a58d7a1..fb9b5469 100644 --- a/src/tree/BranchDataItemWrapper.ts +++ b/src/tree/BranchDataItemWrapper.ts @@ -7,9 +7,9 @@ import { isAzExtTreeItem } from '@microsoft/vscode-azext-utils'; import { v4 as uuidv4 } from "uuid"; import * as vscode from 'vscode'; import { AzureResourceModel, BranchDataProvider, ResourceBase, ResourceModelBase, ViewPropertiesModel, Wrapper } from '../../api/src/index'; -import { DefaultAzureResourceBranchDataProvider } from './azure/DefaultAzureResourceBranchDataProvider'; import { BranchDataItemCache } from './BranchDataItemCache'; import { ResourceGroupsItem } from './ResourceGroupsItem'; +import { DefaultAzureResourceBranchDataProvider } from './azure/DefaultAzureResourceBranchDataProvider'; export type BranchDataItemOptions = { contextValues?: string[]; @@ -123,13 +123,12 @@ export class BranchDataItemWrapper implements ResourceGroupsItem, Wrapper { export type BranchDataItemFactory = (branchItem: ResourceModelBase, branchDataProvider: BranchDataProvider, options?: BranchDataItemOptions) => BranchDataItemWrapper; export function createBranchDataItemFactory(itemCache: BranchDataItemCache): BranchDataItemFactory { - return (branchItem, branchDataProvider, options) => { - return itemCache.createOrGetItem( + return (branchItem, branchDataProvider, options) => + itemCache.createOrGetItem( branchItem, () => new BranchDataItemWrapper(branchItem, branchDataProvider, itemCache, options), createBranchItemId(branchItem.id, options?.idPrefix), ) - } } function createBranchItemId(id?: string, prefix?: string): string {