From acc1830ebbbe98f3234a8d4f9689b337fbf9569e Mon Sep 17 00:00:00 2001 From: Alex Weininger Date: Fri, 3 Jan 2025 16:56:42 -0500 Subject: [PATCH] Prevent tree item ids from having double slash (#1005) --- src/tree/BranchDataItemWrapper.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/tree/BranchDataItemWrapper.ts b/src/tree/BranchDataItemWrapper.ts index 6b9bae97..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[]; @@ -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; @@ -127,6 +127,14 @@ export function createBranchDataItemFactory(itemCache: BranchDataItemCache): Bra 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}`; + } +}