Prettier 2.0 (#393)

This commit is contained in:
Steve Faulkner
2021-01-20 09:15:01 -06:00
committed by GitHub
parent c1937ca464
commit 4be53284b5
500 changed files with 41927 additions and 41838 deletions

View File

@@ -25,9 +25,9 @@ export class NotebookComponentAdapter extends NotebookComponentBootstrapper impl
constructor(options: NotebookComponentAdapterOptions) {
super({
contentRef: selectors.contentRefByFilepath(options.notebookClient.getStore().getState(), {
filepath: options.contentItem.path
filepath: options.contentItem.path,
}),
notebookClient: options.notebookClient
notebookClient: options.notebookClient,
});
this.onUpdateKernelInfo = options.onUpdateKernelInfo;
@@ -42,7 +42,7 @@ export class NotebookComponentAdapter extends NotebookComponentBootstrapper impl
filepath: options.contentItem.path,
params: {},
kernelRef,
contentRef: this.contentRef
contentRef: this.contentRef,
})
);
}

View File

@@ -13,7 +13,7 @@ import {
ContentRef,
KernelRef,
NotebookContentRecord,
selectors
selectors,
} from "@nteract/core";
import * as Immutable from "immutable";
import { Provider } from "react-redux";
@@ -58,7 +58,7 @@ export class NotebookComponentBootstrapper {
mimetype: null as any,
size: 0,
writeable: false,
type: "notebook"
type: "notebook",
};
}
@@ -72,9 +72,7 @@ export class NotebookComponentBootstrapper {
}
public getContent(): { name: string; content: string | ImmutableNotebook } {
const record = this.getStore()
.getState()
.core.entities.contents.byRef.get(this.contentRef);
const record = this.getStore().getState().core.entities.contents.byRef.get(this.contentRef);
let content: string | ImmutableNotebook;
switch (record.model.type) {
case "notebook":
@@ -89,7 +87,7 @@ export class NotebookComponentBootstrapper {
return {
name: NotebookUtil.getName(record.filepath),
content
content,
};
}
@@ -99,7 +97,7 @@ export class NotebookComponentBootstrapper {
filepath: undefined,
model: NotebookComponentBootstrapper.wrapModelIntoContent(name, undefined, content),
kernelRef: undefined,
contentRef: this.contentRef
contentRef: this.contentRef,
})
);
}
@@ -126,7 +124,7 @@ export class NotebookComponentBootstrapper {
public notebookSave(): void {
this.getStore().dispatch(
actions.save({
contentRef: this.contentRef
contentRef: this.contentRef,
})
);
}
@@ -136,7 +134,7 @@ export class NotebookComponentBootstrapper {
actions.changeKernelByName({
contentRef: this.contentRef,
kernelSpecName,
oldKernelRef: this.getCurrentKernelRef()
oldKernelRef: this.getCurrentKernelRef(),
})
);
}
@@ -144,7 +142,7 @@ export class NotebookComponentBootstrapper {
public notebookRunAndAdvance(): void {
this.getStore().dispatch(
CdbActions.executeFocusedCellAndFocusNext({
contentRef: this.contentRef
contentRef: this.contentRef,
})
);
}
@@ -152,7 +150,7 @@ export class NotebookComponentBootstrapper {
public notebookRunAll(): void {
this.getStore().dispatch(
actions.executeAllCells({
contentRef: this.contentRef
contentRef: this.contentRef,
})
);
}
@@ -160,7 +158,7 @@ export class NotebookComponentBootstrapper {
public notebookInterruptKernel(): void {
this.getStore().dispatch(
actions.interruptKernel({
kernelRef: this.getCurrentKernelRef()
kernelRef: this.getCurrentKernelRef(),
})
);
}
@@ -169,7 +167,7 @@ export class NotebookComponentBootstrapper {
this.getStore().dispatch(
actions.killKernel({
restarting: false,
kernelRef: this.getCurrentKernelRef()
kernelRef: this.getCurrentKernelRef(),
})
);
}
@@ -179,7 +177,7 @@ export class NotebookComponentBootstrapper {
actions.restartKernel({
kernelRef: this.getCurrentKernelRef(),
contentRef: this.contentRef,
outputHandling: "None"
outputHandling: "None",
})
);
}
@@ -187,7 +185,7 @@ export class NotebookComponentBootstrapper {
public notebookClearAllOutputs(): void {
this.getStore().dispatch(
actions.clearAllOutputs({
contentRef: this.contentRef
contentRef: this.contentRef,
})
);
}
@@ -196,7 +194,7 @@ export class NotebookComponentBootstrapper {
this.getStore().dispatch(
actions.createCellBelow({
cellType: "code",
contentRef: this.contentRef
contentRef: this.contentRef,
})
);
}
@@ -212,7 +210,7 @@ export class NotebookComponentBootstrapper {
actions.changeCellType({
id: focusedCellId,
contentRef: this.contentRef,
to: type
to: type,
})
);
}
@@ -227,7 +225,7 @@ export class NotebookComponentBootstrapper {
this.getStore().dispatch(
actions.copyCell({
id: focusedCellId,
contentRef: this.contentRef
contentRef: this.contentRef,
})
);
}
@@ -242,7 +240,7 @@ export class NotebookComponentBootstrapper {
this.getStore().dispatch(
actions.cutCell({
id: focusedCellId,
contentRef: this.contentRef
contentRef: this.contentRef,
})
);
}
@@ -250,7 +248,7 @@ export class NotebookComponentBootstrapper {
public notebookPaste(): void {
this.getStore().dispatch(
actions.pasteCell({
contentRef: this.contentRef
contentRef: this.contentRef,
})
);
}
@@ -263,14 +261,14 @@ export class NotebookComponentBootstrapper {
store.dispatch(
actions.killKernel({
restarting: false,
kernelRef
kernelRef,
})
);
}
store.dispatch(
CdbActions.closeNotebook({
contentRef: this.contentRef
contentRef: this.contentRef,
})
);
}

View File

@@ -1,69 +1,69 @@
import { ServerConfig, IContentProvider, FileType, IContent, IGetParams } from "@nteract/core";
import { Observable } from "rxjs";
import { AjaxResponse } from "rxjs/ajax";
import { GitHubContentProvider } from "../../../GitHub/GitHubContentProvider";
import * as GitHubUtils from "../../../Utils/GitHubUtils";
export class NotebookContentProvider implements IContentProvider {
constructor(private gitHubContentProvider: GitHubContentProvider, private jupyterContentProvider: IContentProvider) {}
public remove(serverConfig: ServerConfig, path: string): Observable<AjaxResponse> {
return this.getContentProvider(path).remove(serverConfig, path);
}
public get(serverConfig: ServerConfig, path: string, params: Partial<IGetParams>): Observable<AjaxResponse> {
return this.getContentProvider(path).get(serverConfig, path, params);
}
public update<FT extends FileType>(
serverConfig: ServerConfig,
path: string,
model: Partial<IContent<FT>>
): Observable<AjaxResponse> {
return this.getContentProvider(path).update(serverConfig, path, model);
}
public create<FT extends FileType>(
serverConfig: ServerConfig,
path: string,
model: Partial<IContent<FT>> & { type: FT }
): Observable<AjaxResponse> {
return this.getContentProvider(path).create(serverConfig, path, model);
}
public save<FT extends FileType>(
serverConfig: ServerConfig,
path: string,
model: Partial<IContent<FT>>
): Observable<AjaxResponse> {
return this.getContentProvider(path).save(serverConfig, path, model);
}
public listCheckpoints(serverConfig: ServerConfig, path: string): Observable<AjaxResponse> {
return this.getContentProvider(path).listCheckpoints(serverConfig, path);
}
public createCheckpoint(serverConfig: ServerConfig, path: string): Observable<AjaxResponse> {
return this.getContentProvider(path).createCheckpoint(serverConfig, path);
}
public deleteCheckpoint(serverConfig: ServerConfig, path: string, checkpointID: string): Observable<AjaxResponse> {
return this.getContentProvider(path).deleteCheckpoint(serverConfig, path, checkpointID);
}
public restoreFromCheckpoint(
serverConfig: ServerConfig,
path: string,
checkpointID: string
): Observable<AjaxResponse> {
return this.getContentProvider(path).restoreFromCheckpoint(serverConfig, path, checkpointID);
}
private getContentProvider(path: string): IContentProvider {
if (GitHubUtils.fromContentUri(path)) {
return this.gitHubContentProvider;
}
return this.jupyterContentProvider;
}
}
import { ServerConfig, IContentProvider, FileType, IContent, IGetParams } from "@nteract/core";
import { Observable } from "rxjs";
import { AjaxResponse } from "rxjs/ajax";
import { GitHubContentProvider } from "../../../GitHub/GitHubContentProvider";
import * as GitHubUtils from "../../../Utils/GitHubUtils";
export class NotebookContentProvider implements IContentProvider {
constructor(private gitHubContentProvider: GitHubContentProvider, private jupyterContentProvider: IContentProvider) {}
public remove(serverConfig: ServerConfig, path: string): Observable<AjaxResponse> {
return this.getContentProvider(path).remove(serverConfig, path);
}
public get(serverConfig: ServerConfig, path: string, params: Partial<IGetParams>): Observable<AjaxResponse> {
return this.getContentProvider(path).get(serverConfig, path, params);
}
public update<FT extends FileType>(
serverConfig: ServerConfig,
path: string,
model: Partial<IContent<FT>>
): Observable<AjaxResponse> {
return this.getContentProvider(path).update(serverConfig, path, model);
}
public create<FT extends FileType>(
serverConfig: ServerConfig,
path: string,
model: Partial<IContent<FT>> & { type: FT }
): Observable<AjaxResponse> {
return this.getContentProvider(path).create(serverConfig, path, model);
}
public save<FT extends FileType>(
serverConfig: ServerConfig,
path: string,
model: Partial<IContent<FT>>
): Observable<AjaxResponse> {
return this.getContentProvider(path).save(serverConfig, path, model);
}
public listCheckpoints(serverConfig: ServerConfig, path: string): Observable<AjaxResponse> {
return this.getContentProvider(path).listCheckpoints(serverConfig, path);
}
public createCheckpoint(serverConfig: ServerConfig, path: string): Observable<AjaxResponse> {
return this.getContentProvider(path).createCheckpoint(serverConfig, path);
}
public deleteCheckpoint(serverConfig: ServerConfig, path: string, checkpointID: string): Observable<AjaxResponse> {
return this.getContentProvider(path).deleteCheckpoint(serverConfig, path, checkpointID);
}
public restoreFromCheckpoint(
serverConfig: ServerConfig,
path: string,
checkpointID: string
): Observable<AjaxResponse> {
return this.getContentProvider(path).restoreFromCheckpoint(serverConfig, path, checkpointID);
}
private getContentProvider(path: string): IContentProvider {
if (GitHubUtils.fromContentUri(path)) {
return this.gitHubContentProvider;
}
return this.jupyterContentProvider;
}
}

View File

@@ -49,7 +49,7 @@ const makeMapStateToProps = (
return {
kernelStatus,
kernelSpecName,
currentCellType
currentCellType,
} as VirtualCommandBarComponentProps;
}
@@ -69,7 +69,7 @@ const makeMapStateToProps = (
kernelStatus,
kernelSpecName,
currentCellType,
onRender: initialProps.onRender
onRender: initialProps.onRender,
};
};

View File

@@ -8,12 +8,12 @@ let fakeAjaxResponse: AjaxResponse = {
status: 200,
response: {},
responseText: "",
responseType: "json"
responseType: "json",
};
export const sessions = {
create: (serverConfig: unknown, body: object): Observable<AjaxResponse> => of(fakeAjaxResponse),
__setResponse: (response: AjaxResponse) => {
fakeAjaxResponse = response;
},
createSpy: undefined as any
createSpy: undefined as any,
};

View File

@@ -13,7 +13,7 @@ export interface CloseNotebookAction {
export const closeNotebook = (payload: { contentRef: ContentRef }): CloseNotebookAction => {
return {
type: CLOSE_NOTEBOOK,
payload
payload,
};
};
@@ -30,7 +30,7 @@ export const executeFocusedCellAndFocusNext = (payload: {
}): ExecuteFocusedCellAndFocusNextAction => {
return {
type: EXECUTE_FOCUSED_CELL_AND_FOCUS_NEXT,
payload
payload,
};
};
@@ -45,7 +45,7 @@ export interface UpdateKernelRestartDelayAction {
export const UpdateKernelRestartDelay = (payload: { delayMs: number }): UpdateKernelRestartDelayAction => {
return {
type: UPDATE_KERNEL_RESTART_DELAY,
payload
payload,
};
};
@@ -60,7 +60,7 @@ export interface SetHoveredCellAction {
export const setHoveredCell = (payload: { cellId: CellId }): SetHoveredCellAction => {
return {
type: SET_HOVERED_CELL,
payload
payload,
};
};
@@ -81,7 +81,7 @@ export const traceNotebookTelemetry = (payload: {
}): TraceNotebookTelemetryAction => {
return {
type: TRACE_NOTEBOOK_TELEMETRY,
payload
payload,
};
};
@@ -100,6 +100,6 @@ export const UpdateNotebookParentDomElt = (payload: {
}): UpdateNotebookParentDomEltAction => {
return {
type: UPDATE_NOTEBOOK_PARENT_DOM_ELTS,
payload
payload,
};
};

View File

@@ -85,7 +85,7 @@ const makeMapStateToProps = (initialState: AppState, initialProps: InitialProps)
return {
contentRef,
mimetype: content.mimetype,
type: content.type
type: content.type,
};
};

View File

@@ -45,7 +45,7 @@ export class TextFile extends React.PureComponent<TextFileProps, TextFileState>
constructor(props: TextFileProps) {
super(props);
this.state = {
Editor: EditorPlaceholder
Editor: EditorPlaceholder,
};
}
@@ -54,7 +54,7 @@ export class TextFile extends React.PureComponent<TextFileProps, TextFileState>
};
componentDidMount(): void {
import(/* webpackChunkName: "monaco-editor" */ "@nteract/monaco-editor").then(module => {
import(/* webpackChunkName: "monaco-editor" */ "@nteract/monaco-editor").then((module) => {
this.setState({ Editor: module.default });
});
}
@@ -99,7 +99,7 @@ function makeMapStateToTextFileProps(
return {
contentRef,
mimetype: content.mimetype != null ? content.mimetype : "text/plain",
text
text,
};
};
return mapStateToTextFileProps;
@@ -117,10 +117,10 @@ const makeMapDispatchToTextFileProps = (
dispatch(
actions.updateFileText({
contentRef,
text: source
text: source,
})
);
}
},
};
};
return mapDispatchToTextFileProps;

View File

@@ -10,7 +10,7 @@ import {
DirectoryContentRecordProps,
DummyContentRecordProps,
FileContentRecordProps,
NotebookContentRecordProps
NotebookContentRecordProps,
} from "@nteract/core";
import { RecordOf } from "immutable";
import * as React from "react";
@@ -51,7 +51,7 @@ class Contents extends React.PureComponent<ContentsProps> {
OPEN: ["ctrl+o", "meta+o"],
PASTE_CELL: ["ctrl+shift+v"],
RESTART_KERNEL: ["alt+r r", "alt+r c", "alt+r a"],
SAVE: ["ctrl+s", "ctrl+shift+s", "meta+s", "meta+shift+s"]
SAVE: ["ctrl+s", "ctrl+shift+s", "meta+s", "meta+shift+s"],
};
render(): JSX.Element {
@@ -96,7 +96,7 @@ const makeMapStateToProps: any = (initialState: AppState, initialProps: { conten
return {
contentRef: undefined,
error: undefined,
headerData: undefined
headerData: undefined,
};
}
@@ -104,7 +104,7 @@ const makeMapStateToProps: any = (initialState: AppState, initialProps: { conten
authors: [],
description: "",
tags: [],
title: ""
title: "",
};
// If a notebook, we need to read in the headerData if available
@@ -118,14 +118,14 @@ const makeMapStateToProps: any = (initialState: AppState, initialProps: { conten
authors,
description,
tags,
title
title,
});
}
return {
contentRef,
error: content.error,
headerData
headerData,
};
};
@@ -140,7 +140,7 @@ const mapDispatchToProps = (dispatch: Dispatch, ownProps: ContentsProps): object
return dispatch(
actions.overwriteMetadataFields({
...props,
contentRef: ownProps.contentRef
contentRef: ownProps.contentRef,
})
);
},
@@ -165,8 +165,8 @@ const mapDispatchToProps = (dispatch: Dispatch, ownProps: ContentsProps): object
event.key === "r" ? "None" : event.key === "a" ? "Run All" : "Clear All";
return dispatch(actions.restartKernel({ outputHandling, contentRef }));
},
SAVE: () => dispatch(actions.save({ contentRef }))
}
SAVE: () => dispatch(actions.save({ contentRef })),
},
};
};

View File

@@ -19,7 +19,7 @@ describe("Extract kernel from notebook", () => {
kernelspec: {
display_name: "Python 3",
language: "python",
name: "python3"
name: "python3",
},
language_info: {
name: "python",
@@ -27,13 +27,13 @@ describe("Extract kernel from notebook", () => {
mimetype: "text/x-python",
codemirror_mode: {
name: "ipython",
version: 3
version: 3,
},
pygments_lexer: "ipython3",
nbconvert_exporter: "python",
file_extension: ".py"
}
})
file_extension: ".py",
},
}),
});
const result = NotebookUtil.extractNewKernel("blah", fakeNotebook);
@@ -49,13 +49,13 @@ describe("Extract kernel from notebook", () => {
mimetype: "text/x-python",
codemirror_mode: {
name: "ipython",
version: 3
version: 3,
},
pygments_lexer: "ipython3",
nbconvert_exporter: "python",
file_extension: ".py"
}
})
file_extension: ".py",
},
}),
});
const result = NotebookUtil.extractNewKernel("blah", fakeNotebook);
@@ -65,8 +65,8 @@ describe("Extract kernel from notebook", () => {
it("Returns nothing if no kernelspec nor language info is found in metadata", () => {
const fakeNotebook = makeNotebookRecord({
metadata: Immutable.Map({
blah: "this should be ignored"
})
blah: "this should be ignored",
}),
});
const result = NotebookUtil.extractNewKernel("blah", fakeNotebook);
@@ -79,8 +79,8 @@ const initialState = {
host: state.makeJupyterHostRecord({
type: "jupyter",
token: "eh",
basePath: "/"
})
basePath: "/",
}),
}),
comms: state.makeCommsRecord(),
config: Immutable.Map({}),
@@ -89,8 +89,8 @@ const initialState = {
entities: state.makeEntitiesRecord({
contents: state.makeContentsRecord({
byRef: Immutable.Map({
fakeContentRef: state.makeNotebookContentRecord()
})
fakeContentRef: state.makeNotebookContentRecord(),
}),
}),
kernels: state.makeKernelsRecord({
byRef: Immutable.Map({
@@ -98,16 +98,16 @@ const initialState = {
type: "websocket",
channels: new Subject<any>(),
kernelSpecName: "fancy",
id: "0"
})
})
})
})
id: "0",
}),
}),
}),
}),
}),
cdb: makeCdbRecord({
databaseAccountName: "dbAccountName",
defaultExperience: "defaultExperience"
})
defaultExperience: "defaultExperience",
}),
};
describe("launchWebSocketKernelEpic", () => {
@@ -130,7 +130,7 @@ describe("launchWebSocketKernelEpic", () => {
kernelRef,
kernelSpecName,
cwd,
selectNextKernel: true
selectNextKernel: true,
})
);
@@ -149,20 +149,18 @@ describe("launchWebSocketKernelEpic", () => {
name: "kernel_launched",
last_activity: "2019-11-07T14:29:54.432454Z",
execution_state: "starting",
connections: 0
connections: 0,
},
notebook: {
path: "notebooks/Untitled7.ipynb",
name: ""
}
name: "",
},
},
responseText: null,
responseType: "json"
responseType: "json",
});
const responseActions = await launchWebSocketKernelEpic(action$, state$)
.pipe(toArray())
.toPromise();
const responseActions = await launchWebSocketKernelEpic(action$, state$).pipe(toArray()).toPromise();
expect(responseActions).toMatchObject([
{
@@ -177,10 +175,10 @@ describe("launchWebSocketKernelEpic", () => {
type: "websocket",
kernelSpecName,
cwd,
id: kernelId
}
}
}
id: kernelId,
},
},
},
]);
});
@@ -198,7 +196,7 @@ describe("launchWebSocketKernelEpic", () => {
kernelRef,
kernelSpecName,
cwd,
selectNextKernel: true
selectNextKernel: true,
})
);
@@ -217,25 +215,23 @@ describe("launchWebSocketKernelEpic", () => {
name: "kernel_launched",
last_activity: "2019-11-07T14:29:54.432454Z",
execution_state: "starting",
connections: 0
connections: 0,
},
notebook: {
path: "notebooks/Untitled7.ipynb",
name: ""
}
name: "",
},
},
responseText: null,
responseType: "json"
responseType: "json",
});
await launchWebSocketKernelEpic(action$, state$)
.pipe(toArray())
.toPromise();
await launchWebSocketKernelEpic(action$, state$).pipe(toArray()).toPromise();
expect(createSpy.lastCall.args[1]).toMatchObject({
kernel: {
name: kernelSpecName
}
name: kernelSpecName,
},
});
});
@@ -253,7 +249,7 @@ describe("launchWebSocketKernelEpic", () => {
kernelRef,
kernelSpecName: undefined,
cwd,
selectNextKernel: true
selectNextKernel: true,
})
);
@@ -272,25 +268,23 @@ describe("launchWebSocketKernelEpic", () => {
name: "kernel_launched",
last_activity: "2019-11-07T14:29:54.432454Z",
execution_state: "starting",
connections: 0
connections: 0,
},
notebook: {
path: "notebooks/Untitled7.ipynb",
name: ""
}
name: "",
},
},
responseText: null,
responseType: "json"
responseType: "json",
});
const responseActions = await launchWebSocketKernelEpic(action$, state$)
.pipe(toArray())
.toPromise();
const responseActions = await launchWebSocketKernelEpic(action$, state$).pipe(toArray()).toPromise();
expect(responseActions).toMatchObject([
{
type: actions.LAUNCH_KERNEL_FAILED
}
type: actions.LAUNCH_KERNEL_FAILED,
},
]);
});
@@ -304,7 +298,7 @@ describe("launchWebSocketKernelEpic", () => {
kernelRef,
kernelSpecName: undefined,
cwd,
selectNextKernel: true
selectNextKernel: true,
})
);
@@ -315,17 +309,15 @@ describe("launchWebSocketKernelEpic", () => {
status: 500,
response: null,
responseText: null,
responseType: "json"
responseType: "json",
});
const responseActions = await launchWebSocketKernelEpic(action$, state$)
.pipe(toArray())
.toPromise();
const responseActions = await launchWebSocketKernelEpic(action$, state$).pipe(toArray()).toPromise();
expect(responseActions).toMatchObject([
{
type: actions.LAUNCH_KERNEL_FAILED
}
type: actions.LAUNCH_KERNEL_FAILED,
},
]);
});
@@ -346,7 +338,7 @@ describe("launchWebSocketKernelEpic", () => {
language: "language1",
displayName: "Kernel One",
metadata: Immutable.Map(),
resources: Immutable.Map()
resources: Immutable.Map(),
}),
kernel2: state.makeKernelspec({
name: "kernel2",
@@ -356,12 +348,12 @@ describe("launchWebSocketKernelEpic", () => {
language: "language2",
displayName: "Kernel Two",
metadata: Immutable.Map(),
resources: Immutable.Map()
})
})
})
resources: Immutable.Map(),
}),
}),
}),
}),
refs: Immutable.List(["kernelspecsref"])
refs: Immutable.List(["kernelspecsref"]),
});
initialState.core = initialState.core
.setIn(["entities", "kernelspecs"], createKernelSpecsRecord())
@@ -383,15 +375,15 @@ describe("launchWebSocketKernelEpic", () => {
name: "kernel_launched",
last_activity: "2019-11-07T14:29:54.432454Z",
execution_state: "starting",
connections: 0
connections: 0,
},
notebook: {
path: "notebooks/Untitled7.ipynb",
name: ""
}
name: "",
},
},
responseText: null,
responseType: "json"
responseType: "json",
});
});
@@ -404,17 +396,15 @@ describe("launchWebSocketKernelEpic", () => {
kernelRef,
kernelSpecName: "kernel2",
cwd: "cwd",
selectNextKernel: true
selectNextKernel: true,
})
);
await launchWebSocketKernelEpic(action$, state$)
.pipe(toArray())
.toPromise();
await launchWebSocketKernelEpic(action$, state$).pipe(toArray()).toPromise();
expect(createSpy.lastCall.args[1]).toMatchObject({
kernel: {
name: "kernel2"
}
name: "kernel2",
},
});
});
@@ -427,18 +417,16 @@ describe("launchWebSocketKernelEpic", () => {
kernelRef,
kernelSpecName: undefined,
cwd: "cwd",
selectNextKernel: true
selectNextKernel: true,
})
);
await launchWebSocketKernelEpic(action$, state$)
.pipe(toArray())
.toPromise();
await launchWebSocketKernelEpic(action$, state$).pipe(toArray()).toPromise();
expect(createSpy.lastCall.args[1]).toMatchObject({
kernel: {
name: "kernel2"
}
name: "kernel2",
},
});
});
@@ -451,18 +439,16 @@ describe("launchWebSocketKernelEpic", () => {
kernelRef,
kernelSpecName: "This is an unknown kernelspec",
cwd: "cwd",
selectNextKernel: true
selectNextKernel: true,
})
);
await launchWebSocketKernelEpic(action$, state$)
.pipe(toArray())
.toPromise();
await launchWebSocketKernelEpic(action$, state$).pipe(toArray()).toPromise();
expect(createSpy.lastCall.args[1]).toMatchObject({
kernel: {
name: "kernel2"
}
name: "kernel2",
},
});
});
@@ -475,18 +461,16 @@ describe("launchWebSocketKernelEpic", () => {
kernelRef,
kernelSpecName: "ernel1",
cwd: "cwd",
selectNextKernel: true
selectNextKernel: true,
})
);
await launchWebSocketKernelEpic(action$, state$)
.pipe(toArray())
.toPromise();
await launchWebSocketKernelEpic(action$, state$).pipe(toArray()).toPromise();
expect(createSpy.lastCall.args[1]).toMatchObject({
kernel: {
name: "kernel1"
}
name: "kernel1",
},
});
});
});

View File

@@ -14,7 +14,7 @@ import {
catchError,
first,
concatMap,
timeout
timeout,
} from "rxjs/operators";
import {
AppState,
@@ -27,7 +27,7 @@ import {
ContentRef,
KernelInfo,
actions,
selectors
selectors,
} from "@nteract/core";
import { message, JupyterMessage, Channels, createMessage, childOf, ofMessageType } from "@nteract/messaging";
import { sessions, kernels } from "rx-jupyter";
@@ -58,7 +58,7 @@ const logFailureToTelemetry = (state: CdbAppState, title: string, error?: string
defaultExperience: state.cdb.defaultExperience,
dataExplorerArea: Constants.Areas.Notebook,
title,
error
error,
});
};
@@ -73,7 +73,7 @@ const addInitialCodeCellEpic = (
): Observable<{} | actions.CreateCellBelow> => {
return action$.pipe(
ofType(actions.FETCH_CONTENT_FULFILLED),
mergeMap(action => {
mergeMap((action) => {
const state = state$.value;
const contentRef = action.payload.contentRef;
const model = selectors.model(state, { contentRef });
@@ -88,7 +88,7 @@ const addInitialCodeCellEpic = (
return of(
actions.createCellAppend({
cellType: "code",
contentRef
contentRef,
})
);
}
@@ -135,8 +135,8 @@ export const acquireKernelInfoEpic = (action$: Observable<actions.NewKernelActio
payload: {
kernel: { channels },
kernelRef,
contentRef
}
contentRef,
},
} = action;
return acquireKernelInfo(channels, kernelRef, contentRef);
})
@@ -153,7 +153,7 @@ function acquireKernelInfo(channels: Channels, kernelRef: KernelRef, contentRef:
childOf(message),
ofMessageType("kernel_info_reply"),
first(),
mergeMap(msg => {
mergeMap((msg) => {
const content = msg.content;
const languageInfo = (content && content.language_info) || {
name: "",
@@ -162,7 +162,7 @@ function acquireKernelInfo(channels: Channels, kernelRef: KernelRef, contentRef:
file_extension: "",
pygments_lexer: "",
codemirror_mode: "",
nbconvert_exporter: ""
nbconvert_exporter: "",
};
switch (languageInfo.name) {
@@ -186,7 +186,7 @@ function acquireKernelInfo(channels: Channels, kernelRef: KernelRef, contentRef:
fileExtension: languageInfo.file_extension,
pygmentsLexer: languageInfo.pygments_lexer,
codemirrorMode: languageInfo.codemirror_mode,
nbconvertExporter: languageInfo.nbconvert_exporter
nbconvertExporter: languageInfo.nbconvert_exporter,
};
let result;
@@ -197,8 +197,8 @@ function acquireKernelInfo(channels: Channels, kernelRef: KernelRef, contentRef:
contentRef,
error: new Error(
"The kernel that you are attempting to launch does not support the latest version (v5) of the messaging protocol."
)
})
),
}),
];
} else {
result = [
@@ -206,12 +206,12 @@ function acquireKernelInfo(channels: Channels, kernelRef: KernelRef, contentRef:
actions.setLanguageInfo({
langInfo: msg.content.language_info,
kernelRef,
contentRef
contentRef,
}),
actions.setKernelInfo({
kernelRef,
info
})
info,
}),
];
}
@@ -236,7 +236,7 @@ function acquireKernelInfo(channels: Channels, kernelRef: KernelRef, contentRef:
const connect = (serverConfig: NotebookServiceConfig, kernelID: string, sessionID?: string): Subject<any> => {
const wsSubject = webSocket<JupyterMessage>({
url: formWebSocketURL(serverConfig, kernelID, sessionID),
protocol: serverConfig.wsProtocol
protocol: serverConfig.wsProtocol,
});
// Create a subject that does some of the handling inline for the session
@@ -249,8 +249,8 @@ const connect = (serverConfig: NotebookServiceConfig, kernelID: string, sessionI
...message,
header: {
session: sessionID,
...message.header
}
...message.header,
},
};
wsSubject.next(sessionizedMessage);
@@ -297,7 +297,7 @@ export const launchWebSocketKernelEpic = (
serverConfig.userPuid = getUserPuid();
const {
payload: { kernelSpecName, cwd, kernelRef, contentRef }
payload: { kernelSpecName, cwd, kernelRef, contentRef },
} = action;
const content = selectors.content(state, { contentRef });
@@ -321,7 +321,7 @@ export const launchWebSocketKernelEpic = (
error: new Error(
"Unable to launch kernel: no kernelspec name specified to launch and no default kernelspecs"
),
contentRef
contentRef,
})
);
}
@@ -330,7 +330,7 @@ export const launchWebSocketKernelEpic = (
// Find a kernel that best matches the kernel name
const match = currentKernelspecs.byName.find(
value => value.name.toLowerCase().indexOf(kernelSpecName.toLowerCase()) !== -1
(value) => value.name.toLowerCase().indexOf(kernelSpecName.toLowerCase()) !== -1
);
if (match) {
kernelSpecToLaunch = match.name;
@@ -346,15 +346,15 @@ export const launchWebSocketKernelEpic = (
const sessionPayload = {
kernel: {
id: null,
name: kernelSpecToLaunch
name: kernelSpecToLaunch,
} as any,
name: "",
path: content.filepath.replace(/^\/+/g, ""),
type: "notebook"
type: "notebook",
};
return sessions.create(serverConfig, sessionPayload).pipe(
mergeMap(data => {
mergeMap((data) => {
const session = data.response;
const sessionId = castToSessionId(session.id);
@@ -365,7 +365,7 @@ export const launchWebSocketKernelEpic = (
sessionId,
cwd,
channels: connect(serverConfig, session.kernel.id, sessionId),
kernelSpecName: kernelSpecToLaunch
kernelSpecName: kernelSpecToLaunch,
});
kernel.channels.next(message({ msg_type: "kernel_info_request" }));
@@ -375,11 +375,11 @@ export const launchWebSocketKernelEpic = (
kernel,
kernelRef,
contentRef: action.payload.contentRef,
selectNextKernel: true
selectNextKernel: true,
})
);
}),
catchError(error => {
catchError((error) => {
return of(actions.launchKernelFailed({ error }));
})
);
@@ -411,7 +411,7 @@ export const restartWebSocketKernelEpic = (
actions.restartKernelFailed({
error: new Error("Can't execute restart without kernel ref."),
kernelRef: "none provided",
contentRef
contentRef,
})
);
}
@@ -422,7 +422,7 @@ export const restartWebSocketKernelEpic = (
actions.restartKernelFailed({
error: new Error("Can't restart a kernel with no Jupyter host."),
kernelRef,
contentRef
contentRef,
})
);
}
@@ -433,7 +433,7 @@ export const restartWebSocketKernelEpic = (
actions.restartKernelFailed({
error: new Error("Can't restart a kernel that does not exist."),
kernelRef,
contentRef
contentRef,
})
);
}
@@ -443,7 +443,7 @@ export const restartWebSocketKernelEpic = (
actions.restartKernelFailed({
error: new Error("Can only restart Websocket kernels via API."),
kernelRef,
contentRef
contentRef,
})
);
}
@@ -451,7 +451,7 @@ export const restartWebSocketKernelEpic = (
const newKernelRef = createKernelRef();
const kill = actions.killKernel({
restarting: true,
kernelRef
kernelRef,
});
const relaunch = actions.launchKernelByName({
@@ -459,7 +459,7 @@ export const restartWebSocketKernelEpic = (
cwd: kernel.cwd,
kernelRef: newKernelRef,
selectNextKernel: true,
contentRef: contentRef
contentRef: contentRef,
});
const awaitKernelReady = action$.pipe(
@@ -470,7 +470,7 @@ export const restartWebSocketKernelEpic = (
concatMap(() => {
const restartSuccess = actions.restartKernelSuccessful({
kernelRef: newKernelRef,
contentRef
contentRef,
});
if ((action as actions.RestartKernel).payload.outputHandling === "Run All") {
@@ -479,12 +479,12 @@ export const restartWebSocketKernelEpic = (
return of(restartSuccess);
}
}),
catchError(error => {
catchError((error) => {
return of(
actions.restartKernelFailed({
error,
kernelRef: newKernelRef,
contentRef
contentRef,
})
);
})
@@ -511,7 +511,7 @@ const changeWebSocketKernelEpic = (
filter(() => selectors.isCurrentHostJupyter(state$.value)),
switchMap((action: actions.ChangeKernelByName) => {
const {
payload: { contentRef, oldKernelRef, kernelSpecName }
payload: { contentRef, oldKernelRef, kernelSpecName },
} = action;
const state = state$.value;
const host = selectors.currentHost(state);
@@ -539,7 +539,7 @@ const changeWebSocketKernelEpic = (
}
const {
filepath,
model: { notebook }
model: { notebook },
} = content;
const { cwd } = NotebookUtil.extractNewKernel(filepath, notebook);
@@ -548,7 +548,7 @@ const changeWebSocketKernelEpic = (
mergeMap(({ response }) => {
const { id: kernelId } = response;
const sessionPayload = {
kernel: { id: kernelId, name: kernelSpecName }
kernel: { id: kernelId, name: kernelSpecName },
};
// The sessions API will close down the old kernel for us if it is on this session
return sessions.update(serverConfig, sessionId, sessionPayload).pipe(
@@ -558,21 +558,21 @@ const changeWebSocketKernelEpic = (
sessionId,
cwd,
channels: connect(serverConfig, session.kernel.id, sessionId),
kernelSpecName
kernelSpecName,
});
return of(
actions.launchKernelSuccessful({
kernel,
kernelRef,
contentRef: action.payload.contentRef,
selectNextKernel: true
selectNextKernel: true,
})
);
}),
catchError(error => of(actions.launchKernelFailed({ error, kernelRef, contentRef })))
catchError((error) => of(actions.launchKernelFailed({ error, kernelRef, contentRef })))
);
}),
catchError(error => of(actions.launchKernelFailed({ error, kernelRef, contentRef })))
catchError((error) => of(actions.launchKernelFailed({ error, kernelRef, contentRef })))
);
})
);
@@ -589,7 +589,7 @@ const focusInitialCodeCellEpic = (
): Observable<{} | actions.FocusCell> => {
return action$.pipe(
ofType(actions.CREATE_CELL_APPEND),
mergeMap(action => {
mergeMap((action) => {
const state = state$.value;
const contentRef = action.payload.contentRef;
const model = selectors.model(state, { contentRef });
@@ -606,7 +606,7 @@ const focusInitialCodeCellEpic = (
return of(
actions.focusCell({
id,
contentRef
contentRef,
})
);
}
@@ -631,7 +631,7 @@ const notificationsToUserEpic = (action$: Observable<any>, state$: StateObservab
actions.SAVE_FAILED,
actions.FETCH_CONTENT_FAILED
),
mergeMap(action => {
mergeMap((action) => {
switch (action.type) {
case actions.RESTART_KERNEL_SUCCESSFUL: {
const title = "Kernel restart";
@@ -677,7 +677,7 @@ const handleKernelConnectionLostEpic = (
): Observable<CdbActions.UpdateKernelRestartDelayAction | actions.RestartKernel | {}> => {
return action$.pipe(
ofType(actions.UPDATE_DISPLAY_FAILED),
mergeMap(action => {
mergeMap((action) => {
const state = state$.value;
const msg = "Notebook was disconnected from kernel";
@@ -708,14 +708,14 @@ const handleKernelConnectionLostEpic = (
of(CdbActions.UpdateKernelRestartDelay({ delayMs: delayMs * 1.5 })),
sessions.list(serverConfig).pipe(
delayWhen(() => timer(delayMs)),
map(xhr => {
map((xhr) => {
return actions.restartKernel({
outputHandling: "None",
kernelRef,
contentRef
contentRef,
});
}),
retryWhen(errors => {
retryWhen((errors) => {
return errors.pipe(
delayWhen(() => timer(Constants.Notebook.heartbeatDelayMs)),
tap(() => console.log("retrying...")) // TODO: Send new action?
@@ -738,12 +738,12 @@ export const cleanKernelOnConnectionLostEpic = (
): Observable<actions.KillKernelSuccessful> => {
return action$.pipe(
ofType(actions.UPDATE_DISPLAY_FAILED),
switchMap(action => {
switchMap((action) => {
const contentRef = action.payload.contentRef;
const kernelRef = selectors.kernelRefByContentRef(state$.value, { contentRef });
return of(
actions.killKernelSuccessful({
kernelRef
kernelRef,
})
);
})
@@ -761,7 +761,7 @@ const executeFocusedCellAndFocusNextEpic = (
): Observable<{} | actions.FocusNextCellEditor> => {
return action$.pipe(
ofType(CdbActions.EXECUTE_FOCUSED_CELL_AND_FOCUS_NEXT),
mergeMap(action => {
mergeMap((action) => {
const contentRef = action.payload.contentRef;
return concat(
of(actions.executeFocusedCell({ contentRef })),
@@ -801,7 +801,7 @@ const closeUnsupportedMimetypesEpic = (
): Observable<{}> => {
return action$.pipe(
ofType(actions.FETCH_CONTENT_FULFILLED),
mergeMap(action => {
mergeMap((action) => {
const mimetype = action.payload.model.mimetype;
const explorer = window.dataExplorer;
if (explorer && !TextFile.handles(mimetype)) {
@@ -830,7 +830,7 @@ const closeContentFailedToFetchEpic = (
): Observable<{}> => {
return action$.pipe(
ofType(actions.FETCH_CONTENT_FAILED),
mergeMap(action => {
mergeMap((action) => {
const explorer = window.dataExplorer;
if (explorer) {
const filepath = action.payload.filepath;
@@ -860,7 +860,7 @@ const traceNotebookTelemetryEpic = (
...action.payload.data,
databaseAccountName: state.cdb.databaseAccountName,
defaultExperience: state.cdb.defaultExperience,
dataExplorerArea: Areas.Notebook
dataExplorerArea: Areas.Notebook,
});
return EMPTY;
})
@@ -893,7 +893,7 @@ const traceNotebookInfoEpic = (
nbCodeCells: 0,
nbRawCells: 0,
nbMarkdownCells: 0,
nbCells: 0
nbCells: 0,
};
for (let [id, cell] of selectors.notebook.cellMap(model)) {
switch (cell.cell_type) {
@@ -914,7 +914,7 @@ const traceNotebookInfoEpic = (
cdbActions.traceNotebookTelemetry({
action: TelemetryAction.NotebooksFetched,
actionModifier: ActionModifiers.Mark,
data: dataToLog
data: dataToLog,
})
);
})
@@ -938,8 +938,8 @@ const traceNotebookKernelEpic = (
action: TelemetryAction.NotebooksKernelSpecName,
actionModifier: ActionModifiers.Mark,
data: {
kernelSpecName: action.payload.kernel.name
}
kernelSpecName: action.payload.kernel.name,
},
})
);
})
@@ -961,5 +961,5 @@ export const allEpics = [
restartWebSocketKernelEpic,
traceNotebookTelemetryEpic,
traceNotebookInfoEpic,
traceNotebookKernelEpic
traceNotebookKernelEpic,
];

View File

@@ -2,24 +2,24 @@
// https://github.com/nteract/nteract/blob/master/applications/jupyter-extension/nteract_on_jupyter/app/contents/notebook.tsx
export default (props: { addTransform: (component: any) => void }) => {
import(/* webpackChunkName: "plotly" */ "@nteract/transform-plotly").then(module => {
import(/* webpackChunkName: "plotly" */ "@nteract/transform-plotly").then((module) => {
props.addTransform(module.default);
props.addTransform(module.PlotlyNullTransform);
});
import(/* webpackChunkName: "tabular-dataresource" */ "@nteract/data-explorer").then(module => {
import(/* webpackChunkName: "tabular-dataresource" */ "@nteract/data-explorer").then((module) => {
props.addTransform(module.default);
});
import(/* webpackChunkName: "jupyter-widgets" */ "@nteract/jupyter-widgets").then(module => {
import(/* webpackChunkName: "jupyter-widgets" */ "@nteract/jupyter-widgets").then((module) => {
props.addTransform(module.WidgetDisplay);
});
import("@nteract/transform-model-debug").then(module => {
import("@nteract/transform-model-debug").then((module) => {
props.addTransform(module.default);
});
import(/* webpackChunkName: "vega-transform" */ "@nteract/transform-vega").then(module => {
import(/* webpackChunkName: "vega-transform" */ "@nteract/transform-vega").then((module) => {
props.addTransform(module.VegaLite1);
props.addTransform(module.VegaLite2);
props.addTransform(module.VegaLite3);

View File

@@ -41,7 +41,7 @@ export const coreReducer = (state: CoreRecord, action: Action) => {
"model",
"notebook",
"metadata",
"kernelspec"
"kernelspec",
];
// Update metadata
return state

View File

@@ -23,7 +23,7 @@ export default function configureStore(
*/
const catchErrorMiddleware: Middleware = <D extends Dispatch<AnyAction>, S extends AppState>({
dispatch,
getState
getState,
}: MiddlewareAPI<D, S>) => (next: Dispatch<AnyAction>) => <A extends AnyAction>(action: A): any => {
try {
next(action);
@@ -52,7 +52,7 @@ export default function configureStore(
};
const protectEpics = (epics: Epic[]): Epic[] => {
return epics.map(epic => protect(epic));
return epics.map((epic) => protect(epic));
};
const filteredCoreEpics = getCoreEpics(autoStartKernelOnNotebookOpen);
@@ -62,12 +62,12 @@ export default function configureStore(
reducers: {
app: reducers.app,
core: coreReducer as any,
cdb: cdbReducer
cdb: cdbReducer,
},
epics: protectEpics([...filteredCoreEpics, ...allEpics]),
epicDependencies: { contentProvider },
epicMiddleware: customMiddlewares.concat(catchErrorMiddleware),
enhancer: composeEnhancers
enhancer: composeEnhancers,
});
const store = mythConfigureStore(initialState as any);
@@ -100,7 +100,7 @@ export const getCoreEpics = (autoStartKernelOnNotebookOpen: boolean): Epic[] =>
coreEpics.saveContentEpic,
coreEpics.publishToBookstore,
coreEpics.publishToBookstoreAfterSave,
coreEpics.sendInputReplyEpic
coreEpics.sendInputReplyEpic,
];
if (autoStartKernelOnNotebookOpen) {

View File

@@ -23,5 +23,5 @@ export const makeCdbRecord = Immutable.Record<CdbRecordProps>({
defaultExperience: undefined,
kernelRestartDelayMs: Notebook.kernelRestartInitialDelayMs,
hoveredCellId: undefined,
currentNotebookParentElements: new Map<ContentRef, HTMLElement>()
currentNotebookParentElements: new Map<ContentRef, HTMLElement>(),
});