Skip to content

Commit

Permalink
Prevent tree item ids from having double slash (#1005)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexweininger authored Jan 3, 2025
1 parent cb4a891 commit acc1830
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/tree/BranchDataItemWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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}`;
}
}

0 comments on commit acc1830

Please sign in to comment.