Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions src/client/datascience/data-viewing/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'use strict';
import { JSONObject } from '@phosphor/coreutils';

import { CssMessages, IGetCssRequest, IGetCssResponse, SharedMessages } from '../messages';
import { SharedMessages } from '../messages';
import { IJupyterVariable } from '../types';

export const CellFetchAllLimit = 100000;
Expand Down Expand Up @@ -40,15 +40,13 @@ export interface IGetRowsResponse {
}

// Map all messages to specific payloads
export class IDataViewerMapping {
public [DataViewerMessages.Started]: never | undefined;
public [DataViewerMessages.UpdateSettings]: string;
public [DataViewerMessages.InitializeData]: IJupyterVariable;
public [DataViewerMessages.GetAllRowsRequest]: never | undefined;
public [DataViewerMessages.GetAllRowsResponse]: JSONObject;
public [DataViewerMessages.GetRowsRequest]: IGetRowsRequest;
public [DataViewerMessages.GetRowsResponse]: IGetRowsResponse;
public [DataViewerMessages.CompletedData]: never | undefined;
public [CssMessages.GetCssRequest]: IGetCssRequest;
public [CssMessages.GetCssResponse]: IGetCssResponse;
}
export type IDataViewerMapping = {
[DataViewerMessages.Started]: never | undefined;
[DataViewerMessages.UpdateSettings]: string;
[DataViewerMessages.InitializeData]: IJupyterVariable;
[DataViewerMessages.GetAllRowsRequest]: never | undefined;
[DataViewerMessages.GetAllRowsResponse]: JSONObject;
[DataViewerMessages.GetRowsRequest]: IGetRowsRequest;
[DataViewerMessages.GetRowsResponse]: IGetRowsResponse;
[DataViewerMessages.CompletedData]: never | undefined;
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
'use strict';
import * as monacoEditor from 'monaco-editor/esm/vs/editor/editor.api';
import { IServerState } from '../../../datascience-ui/interactive-common/mainState';
import { IAddCellAction } from '../../../datascience-ui/interactive-common/redux/reducers/types';
import { CssMessages, IGetCssRequest, IGetCssResponse, IGetMonacoThemeRequest } from '../messages';
import { IAddCellAction, ICellAction } from '../../../datascience-ui/interactive-common/redux/reducers/types';
import { CssMessages, IGetCssRequest, IGetCssResponse, IGetMonacoThemeRequest, SharedMessages } from '../messages';
import { IGetMonacoThemeResponse } from '../monacoMessages';
import { ICell, IInteractiveWindowInfo, IJupyterVariable, IJupyterVariablesRequest, IJupyterVariablesResponse } from '../types';

export enum InteractiveWindowMessages {
Expand Down Expand Up @@ -305,9 +306,9 @@ export class IInteractiveWindowMapping {
public [InteractiveWindowMessages.SelectKernel]: IServerState | undefined;
public [InteractiveWindowMessages.SelectJupyterServer]: never | undefined;
public [InteractiveWindowMessages.Export]: ICell[];
public [InteractiveWindowMessages.GetAllCells]: ICell;
public [InteractiveWindowMessages.GetAllCells]: never | undefined;
public [InteractiveWindowMessages.ReturnAllCells]: ICell[];
public [InteractiveWindowMessages.DeleteCell]: never | undefined;
public [InteractiveWindowMessages.DeleteCell]: ICellAction;
public [InteractiveWindowMessages.DeleteAllCells]: IAddCellAction;
public [InteractiveWindowMessages.Undo]: never | undefined;
public [InteractiveWindowMessages.Redo]: never | undefined;
Expand All @@ -331,6 +332,7 @@ export class IInteractiveWindowMapping {
public [CssMessages.GetCssRequest]: IGetCssRequest;
public [CssMessages.GetCssResponse]: IGetCssResponse;
public [CssMessages.GetMonacoThemeRequest]: IGetMonacoThemeRequest;
public [CssMessages.GetMonacoThemeResponse]: IGetMonacoThemeResponse;
public [InteractiveWindowMessages.ProvideCompletionItemsRequest]: IProvideCompletionItemsRequest;
public [InteractiveWindowMessages.CancelCompletionItemsRequest]: ICancelIntellisenseRequest;
public [InteractiveWindowMessages.ProvideCompletionItemsResponse]: IProvideCompletionItemsResponse;
Expand Down Expand Up @@ -370,11 +372,14 @@ export class IInteractiveWindowMapping {
public [InteractiveWindowMessages.VariablesComplete]: never | undefined;
public [InteractiveWindowMessages.NotebookRunAllCells]: never | undefined;
public [InteractiveWindowMessages.NotebookRunSelectedCell]: never | undefined;
public [InteractiveWindowMessages.NotebookAddCellBelow]: never | undefined;
public [InteractiveWindowMessages.NotebookAddCellBelow]: IAddCellAction;
public [InteractiveWindowMessages.DoSave]: never | undefined;
public [InteractiveWindowMessages.ExecutionRendered]: IRenderComplete;
public [InteractiveWindowMessages.FocusedCellEditor]: IFocusedCellEditor;
public [InteractiveWindowMessages.UnfocusedCellEditor]: never | undefined;
public [InteractiveWindowMessages.MonacoReady]: never | undefined;
public [InteractiveWindowMessages.ClearAllOutputs]: never | undefined;
public [InteractiveWindowMessages.UpdateKernel]: IServerState | undefined;
public [InteractiveWindowMessages.UpdateKernel]: IServerState;
public [SharedMessages.UpdateSettings]: string;
public [SharedMessages.LocInit]: string;
}
42 changes: 42 additions & 0 deletions src/client/datascience/interactive-common/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

'use strict';

// Stuff common to React and Extensions.

type BaseData = {
/**
* If this property exists, then this is an action that has been dispatched for the solve purpose of:
* 1. Synchronizing states across different editors (pointing to the same file).
* 2. Synchronizing states across different editors (pointing to the same file) in different sessions.
*
* @type {('syncEditors' | 'syncSessions')}
*/
broadcastReason?: 'syncEditors' | 'syncSessions';
/**
* Tells us whether this message is incoming for reducer use or
* whether this is a message that needs to be sent out to extension (from reducer).
*/
messageDirection?: 'incoming' | 'outgoing';
};

type BaseDataWithPayload<T> = {
/**
* If this property exists, then this is an action that has been dispatched for the solve purpose of:
* 1. Synchronizing states across different editors (pointing to the same file).
* 2. Synchronizing states across different editors (pointing to the same file) in different sessions.
*
* @type {('syncEditors' | 'syncSessions')}
*/
broadcastReason?: 'syncEditors' | 'syncSessions';
/**
* Tells us whether this message is incoming for reducer use or
* whether this is a message that needs to be sent out to extension (from reducer).
*/
messageDirection?: 'incoming' | 'outgoing';
data: T;
};

// This forms the base content of every payload in all dispatchers.
export type BaseReduxActionPayload<T = never | undefined> = T extends never ? (T extends undefined ? BaseData : BaseDataWithPayload<T>) : BaseDataWithPayload<T>;
20 changes: 10 additions & 10 deletions src/client/datascience/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
// Licensed under the MIT License.
'use strict';

export namespace CssMessages {
export const GetCssRequest = 'get_css_request';
export const GetCssResponse = 'get_css_response';
export const GetMonacoThemeRequest = 'get_monaco_theme_request';
export const GetMonacoThemeResponse = 'get_monaco_theme_response';
export enum CssMessages {
GetCssRequest = 'get_css_request',
GetCssResponse = 'get_css_response',
GetMonacoThemeRequest = 'get_monaco_theme_request',
GetMonacoThemeResponse = 'get_monaco_theme_response'
}

export namespace SharedMessages {
export const UpdateSettings = 'update_settings';
export const Started = 'started';
export const LocInit = 'loc_init';
export const StyleUpdate = 'style_update';
export enum SharedMessages {
UpdateSettings = 'update_settings',
Started = 'started',
LocInit = 'loc_init',
StyleUpdate = 'style_update'
}

export interface IGetCssRequest {
Expand Down
2 changes: 1 addition & 1 deletion src/datascience-ui/data-explorer/mainPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class MainPanel extends React.Component<IMainPanelProps, IMainPanelState>
this.postOffice.addHandler(this);

// Tell the dataviewer code we have started.
this.postOffice.sendMessage<IDataViewerMapping, 'started'>(DataViewerMessages.Started);
this.postOffice.sendMessage<IDataViewerMapping>(DataViewerMessages.Started);
}

public componentWillUnmount() {
Expand Down
81 changes: 39 additions & 42 deletions src/datascience-ui/history-react/redux/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,60 +3,57 @@
'use strict';
import * as monacoEditor from 'monaco-editor/esm/vs/editor/editor.api';

import { IRefreshVariablesRequest } from '../../../client/datascience/interactive-common/interactiveWindowTypes';
import { InteractiveWindowMessages, IRefreshVariablesRequest } from '../../../client/datascience/interactive-common/interactiveWindowTypes';
import { IJupyterVariable, IJupyterVariablesRequest } from '../../../client/datascience/types';
import {
CommonAction,
CommonActionType,
createIncomingAction,
createIncomingActionWithPayload,
ICellAction,
ICodeAction,
ICodeCreatedAction,
IEditCellAction,
ILinkClickAction,
IScrollAction,
IShowDataViewerAction,
IShowPlotAction
IShowDataViewerAction
} from '../../interactive-common/redux/reducers/types';

// See https://react-redux.js.org/using-react-redux/connect-mapdispatch#defining-mapdispatchtoprops-as-an-object
export const actionCreators = {
refreshVariables: (newExecutionCount?: number): CommonAction<IRefreshVariablesRequest> => ({ type: CommonActionType.REFRESH_VARIABLES, payload: { newExecutionCount } }),
restartKernel: (): CommonAction<never | undefined> => ({ type: CommonActionType.RESTART_KERNEL }),
interruptKernel: (): CommonAction<never | undefined> => ({ type: CommonActionType.INTERRUPT_KERNEL }),
deleteAllCells: (): CommonAction<never | undefined> => ({ type: CommonActionType.DELETE_ALL_CELLS }),
deleteCell: (cellId: string): CommonAction<ICellAction> => ({ type: CommonActionType.DELETE_CELL, payload: { cellId } }),
undo: (): CommonAction<never | undefined> => ({ type: CommonActionType.UNDO }),
redo: (): CommonAction<never | undefined> => ({ type: CommonActionType.REDO }),
linkClick: (href: string): CommonAction<ILinkClickAction> => ({ type: CommonActionType.LINK_CLICK, payload: { href } }),
showPlot: (imageHtml: string): CommonAction<IShowPlotAction> => ({ type: CommonActionType.SHOW_PLOT, payload: { imageHtml } }),
toggleInputBlock: (cellId: string): CommonAction<ICellAction> => ({ type: CommonActionType.TOGGLE_INPUT_BLOCK, payload: { cellId } }),
gotoCell: (cellId: string): CommonAction<ICellAction> => ({ type: CommonActionType.GOTO_CELL, payload: { cellId } }),
copyCellCode: (cellId: string): CommonAction<ICellAction> => ({ type: CommonActionType.COPY_CELL_CODE, payload: { cellId } }),
gatherCell: (cellId: string): CommonAction<ICellAction> => ({ type: CommonActionType.GATHER_CELL, payload: { cellId } }),
clickCell: (cellId: string): CommonAction<ICellAction> => ({ type: CommonActionType.CLICK_CELL, payload: { cellId } }),
doubleClickCell: (cellId: string): CommonAction<ICellAction> => ({ type: CommonActionType.DOUBLE_CLICK_CELL, payload: { cellId } }),
editCell: (cellId: string, changes: monacoEditor.editor.IModelContentChange[], modelId: string, code: string): CommonAction<IEditCellAction> => ({
type: CommonActionType.EDIT_CELL,
payload: { cellId, changes, modelId, code }
}),
submitInput: (code: string, cellId: string): CommonAction<ICodeAction> => ({ type: CommonActionType.SUBMIT_INPUT, payload: { code, cellId } }),
toggleVariableExplorer: (): CommonAction<never | undefined> => ({ type: CommonActionType.TOGGLE_VARIABLE_EXPLORER }),
expandAll: (): CommonAction<never | undefined> => ({ type: CommonActionType.EXPAND_ALL }),
collapseAll: (): CommonAction<never | undefined> => ({ type: CommonActionType.COLLAPSE_ALL }),
export: (): CommonAction<never | undefined> => ({ type: CommonActionType.EXPORT }),
showDataViewer: (variable: IJupyterVariable, columnSize: number): CommonAction<IShowDataViewerAction> => ({
type: CommonActionType.SHOW_DATA_VIEWER,
payload: { variable, columnSize }
}),
editorLoaded: (): CommonAction<never | undefined> => ({ type: CommonActionType.EDITOR_LOADED }),
scroll: (isAtBottom: boolean): CommonAction<IScrollAction> => ({ type: CommonActionType.SCROLL, payload: { isAtBottom } }),
unfocus: (cellId: string | undefined): CommonAction<ICellAction> => ({ type: CommonActionType.UNFOCUS_CELL, payload: { cellId } }),
codeCreated: (cellId: string | undefined, modelId: string): CommonAction<ICodeCreatedAction> => ({ type: CommonActionType.CODE_CREATED, payload: { cellId, modelId } }),
editorUnmounted: (): CommonAction<never | undefined> => ({ type: CommonActionType.UNMOUNT }),
selectKernel: (): CommonAction<never | undefined> => ({ type: CommonActionType.SELECT_KERNEL }),
selectServer: (): CommonAction<never | undefined> => ({ type: CommonActionType.SELECT_SERVER }),
getVariableData: (newExecutionCount: number, startIndex: number = 0, pageSize: number = 100): CommonAction<IJupyterVariablesRequest> => ({
type: CommonActionType.GET_VARIABLE_DATA,
payload: { executionCount: newExecutionCount, sortColumn: 'name', sortAscending: true, startIndex, pageSize }
})
refreshVariables: (newExecutionCount?: number): CommonAction<IRefreshVariablesRequest> =>
createIncomingActionWithPayload(CommonActionType.REFRESH_VARIABLES, { newExecutionCount }),
restartKernel: (): CommonAction => createIncomingAction(CommonActionType.RESTART_KERNEL),
interruptKernel: (): CommonAction => createIncomingAction(CommonActionType.INTERRUPT_KERNEL),
deleteAllCells: (): CommonAction => createIncomingAction(InteractiveWindowMessages.DeleteAllCells),
deleteCell: (cellId: string): CommonAction<ICellAction> => createIncomingActionWithPayload(InteractiveWindowMessages.DeleteCell, { cellId }),
undo: (): CommonAction => createIncomingAction(InteractiveWindowMessages.Undo),
redo: (): CommonAction => createIncomingAction(InteractiveWindowMessages.Redo),
linkClick: (href: string): CommonAction<ILinkClickAction> => createIncomingActionWithPayload(CommonActionType.LINK_CLICK, { href }),
showPlot: (imageHtml: string): CommonAction<string> => createIncomingActionWithPayload(InteractiveWindowMessages.ShowPlot, imageHtml),
toggleInputBlock: (cellId: string): CommonAction<ICellAction> => createIncomingActionWithPayload(CommonActionType.TOGGLE_INPUT_BLOCK, { cellId }),
gotoCell: (cellId: string): CommonAction<ICellAction> => createIncomingActionWithPayload(CommonActionType.GOTO_CELL, { cellId }),
copyCellCode: (cellId: string): CommonAction<ICellAction> => createIncomingActionWithPayload(CommonActionType.COPY_CELL_CODE, { cellId }),
gatherCell: (cellId: string): CommonAction<ICellAction> => createIncomingActionWithPayload(CommonActionType.GATHER_CELL, { cellId }),
clickCell: (cellId: string): CommonAction<ICellAction> => createIncomingActionWithPayload(CommonActionType.CLICK_CELL, { cellId }),
doubleClickCell: (cellId: string): CommonAction<ICellAction> => createIncomingActionWithPayload(CommonActionType.DOUBLE_CLICK_CELL, { cellId }),
editCell: (cellId: string, changes: monacoEditor.editor.IModelContentChange[], modelId: string, code: string): CommonAction<IEditCellAction> =>
createIncomingActionWithPayload(CommonActionType.EDIT_CELL, { cellId, changes, modelId, code }),
submitInput: (code: string, cellId: string): CommonAction<ICodeAction> => createIncomingActionWithPayload(CommonActionType.SUBMIT_INPUT, { code, cellId }),
toggleVariableExplorer: (): CommonAction => createIncomingAction(CommonActionType.TOGGLE_VARIABLE_EXPLORER),
expandAll: (): CommonAction => createIncomingAction(InteractiveWindowMessages.ExpandAll),
collapseAll: (): CommonAction => createIncomingAction(InteractiveWindowMessages.CollapseAll),
export: (): CommonAction => createIncomingAction(CommonActionType.EXPORT),
showDataViewer: (variable: IJupyterVariable, columnSize: number): CommonAction<IShowDataViewerAction> =>
createIncomingActionWithPayload(CommonActionType.SHOW_DATA_VIEWER, { variable, columnSize }),
editorLoaded: (): CommonAction => createIncomingAction(CommonActionType.EDITOR_LOADED),
scroll: (isAtBottom: boolean): CommonAction<IScrollAction> => createIncomingActionWithPayload(CommonActionType.SCROLL, { isAtBottom }),
unfocus: (cellId: string | undefined): CommonAction<ICellAction> => createIncomingActionWithPayload(CommonActionType.UNFOCUS_CELL, { cellId }),
codeCreated: (cellId: string | undefined, modelId: string): CommonAction<ICodeCreatedAction> =>
createIncomingActionWithPayload(CommonActionType.CODE_CREATED, { cellId, modelId }),
editorUnmounted: (): CommonAction => createIncomingAction(CommonActionType.UNMOUNT),
selectKernel: (): CommonAction => createIncomingAction(InteractiveWindowMessages.SelectKernel),
selectServer: (): CommonAction => createIncomingAction(CommonActionType.SELECT_SERVER),
getVariableData: (newExecutionCount: number, startIndex: number = 0, pageSize: number = 100): CommonAction<IJupyterVariablesRequest> =>
createIncomingActionWithPayload(CommonActionType.GET_VARIABLE_DATA, { executionCount: newExecutionCount, sortColumn: 'name', sortAscending: true, startIndex, pageSize })
};
Loading