Skip to content

Commit

Permalink
Hide web variableviewer features (#10313)
Browse files Browse the repository at this point in the history
* Hiding the data viewer on the variable viewer if web (#10305)

* wip

* wip

* almost there

* both fixes in the same commit, I need to clean this up

* Not using IsWebExtension

* no more console logs

* no more TODO comment

* changelog entry

* comment about the DataFrame viewer and the Plot viewer
  • Loading branch information
sadasant authored Jun 3, 2022
1 parent e087816 commit 88d22f9
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
([#8399](https://github.com/Microsoft/vscode-jupyter/issues/8399))
1. Enabled the Interactive Window in web.
([#9717](https://github.com/Microsoft/vscode-jupyter/issues/9717))
1. Enabled the Variables Viewer in web.
([#10154](https://github.com/microsoft/vscode-jupyter/pull/10154))
However, neither the DataFrame viewer nor the Plot viewer are enabled in this release.
(Tracking: [#9665](https://github.com/microsoft/vscode-jupyter/issues/9665))

### Fixes

Expand Down
4 changes: 3 additions & 1 deletion src/notebooks/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
import { IJupyterKernelSpec, KernelConnectionMetadata } from '../kernels/types';
import { JupyterNotebookView, InteractiveWindowView } from './constants';
import { CellOutputMimeTypes } from './types';
import { getOSType, OSType } from '../platform/common/utils/platform';

/**
* Whether this is a Notebook we created/manage/use.
Expand Down Expand Up @@ -360,7 +361,8 @@ function translateDisplayDataOutput(
*/
const metadata = getOutputMetadata(output);
// If we have SVG or PNG, then add special metadata to indicate whether to display `open plot`
if ('image/svg+xml' in output.data || 'image/png' in output.data) {
const osType = getOSType();
if (osType !== OSType.Unknown && ('image/svg+xml' in output.data || 'image/png' in output.data)) {
metadata.__displayOpenPlotIcon = true;
}
const items: NotebookCellOutputItem[] = [];
Expand Down
1 change: 1 addition & 0 deletions src/webviews/extension-side/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface IJupyterExtraSettings extends IJupyterSettings {
};
theme: string;
hasPythonExtension: boolean;
isWeb: boolean;
};
}

Expand Down
4 changes: 3 additions & 1 deletion src/webviews/extension-side/webviewHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { CssMessages, InteractiveWindowMessages, SharedMessages } from '../../pl
import { captureTelemetry, sendTelemetryEvent } from '../../telemetry';
import { DefaultTheme, PythonExtension, Telemetry } from '../webview-side/common/constants';
import { IJupyterExtraSettings } from './types';
import { getOSType, OSType } from '../../platform/common/utils/platform';

/* eslint-disable @typescript-eslint/no-explicit-any */

Expand Down Expand Up @@ -246,7 +247,8 @@ export abstract class WebviewHost<IMapping> implements IDisposable {
fontFamily: this.getValue(editor, 'fontFamily', "Consolas, 'Courier New', monospace")
},
theme,
hasPythonExtension: pythonExt !== undefined
hasPythonExtension: pythonExt !== undefined,
isWeb: getOSType() === OSType.Unknown
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import {
import {
InteractiveWindowMessages,
IFinishCell,
IInteractiveWindowMapping
IInteractiveWindowMapping,
SharedMessages
} from '../../../../../platform/messageTypes';
import { IJupyterExtraSettings } from '../../../../extension-side/types';
import { BaseReduxActionPayload } from '../../../../types';
import { combineReducers, QueuableAction, ReducerArg, ReducerFunc } from '../../../react-common/reduxUtils';
import { postActionToExtension } from '../helpers';
Expand All @@ -37,6 +39,7 @@ export type IVariableState = {
showVariablesOnDebug: boolean;
viewHeight: number;
requestInProgress: boolean;
isWeb: boolean;
};

type VariableReducerFunc<T = never | undefined> = ReducerFunc<
Expand Down Expand Up @@ -125,6 +128,14 @@ function handleSort(arg: VariableReducerArg<ISortVariablesRequest>): IVariableSt
};
}

function handleIsWebUpdate(arg: VariableReducerArg<string>): IVariableState {
const settings = JSON.parse(arg.payload.data) as IJupyterExtraSettings;
return {
...arg.prevState,
isWeb: settings.extraSettings.isWeb
};
}

function handleVariableExplorerHeightResponse(arg: VariableReducerArg<IVariableExplorerHeight>): IVariableState {
if (arg.payload.data) {
const containerHeight = arg.payload.data.containerHeight;
Expand Down Expand Up @@ -367,7 +378,8 @@ const reducerMap: Partial<VariableActionMapping> = {
[InteractiveWindowMessages.GetVariablesResponse]: handleResponse,
[CommonActionType.RUN_BY_LINE]: handleDebugStart,
[InteractiveWindowMessages.UpdateVariableViewExecutionCount]: updateExecutionCount,
[CommonActionType.SORT_VARIABLES]: handleSort
[CommonActionType.SORT_VARIABLES]: handleSort,
[SharedMessages.UpdateSettings]: handleIsWebUpdate
};

export function generateVariableReducer(
Expand All @@ -387,7 +399,8 @@ export function generateVariableReducer(
refreshCount: 0,
showVariablesOnDebug,
viewHeight: 0,
requestInProgress: false
requestInProgress: false,
isWeb: false
};

// Then combine that with our map of state change message to reducer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ interface IVariableExplorerProps {
sort(sortColumn: string, sortAscending: boolean): void;
viewHeight: number;
requestInProgress: boolean;
isWeb: boolean;
}

const defaultColumnProperties = {
Expand Down Expand Up @@ -66,6 +67,7 @@ interface IGridRow {
interface IVariableExplorerState {
containerHeight: number;
gridHeight: number;
isWeb: boolean;
}

/* eslint-disable @typescript-eslint/no-explicit-any */
Expand Down Expand Up @@ -99,7 +101,8 @@ export class VariableExplorer extends React.Component<IVariableExplorerProps, IV

this.state = {
containerHeight: this.props.containerHeight,
gridHeight: this.props.gridHeight
gridHeight: this.props.gridHeight,
isWeb: this.props.isWeb
};

this.handleResizeMouseMove = this.handleResizeMouseMove.bind(this);
Expand All @@ -119,6 +122,7 @@ export class VariableExplorer extends React.Component<IVariableExplorerProps, IV
<VariableExplorerButtonCellFormatter
showDataExplorer={this.props.showDataExplorer}
baseTheme={this.props.baseTheme}
isWeb={() => this.props.isWeb}
/>
)
},
Expand Down Expand Up @@ -190,6 +194,10 @@ export class VariableExplorer extends React.Component<IVariableExplorerProps, IV
return true;
}

if (prevState.isWeb !== nextProps.isWeb) {
return true;
}

return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface IVariableExplorerButtonCellFormatterProps {
baseTheme: string;
value?: IButtonCellValue;
showDataExplorer(targetVariable: IJupyterVariable, numberOfColumns: number): void;
isWeb: () => boolean;
}

export class VariableExplorerButtonCellFormatter extends React.Component<IVariableExplorerButtonCellFormatterProps> {
Expand All @@ -31,7 +32,7 @@ export class VariableExplorerButtonCellFormatter extends React.Component<IVariab
public override render() {
const className = 'variable-explorer-button-cell';
if (this.props.value !== null && this.props.value !== undefined) {
if (this.props.value.supportsDataExplorer) {
if (this.props.value.supportsDataExplorer && !this.props.isWeb()) {
return (
<div className={className}>
<ImageButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface IVariablePanelProps {
sort(sortColumn: string, sortAscending: boolean): void;
viewHeight: number;
requestInProgress: boolean;
isWeb: boolean;
}

export class VariablePanel extends React.Component<IVariablePanelProps> {
Expand All @@ -51,6 +52,7 @@ export class VariablePanel extends React.Component<IVariablePanelProps> {
refreshCount={this.props.refreshCount}
viewHeight={this.props.viewHeight}
requestInProgress={this.props.requestInProgress}
isWeb={this.props.isWeb}
/>
);
}
Expand Down
3 changes: 2 additions & 1 deletion src/webviews/webview-side/react-common/settingsReactSide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export function getDefaultSettings(): IJupyterExtraSettings {
fontFamily: "Consolas, 'Courier New', monospace"
},
theme: 'Default Dark+',
hasPythonExtension: true
hasPythonExtension: true,
isWeb: false
},
runStartupCommands: '',
debugJustMyCode: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ ${buildSettingsCss(this.props.settings)}`}</style>
refreshCount: this.props.variableState.refreshCount,
offsetHeight: 0, // No toolbar in variable view panel
viewHeight: this.props.variableState.viewHeight, // Height to use for variable view mode
requestInProgress: this.props.variableState.requestInProgress
requestInProgress: this.props.variableState.requestInProgress,
isWeb: this.props.variableState.isWeb
};
};

Expand Down

0 comments on commit 88d22f9

Please sign in to comment.