fixed lint issue of NoteBookUtils

This commit is contained in:
sunilyadav840 2021-03-08 18:35:19 +05:30
parent 69975cd0e8
commit 7bc4894382
12 changed files with 158 additions and 161 deletions

View File

@ -122,7 +122,6 @@ src/Explorer/Notebook/NotebookComponent/types.ts
src/Explorer/Notebook/NotebookContainerClient.ts
src/Explorer/Notebook/NotebookContentClient.ts
src/Explorer/Notebook/NotebookContentItem.ts
src/Explorer/Notebook/NotebookUtil.ts
src/Explorer/OpenActions.test.ts
src/Explorer/OpenActions.ts
src/Explorer/OpenActionsStubs.ts

View File

@ -49,7 +49,7 @@ import { LoadQueryPane } from "./Panes/LoadQueryPane";
import * as Logger from "../Common/Logger";
import { sendMessage, sendCachedDataMessage } from "../Common/MessageHandler";
import { NotebookContentItem, NotebookContentItemType } from "./Notebook/NotebookContentItem";
import { NotebookUtil } from "./Notebook/NotebookUtil";
import * as NotebookUtil from "./Notebook/NotebookUtil";
import { NotebookWorkspaceManager } from "../NotebookWorkspaceManager/NotebookWorkspaceManager";
import * as NotificationConsoleUtils from "../Utils/NotificationConsoleUtils";
import { QueriesClient } from "../Common/QueriesClient";

View File

@ -2,7 +2,7 @@ import * as React from "react";
import { NotebookComponent } from "./NotebookComponent";
import { NotebookClientV2 } from "../NotebookClientV2";
import { NotebookUtil } from "../NotebookUtil";
import * as NotebookUtil from "../NotebookUtil";
// Vendor modules
import {

View File

@ -8,7 +8,7 @@ import * as sinon from "sinon";
import { CdbAppState, makeCdbRecord } from "./types";
import { launchWebSocketKernelEpic } from "./epics";
import { NotebookUtil } from "../NotebookUtil";
import * as NotebookUtil from "../NotebookUtil";
import { sessions } from "rx-jupyter";

View File

@ -43,7 +43,7 @@ import { Action as TelemetryAction, ActionModifiers } from "../../../Shared/Tele
import { CdbAppState } from "./types";
import { decryptJWTToken } from "../../../Utils/AuthorizationUtils";
import * as TextFile from "./contents/file/text-file";
import { NotebookUtil } from "../NotebookUtil";
import * as NotebookUtil from "../NotebookUtil";
import { FileSystemUtil } from "../FileSystemUtil";
import * as cdbActions from "../NotebookComponent/actions";
import { Areas } from "../../../Common/Constants";

View File

@ -2,7 +2,7 @@ import * as DataModels from "../../Contracts/DataModels";
import { NotebookContentItem, NotebookContentItemType } from "./NotebookContentItem";
import { StringUtils } from "../../Utils/StringUtils";
import { FileSystemUtil } from "./FileSystemUtil";
import { NotebookUtil } from "./NotebookUtil";
import * as NotebookUtil from "./NotebookUtil";
import { ServerConfig, IContent, IContentProvider, FileType, IEmptyContent } from "@nteract/core";
import { AjaxResponse } from "rxjs/ajax";

View File

@ -1,4 +1,4 @@
import { NotebookUtil } from "./NotebookUtil";
import * as NotebookUtil from "./NotebookUtil";
import * as GitHubUtils from "../../Utils/GitHubUtils";
import {
ImmutableNotebook,

View File

@ -7,34 +7,33 @@ import * as GitHubUtils from "../../Utils/GitHubUtils";
// Must match rx-jupyter' FileType
export type FileType = "directory" | "file" | "notebook";
// Utilities for notebooks
export class NotebookUtil {
/**
/**
* It's a notebook file if the filename ends with .ipynb.
*/
public static isNotebookFile(notebookPath: string): boolean {
const fileName = NotebookUtil.getName(notebookPath);
export function isNotebookFile(notebookPath: string): boolean {
const fileName = getName(notebookPath);
return !!fileName && StringUtils.endsWith(fileName, ".ipynb");
}
}
/**
/**
* Note: this does not connect the item to a parent in a tree.
* @param name
* @param path
*/
public static createNotebookContentItem(name: string, path: string, type: FileType): NotebookContentItem {
export function createNotebookContentItem(name: string, path: string, type: FileType): NotebookContentItem {
return {
name,
path,
type: NotebookUtil.getType(type),
timestamp: NotebookUtil.getCurrentTimestamp(),
type: getType(type),
timestamp: getCurrentTimestamp(),
};
}
}
/**
/**
* Convert rx-jupyter type to our type
* @param type
*/
public static getType(type: FileType): NotebookContentItemType {
export function getType(type: FileType): NotebookContentItemType {
switch (type) {
case "directory":
return NotebookContentItemType.Directory;
@ -45,20 +44,20 @@ export class NotebookUtil {
default:
throw new Error(`Unknown file type: ${type}`);
}
}
}
public static getCurrentTimestamp(): number {
export function getCurrentTimestamp(): number {
return new Date().getTime();
}
}
/**
/**
* Override from kernel-lifecycle.ts to improve kernel selection:
* Only return the kernel name persisted in the notebook
*
* @param filepath
* @param notebook
*/
public static extractNewKernel(filepath: string | null, notebook: ImmutableNotebook) {
export function extractNewKernel(filepath: string | null, notebook: ImmutableNotebook) {
const cwd = (filepath && path.dirname(filepath)) || "/";
const kernelSpecName =
@ -68,9 +67,9 @@ export class NotebookUtil {
cwd,
kernelSpecName,
};
}
}
public static getFilePath(path: string, fileName: string): string {
export function getFilePath(path: string, fileName: string): string {
const contentInfo = GitHubUtils.fromContentUri(path);
if (contentInfo) {
let path = fileName;
@ -81,10 +80,10 @@ export class NotebookUtil {
}
return `${path}/${fileName}`;
}
}
public static getParentPath(filepath: string): undefined | string {
const basename = NotebookUtil.getName(filepath);
export function getParentPath(filepath: string): undefined | string {
const basename = getName(filepath);
if (basename) {
const contentInfo = GitHubUtils.fromContentUri(filepath);
if (contentInfo) {
@ -108,9 +107,9 @@ export class NotebookUtil {
}
return undefined;
}
}
public static getName(path: string): undefined | string {
export function getName(path: string): undefined | string {
let relativePath: string = path;
const contentInfo = GitHubUtils.fromContentUri(path);
if (contentInfo) {
@ -118,9 +117,9 @@ export class NotebookUtil {
}
return relativePath.split("/").pop();
}
}
public static replaceName(path: string, newName: string): string {
export function replaceName(path: string, newName: string): string {
const contentInfo = GitHubUtils.fromContentUri(path);
if (contentInfo) {
const contentName = contentInfo.path.split("/").pop();
@ -139,9 +138,9 @@ export class NotebookUtil {
const basePath = path.split(contentName).shift();
return `${basePath}${newName}`;
}
}
public static findFirstCodeCellWithDisplay(notebookObject: ImmutableNotebook): number {
export function findFirstCodeCellWithDisplay(notebookObject: ImmutableNotebook): number {
let codeCellIndex = 0;
for (let i = 0; i < notebookObject.cellOrder.size; i++) {
const cellId = notebookObject.cellOrder.get(i);
@ -159,5 +158,4 @@ export class NotebookUtil {
}
}
throw new Error("Output does not exist for any of the cells.");
}
}

View File

@ -5,7 +5,7 @@ import { FileSystemUtil } from "../Notebook/FileSystemUtil";
import "./PublishNotebookPaneComponent.less";
import Html2Canvas from "html2canvas";
import { ImmutableNotebook } from "@nteract/commutable/src";
import { NotebookUtil } from "../Notebook/NotebookUtil";
import * as NotebookUtil from "../Notebook/NotebookUtil";
export interface PublishNotebookPaneProps {
notebookName: string;

View File

@ -17,7 +17,7 @@ import NewNotebookIcon from "../../../images/notebook/Notebook-new.svg";
import FileIcon from "../../../images/notebook/file-cosmos.svg";
import PublishIcon from "../../../images/notebook/publish_content.svg";
import { ArrayHashMap } from "../../Common/ArrayHashMap";
import { NotebookUtil } from "../Notebook/NotebookUtil";
import * as NotebookUtil from "../Notebook/NotebookUtil";
import _ from "underscore";
import { IPinnedRepo } from "../../Juno/JunoClient";
import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor";

View File

@ -2,7 +2,7 @@ import { Octokit } from "@octokit/rest";
import { HttpStatusCodes } from "../Common/Constants";
import * as Logger from "../Common/Logger";
import UrlUtility from "../Common/UrlUtility";
import { NotebookUtil } from "../Explorer/Notebook/NotebookUtil";
import * as NotebookUtil from "../Explorer/Notebook/NotebookUtil";
import { getErrorMessage } from "../Common/ErrorHandlingUtils";
export interface IGitHubPageInfo {

View File

@ -5,7 +5,7 @@ import { AjaxResponse } from "rxjs/ajax";
import * as Base64Utils from "../Utils/Base64Utils";
import { HttpStatusCodes } from "../Common/Constants";
import * as Logger from "../Common/Logger";
import { NotebookUtil } from "../Explorer/Notebook/NotebookUtil";
import * as NotebookUtil from "../Explorer/Notebook/NotebookUtil";
import { GitHubClient, IGitHubFile, IGitHubResponse } from "./GitHubClient";
import * as GitHubUtils from "../Utils/GitHubUtils";
import UrlUtility from "../Common/UrlUtility";