mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-20 01:11:25 +00:00
Update to ADO 5ed9b2130da7f822153531489d802c28986f5d30
This commit is contained in:
@@ -60,7 +60,7 @@ export class NotebookContentProvider implements IContentProvider {
|
||||
}
|
||||
|
||||
private getContentProvider(path: string): IContentProvider {
|
||||
if (GitHubUtils.fromGitHubUri(path)) {
|
||||
if (GitHubUtils.fromContentUri(path)) {
|
||||
return this.gitHubContentProvider;
|
||||
}
|
||||
|
||||
|
||||
@@ -141,8 +141,7 @@ export class NotebookContentClient implements ViewModels.INotebookContentClient
|
||||
targetName += extension;
|
||||
}
|
||||
}
|
||||
const parsedPath = NotebookContentClient.parsePath(sourcePath);
|
||||
const targetPath = `${parsedPath.dirpath}${targetName}`;
|
||||
const targetPath = NotebookUtil.replaceName(sourcePath, targetName);
|
||||
return this.contentProvider
|
||||
.update<"file" | "notebook" | "directory">(this.getServerConfig(), sourcePath, { path: targetPath })
|
||||
.toPromise()
|
||||
@@ -214,21 +213,6 @@ export class NotebookContentClient implements ViewModels.INotebookContentClient
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param path
|
||||
* @returns basename and dirpath. Note: dirpath has trailing / already
|
||||
*/
|
||||
private static parsePath(path: string): { dirpath: string; basename: string } {
|
||||
const basename = path.split("/").pop();
|
||||
const dirpath = path.split(basename).shift();
|
||||
|
||||
return {
|
||||
dirpath,
|
||||
basename
|
||||
};
|
||||
}
|
||||
|
||||
private deleteNotebookFile(path: string): Promise<string> {
|
||||
return this.contentProvider
|
||||
.remove(this.getServerConfig(), path)
|
||||
|
||||
49
src/Explorer/Notebook/NotebookUtil.test.ts
Normal file
49
src/Explorer/Notebook/NotebookUtil.test.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { NotebookUtil } from "./NotebookUtil";
|
||||
import { GitHubUtils } from "../../Utils/GitHubUtils";
|
||||
|
||||
const fileName = "file";
|
||||
const notebookName = "file.ipynb";
|
||||
const filePath = `folder/${fileName}`;
|
||||
const notebookPath = `folder/${notebookName}`;
|
||||
const gitHubFileUri = GitHubUtils.toContentUri("owner", "repo", "branch", filePath);
|
||||
const gitHubNotebookUri = GitHubUtils.toContentUri("owner", "repo", "branch", notebookPath);
|
||||
|
||||
describe("NotebookUtil", () => {
|
||||
describe("isNotebookFile", () => {
|
||||
it("works for jupyter file paths", () => {
|
||||
expect(NotebookUtil.isNotebookFile(filePath)).toBeFalsy();
|
||||
expect(NotebookUtil.isNotebookFile(notebookPath)).toBeTruthy();
|
||||
});
|
||||
|
||||
it("works for github file uris", () => {
|
||||
expect(NotebookUtil.isNotebookFile(gitHubFileUri)).toBeFalsy();
|
||||
expect(NotebookUtil.isNotebookFile(gitHubNotebookUri)).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe("getName", () => {
|
||||
it("works for jupyter file paths", () => {
|
||||
expect(NotebookUtil.getName(filePath)).toEqual(fileName);
|
||||
expect(NotebookUtil.getName(notebookPath)).toEqual(notebookName);
|
||||
});
|
||||
|
||||
it("works for github file uris", () => {
|
||||
expect(NotebookUtil.getName(gitHubFileUri)).toEqual(fileName);
|
||||
expect(NotebookUtil.getName(gitHubNotebookUri)).toEqual(notebookName);
|
||||
});
|
||||
});
|
||||
|
||||
describe("replaceName", () => {
|
||||
it("works for jupyter file paths", () => {
|
||||
expect(NotebookUtil.replaceName(filePath, "newName")).toEqual(filePath.replace(fileName, "newName"));
|
||||
expect(NotebookUtil.replaceName(notebookPath, "newName")).toEqual(notebookPath.replace(notebookName, "newName"));
|
||||
});
|
||||
|
||||
it("works for github file uris", () => {
|
||||
expect(NotebookUtil.replaceName(gitHubFileUri, "newName")).toEqual(gitHubFileUri.replace(fileName, "newName"));
|
||||
expect(NotebookUtil.replaceName(gitHubNotebookUri, "newName")).toEqual(
|
||||
gitHubNotebookUri.replace(notebookName, "newName")
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -2,6 +2,7 @@ import path from "path";
|
||||
import { ImmutableNotebook } from "@nteract/commutable";
|
||||
import { NotebookContentItem, NotebookContentItemType } from "./NotebookContentItem";
|
||||
import { StringUtils } from "../../Utils/StringUtils";
|
||||
import { GitHubUtils } from "../../Utils/GitHubUtils";
|
||||
|
||||
// Must match rx-jupyter' FileType
|
||||
export type FileType = "directory" | "file" | "notebook";
|
||||
@@ -11,7 +12,8 @@ export class NotebookUtil {
|
||||
* It's a notebook file if the filename ends with .ipynb.
|
||||
*/
|
||||
public static isNotebookFile(notebookPath: string): boolean {
|
||||
return StringUtils.endsWith(notebookPath, ".ipynb");
|
||||
const fileName = NotebookUtil.getName(notebookPath);
|
||||
return !!fileName && StringUtils.endsWith(fileName, ".ipynb");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,8 +70,34 @@ export class NotebookUtil {
|
||||
};
|
||||
}
|
||||
|
||||
public static getContentName(uri: string): string | undefined {
|
||||
const parts = uri.split("/");
|
||||
return parts.pop() || parts.pop(); // handle potential trailing slash
|
||||
public static getName(path: string): undefined | string {
|
||||
let relativePath: string = path;
|
||||
const contentInfo = GitHubUtils.fromContentUri(path);
|
||||
if (contentInfo) {
|
||||
relativePath = contentInfo.path;
|
||||
}
|
||||
|
||||
return relativePath.split("/").pop();
|
||||
}
|
||||
|
||||
public static replaceName(path: string, newName: string): string {
|
||||
const contentInfo = GitHubUtils.fromContentUri(path);
|
||||
if (contentInfo) {
|
||||
const contentName = contentInfo.path.split("/").pop();
|
||||
if (!contentName) {
|
||||
throw new Error(`Failed to extract name from github path ${contentInfo.path}`);
|
||||
}
|
||||
|
||||
const basePath = contentInfo.path.split(contentName).shift();
|
||||
return GitHubUtils.toContentUri(contentInfo.owner, contentInfo.repo, contentInfo.branch, `${basePath}${newName}`);
|
||||
}
|
||||
|
||||
const contentName = path.split("/").pop();
|
||||
if (!contentName) {
|
||||
throw new Error(`Failed to extract name from path ${path}`);
|
||||
}
|
||||
|
||||
const basePath = path.split(contentName).shift();
|
||||
return `${basePath}${newName}`;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user