Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent tree item ids from having double slash #1005

Merged
merged 3 commits into from
Jan 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}`;
}
}
Loading