Skip to content

feat(ContentNavigator): added more detailed path information #1597

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from 3 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
41 changes: 41 additions & 0 deletions client/src/components/ContentNavigator/ContentDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class ContentDataProvider
public dropMimeTypes: string[];
public dragMimeTypes: string[];

private parentPathCache = new Map<string, string>();

get treeView(): TreeView<ContentItem> {
return this._treeView;
}
Expand Down Expand Up @@ -213,6 +215,20 @@ class ContentDataProvider
public async getTreeItem(item: ContentItem): Promise<TreeItem> {
const isContainer = getIsContainer(item);
const uri = await this.model.getUri(item, false);
let tooltip = item.name;

const canCopyPath = item.contextValue?.includes("copyPath");

if (canCopyPath) {
try {
const parentPath = await this.getCachedParentPath(item);
if (parentPath) {
tooltip = parentPath + "/" + item.name;
}
} catch {
// If getting parent path fails, tooltip will remain as item.name
}
}

return {
collapsibleState: isContainer
Expand All @@ -230,6 +246,7 @@ class ContentDataProvider
id: item.uid,
label: item.name,
resourceUri: uri,
tooltip: tooltip,
};
}

Expand Down Expand Up @@ -735,6 +752,30 @@ class ContentDataProvider
}
: undefined;
}

private async getCachedParentPath(item: ContentItem): Promise<string> {
const parentUri = item.parentFolderUri;
if (!parentUri) {
return "";
}

if (!this.parentPathCache.has(parentUri)) {
try {
const fullPath = await this.model.getPathOfItem(item);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may also be worth updating RestContentAdapter.getPathOfItem to handle its own caching since it's really the only ContentAdapter that requires it. And doing that w/n RestContentAdapter may make things easier w/r/t Wei's comment about using uri

if (fullPath) {
const parentPath =
fullPath.substring(0, fullPath.lastIndexOf("/")) || "/";
this.parentPathCache.set(parentUri, parentPath);
} else {
this.parentPathCache.set(parentUri, "");
}
} catch {
this.parentPathCache.set(parentUri, "");
}
}

return this.parentPathCache.get(parentUri) || "";
}
}

export default ContentDataProvider;
Expand Down
Loading