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/NotebookContainerClient.ts
src/Explorer/Notebook/NotebookContentClient.ts src/Explorer/Notebook/NotebookContentClient.ts
src/Explorer/Notebook/NotebookContentItem.ts src/Explorer/Notebook/NotebookContentItem.ts
src/Explorer/Notebook/NotebookUtil.ts
src/Explorer/OpenActions.test.ts src/Explorer/OpenActions.test.ts
src/Explorer/OpenActions.ts src/Explorer/OpenActions.ts
src/Explorer/OpenActionsStubs.ts src/Explorer/OpenActionsStubs.ts

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -7,34 +7,33 @@ import * as GitHubUtils from "../../Utils/GitHubUtils";
// Must match rx-jupyter' FileType // Must match rx-jupyter' FileType
export type FileType = "directory" | "file" | "notebook"; export type FileType = "directory" | "file" | "notebook";
// Utilities for notebooks // Utilities for notebooks
export class NotebookUtil { /**
/**
* It's a notebook file if the filename ends with .ipynb. * It's a notebook file if the filename ends with .ipynb.
*/ */
public static isNotebookFile(notebookPath: string): boolean { export function isNotebookFile(notebookPath: string): boolean {
const fileName = NotebookUtil.getName(notebookPath); const fileName = getName(notebookPath);
return !!fileName && StringUtils.endsWith(fileName, ".ipynb"); return !!fileName && StringUtils.endsWith(fileName, ".ipynb");
} }
/** /**
* Note: this does not connect the item to a parent in a tree. * Note: this does not connect the item to a parent in a tree.
* @param name * @param name
* @param path * @param path
*/ */
public static createNotebookContentItem(name: string, path: string, type: FileType): NotebookContentItem { export function createNotebookContentItem(name: string, path: string, type: FileType): NotebookContentItem {
return { return {
name, name,
path, path,
type: NotebookUtil.getType(type), type: getType(type),
timestamp: NotebookUtil.getCurrentTimestamp(), timestamp: getCurrentTimestamp(),
}; };
} }
/** /**
* Convert rx-jupyter type to our type * Convert rx-jupyter type to our type
* @param type * @param type
*/ */
public static getType(type: FileType): NotebookContentItemType { export function getType(type: FileType): NotebookContentItemType {
switch (type) { switch (type) {
case "directory": case "directory":
return NotebookContentItemType.Directory; return NotebookContentItemType.Directory;
@ -45,20 +44,20 @@ export class NotebookUtil {
default: default:
throw new Error(`Unknown file type: ${type}`); throw new Error(`Unknown file type: ${type}`);
} }
} }
public static getCurrentTimestamp(): number { export function getCurrentTimestamp(): number {
return new Date().getTime(); return new Date().getTime();
} }
/** /**
* Override from kernel-lifecycle.ts to improve kernel selection: * Override from kernel-lifecycle.ts to improve kernel selection:
* Only return the kernel name persisted in the notebook * Only return the kernel name persisted in the notebook
* *
* @param filepath * @param filepath
* @param notebook * @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 cwd = (filepath && path.dirname(filepath)) || "/";
const kernelSpecName = const kernelSpecName =
@ -68,9 +67,9 @@ export class NotebookUtil {
cwd, cwd,
kernelSpecName, kernelSpecName,
}; };
} }
public static getFilePath(path: string, fileName: string): string { export function getFilePath(path: string, fileName: string): string {
const contentInfo = GitHubUtils.fromContentUri(path); const contentInfo = GitHubUtils.fromContentUri(path);
if (contentInfo) { if (contentInfo) {
let path = fileName; let path = fileName;
@ -81,10 +80,10 @@ export class NotebookUtil {
} }
return `${path}/${fileName}`; return `${path}/${fileName}`;
} }
public static getParentPath(filepath: string): undefined | string { export function getParentPath(filepath: string): undefined | string {
const basename = NotebookUtil.getName(filepath); const basename = getName(filepath);
if (basename) { if (basename) {
const contentInfo = GitHubUtils.fromContentUri(filepath); const contentInfo = GitHubUtils.fromContentUri(filepath);
if (contentInfo) { if (contentInfo) {
@ -108,9 +107,9 @@ export class NotebookUtil {
} }
return undefined; return undefined;
} }
public static getName(path: string): undefined | string { export function getName(path: string): undefined | string {
let relativePath: string = path; let relativePath: string = path;
const contentInfo = GitHubUtils.fromContentUri(path); const contentInfo = GitHubUtils.fromContentUri(path);
if (contentInfo) { if (contentInfo) {
@ -118,9 +117,9 @@ export class NotebookUtil {
} }
return relativePath.split("/").pop(); 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); const contentInfo = GitHubUtils.fromContentUri(path);
if (contentInfo) { if (contentInfo) {
const contentName = contentInfo.path.split("/").pop(); const contentName = contentInfo.path.split("/").pop();
@ -139,9 +138,9 @@ export class NotebookUtil {
const basePath = path.split(contentName).shift(); const basePath = path.split(contentName).shift();
return `${basePath}${newName}`; return `${basePath}${newName}`;
} }
public static findFirstCodeCellWithDisplay(notebookObject: ImmutableNotebook): number { export function findFirstCodeCellWithDisplay(notebookObject: ImmutableNotebook): number {
let codeCellIndex = 0; let codeCellIndex = 0;
for (let i = 0; i < notebookObject.cellOrder.size; i++) { for (let i = 0; i < notebookObject.cellOrder.size; i++) {
const cellId = notebookObject.cellOrder.get(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."); 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 "./PublishNotebookPaneComponent.less";
import Html2Canvas from "html2canvas"; import Html2Canvas from "html2canvas";
import { ImmutableNotebook } from "@nteract/commutable/src"; import { ImmutableNotebook } from "@nteract/commutable/src";
import { NotebookUtil } from "../Notebook/NotebookUtil"; import * as NotebookUtil from "../Notebook/NotebookUtil";
export interface PublishNotebookPaneProps { export interface PublishNotebookPaneProps {
notebookName: string; 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 FileIcon from "../../../images/notebook/file-cosmos.svg";
import PublishIcon from "../../../images/notebook/publish_content.svg"; import PublishIcon from "../../../images/notebook/publish_content.svg";
import { ArrayHashMap } from "../../Common/ArrayHashMap"; import { ArrayHashMap } from "../../Common/ArrayHashMap";
import { NotebookUtil } from "../Notebook/NotebookUtil"; import * as NotebookUtil from "../Notebook/NotebookUtil";
import _ from "underscore"; import _ from "underscore";
import { IPinnedRepo } from "../../Juno/JunoClient"; import { IPinnedRepo } from "../../Juno/JunoClient";
import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor"; import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor";

View File

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

View File

@ -5,7 +5,7 @@ import { AjaxResponse } from "rxjs/ajax";
import * as Base64Utils from "../Utils/Base64Utils"; import * as Base64Utils from "../Utils/Base64Utils";
import { HttpStatusCodes } from "../Common/Constants"; import { HttpStatusCodes } from "../Common/Constants";
import * as Logger from "../Common/Logger"; 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 { GitHubClient, IGitHubFile, IGitHubResponse } from "./GitHubClient";
import * as GitHubUtils from "../Utils/GitHubUtils"; import * as GitHubUtils from "../Utils/GitHubUtils";
import UrlUtility from "../Common/UrlUtility"; import UrlUtility from "../Common/UrlUtility";