mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-04-21 17:17:49 +01:00
Disable auto save for notebooks under temporary workspace (#1181)
* disable autosave only for temporary notebooks * Add override epic description
This commit is contained in:
parent
b19144f792
commit
c7ceda3a3e
@ -12,11 +12,12 @@ import {
|
|||||||
ServerConfig as JupyterServerConfig,
|
ServerConfig as JupyterServerConfig,
|
||||||
} from "@nteract/core";
|
} from "@nteract/core";
|
||||||
import { Channels, childOf, createMessage, JupyterMessage, message, ofMessageType } from "@nteract/messaging";
|
import { Channels, childOf, createMessage, JupyterMessage, message, ofMessageType } from "@nteract/messaging";
|
||||||
|
import { defineConfigOption } from "@nteract/mythic-configuration";
|
||||||
import { RecordOf } from "immutable";
|
import { RecordOf } from "immutable";
|
||||||
import { AnyAction } from "redux";
|
import { Action, AnyAction } from "redux";
|
||||||
import { ofType, StateObservable } from "redux-observable";
|
import { ofType, StateObservable } from "redux-observable";
|
||||||
import { kernels, sessions } from "rx-jupyter";
|
import { kernels, sessions } from "rx-jupyter";
|
||||||
import { concat, EMPTY, from, merge, Observable, Observer, of, Subject, Subscriber, timer } from "rxjs";
|
import { concat, EMPTY, from, interval, merge, Observable, Observer, of, Subject, Subscriber, timer } from "rxjs";
|
||||||
import {
|
import {
|
||||||
catchError,
|
catchError,
|
||||||
concatMap,
|
concatMap,
|
||||||
@ -41,7 +42,7 @@ import { logConsoleError, logConsoleInfo } from "../../../Utils/NotificationCons
|
|||||||
import { useDialog } from "../../Controls/Dialog";
|
import { useDialog } from "../../Controls/Dialog";
|
||||||
import * as FileSystemUtil from "../FileSystemUtil";
|
import * as FileSystemUtil from "../FileSystemUtil";
|
||||||
import * as cdbActions from "../NotebookComponent/actions";
|
import * as cdbActions from "../NotebookComponent/actions";
|
||||||
import { NotebookUtil } from "../NotebookUtil";
|
import { NotebookContentProviderType, NotebookUtil } from "../NotebookUtil";
|
||||||
import * as CdbActions from "./actions";
|
import * as CdbActions from "./actions";
|
||||||
import * as TextFile from "./contents/file/text-file";
|
import * as TextFile from "./contents/file/text-file";
|
||||||
import { CdbAppState } from "./types";
|
import { CdbAppState } from "./types";
|
||||||
@ -948,6 +949,54 @@ const resetCellStatusOnExecuteCanceledEpic = (
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const { selector: autoSaveInterval } = defineConfigOption({
|
||||||
|
key: "autoSaveInterval",
|
||||||
|
label: "Auto-save interval",
|
||||||
|
defaultValue: 120_000,
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Override autoSaveCurrentContentEpic to disable auto save for notebooks under temporary workspace.
|
||||||
|
* @param action$
|
||||||
|
*/
|
||||||
|
export function autoSaveCurrentContentEpic(
|
||||||
|
action$: Observable<Action>,
|
||||||
|
state$: StateObservable<AppState>
|
||||||
|
): Observable<actions.Save> {
|
||||||
|
return state$.pipe(
|
||||||
|
map((state) => autoSaveInterval(state)),
|
||||||
|
switchMap((time) => interval(time)),
|
||||||
|
mergeMap(() => {
|
||||||
|
const state = state$.value;
|
||||||
|
return from(
|
||||||
|
selectors
|
||||||
|
.contentByRef(state)
|
||||||
|
.filter(
|
||||||
|
/*
|
||||||
|
* Only save contents that are files or notebooks with
|
||||||
|
* a filepath already set.
|
||||||
|
*/
|
||||||
|
(content) => (content.type === "file" || content.type === "notebook") && content.filepath !== ""
|
||||||
|
)
|
||||||
|
.keys()
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
filter((contentRef: ContentRef) => {
|
||||||
|
const model = selectors.model(state$.value, { contentRef });
|
||||||
|
const content = selectors.content(state$.value, { contentRef });
|
||||||
|
if (
|
||||||
|
model &&
|
||||||
|
model.type === "notebook" &&
|
||||||
|
NotebookUtil.getContentProviderType(content.filepath) !== NotebookContentProviderType.JupyterContentProviderType
|
||||||
|
) {
|
||||||
|
return selectors.notebook.isDirty(model);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}),
|
||||||
|
map((contentRef: ContentRef) => actions.save({ contentRef }))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export const allEpics = [
|
export const allEpics = [
|
||||||
addInitialCodeCellEpic,
|
addInitialCodeCellEpic,
|
||||||
focusInitialCodeCellEpic,
|
focusInitialCodeCellEpic,
|
||||||
@ -965,4 +1014,5 @@ export const allEpics = [
|
|||||||
traceNotebookInfoEpic,
|
traceNotebookInfoEpic,
|
||||||
traceNotebookKernelEpic,
|
traceNotebookKernelEpic,
|
||||||
resetCellStatusOnExecuteCanceledEpic,
|
resetCellStatusOnExecuteCanceledEpic,
|
||||||
|
autoSaveCurrentContentEpic,
|
||||||
];
|
];
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
import { AppState, epics as coreEpics, reducers, IContentProvider } from "@nteract/core";
|
import { AppState, epics as coreEpics, IContentProvider, reducers } from "@nteract/core";
|
||||||
import { compose, Store, AnyAction, Middleware, Dispatch, MiddlewareAPI } from "redux";
|
|
||||||
import { Epic } from "redux-observable";
|
|
||||||
import { allEpics } from "./epics";
|
|
||||||
import { coreReducer, cdbReducer } from "./reducers";
|
|
||||||
import { catchError } from "rxjs/operators";
|
|
||||||
import { Observable } from "rxjs";
|
|
||||||
import { configuration } from "@nteract/mythic-configuration";
|
import { configuration } from "@nteract/mythic-configuration";
|
||||||
import { makeConfigureStore } from "@nteract/myths";
|
import { makeConfigureStore } from "@nteract/myths";
|
||||||
|
import { AnyAction, compose, Dispatch, Middleware, MiddlewareAPI, Store } from "redux";
|
||||||
|
import { Epic } from "redux-observable";
|
||||||
|
import { Observable } from "rxjs";
|
||||||
|
import { catchError } from "rxjs/operators";
|
||||||
|
import { allEpics } from "./epics";
|
||||||
|
import { cdbReducer, coreReducer } from "./reducers";
|
||||||
import { CdbAppState } from "./types";
|
import { CdbAppState } from "./types";
|
||||||
|
|
||||||
const composeEnhancers = (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
|
const composeEnhancers = (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
|
||||||
@ -81,7 +81,6 @@ export const getCoreEpics = (autoStartKernelOnNotebookOpen: boolean): Epic[] =>
|
|||||||
// This list needs to be consistent and in sync with core.allEpics until we figure
|
// This list needs to be consistent and in sync with core.allEpics until we figure
|
||||||
// out how to safely filter out the ones we are overriding here.
|
// out how to safely filter out the ones we are overriding here.
|
||||||
const filteredCoreEpics = [
|
const filteredCoreEpics = [
|
||||||
coreEpics.autoSaveCurrentContentEpic,
|
|
||||||
coreEpics.executeCellEpic,
|
coreEpics.executeCellEpic,
|
||||||
coreEpics.executeFocusedCellEpic,
|
coreEpics.executeFocusedCellEpic,
|
||||||
coreEpics.executeCellAfterKernelLaunchEpic,
|
coreEpics.executeCellAfterKernelLaunchEpic,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user