mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-21 09:51:11 +00:00
Copy To functionality for notebooks (#141)
* Add Copy To functionality for notebooks * Fix formatting * Fix linting errors * Fixes * Fix build failure * Rebase and address feedback * Increase test coverage
This commit is contained in:
@@ -70,6 +70,46 @@ export class NotebookUtil {
|
||||
};
|
||||
}
|
||||
|
||||
public static getFilePath(path: string, fileName: string): string {
|
||||
const contentInfo = GitHubUtils.fromContentUri(path);
|
||||
if (contentInfo) {
|
||||
let path = fileName;
|
||||
if (contentInfo.path) {
|
||||
path = `${contentInfo.path}/${path}`;
|
||||
}
|
||||
return GitHubUtils.toContentUri(contentInfo.owner, contentInfo.repo, contentInfo.branch, path);
|
||||
}
|
||||
|
||||
return `${path}/${fileName}`;
|
||||
}
|
||||
|
||||
public static getParentPath(filepath: string): undefined | string {
|
||||
const basename = NotebookUtil.getName(filepath);
|
||||
if (basename) {
|
||||
const contentInfo = GitHubUtils.fromContentUri(filepath);
|
||||
if (contentInfo) {
|
||||
const parentPath = contentInfo.path.split(basename).shift();
|
||||
if (parentPath === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return GitHubUtils.toContentUri(
|
||||
contentInfo.owner,
|
||||
contentInfo.repo,
|
||||
contentInfo.branch,
|
||||
parentPath.replace(/\/$/, "") // no trailling slash
|
||||
);
|
||||
}
|
||||
|
||||
const parentPath = filepath.split(basename).shift();
|
||||
if (parentPath) {
|
||||
return parentPath.replace(/\/$/, ""); // no trailling slash
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
public static getName(path: string): undefined | string {
|
||||
let relativePath: string = path;
|
||||
const contentInfo = GitHubUtils.fromContentUri(path);
|
||||
|
||||
Reference in New Issue
Block a user