Skip to content

Commit

Permalink
Hide raw text if output is an ipywidget (microsoft#10620)
Browse files Browse the repository at this point in the history
  • Loading branch information
DonJayamanne committed Mar 17, 2020
1 parent 6141edb commit 3c6f009
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/datascience-ui/interactive-common/cellOutput.tsx
Expand Up @@ -16,7 +16,7 @@ import { ImageButton } from '../react-common/imageButton';
import { getLocString } from '../react-common/locReactSide';
import { fixLatexEquations } from './latexManipulation';
import { ICellViewModel } from './mainState';
import { getRichestMimetype, getTransform, isMimeTypeSupported } from './transforms';
import { getRichestMimetype, getTransform, isIPyWidgetOutput, isMimeTypeSupported } from './transforms';

// tslint:disable-next-line: no-var-requires no-require-imports
const ansiToHtml = require('ansi-to-html');
Expand Down Expand Up @@ -504,8 +504,10 @@ export class CellOutput extends React.Component<ICellOutputProps> {
transformedList.forEach((transformed, index) => {
let mimetype = transformed.output.mimeType;

// If that worked, use the transform
if (mimetype && isMimeTypeSupported(mimetype)) {
if (isIPyWidgetOutput(transformed.output.mimeBundle)) {
return;
} else if (mimetype && isMimeTypeSupported(mimetype)) {
// If that worked, use the transform
// Get the matching React.Component for that mimetype
const Transform = getTransform(mimetype);

Expand Down
10 changes: 9 additions & 1 deletion src/datascience-ui/interactive-common/transforms.tsx
Expand Up @@ -152,7 +152,15 @@ export async function forceLoad() {
await Promise.all(mimeTypeToImport.map(m => m.getComponent()));
}

export function isMimeTypeSupported(mimeType: string): Boolean {
export function isMimeTypeSupported(mimeType: string): boolean {
const match = mimeTypeToImport.find(m => m.mimeType === mimeType);
return match ? true : false;
}

export function isIPyWidgetOutput(data: {}): boolean {
return (
data &&
(data as Object).hasOwnProperty &&
(data as Object).hasOwnProperty('application/vnd.jupyter.widget-view+json')
);
}

0 comments on commit 3c6f009

Please sign in to comment.