Skip to content

Commit 3c6f009

Browse files
authored
Hide raw text if output is an ipywidget (#10620)
1 parent 6141edb commit 3c6f009

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/datascience-ui/interactive-common/cellOutput.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { ImageButton } from '../react-common/imageButton';
1616
import { getLocString } from '../react-common/locReactSide';
1717
import { fixLatexEquations } from './latexManipulation';
1818
import { ICellViewModel } from './mainState';
19-
import { getRichestMimetype, getTransform, isMimeTypeSupported } from './transforms';
19+
import { getRichestMimetype, getTransform, isIPyWidgetOutput, isMimeTypeSupported } from './transforms';
2020

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

507-
// If that worked, use the transform
508-
if (mimetype && isMimeTypeSupported(mimetype)) {
507+
if (isIPyWidgetOutput(transformed.output.mimeBundle)) {
508+
return;
509+
} else if (mimetype && isMimeTypeSupported(mimetype)) {
510+
// If that worked, use the transform
509511
// Get the matching React.Component for that mimetype
510512
const Transform = getTransform(mimetype);
511513

src/datascience-ui/interactive-common/transforms.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,15 @@ export async function forceLoad() {
152152
await Promise.all(mimeTypeToImport.map(m => m.getComponent()));
153153
}
154154

155-
export function isMimeTypeSupported(mimeType: string): Boolean {
155+
export function isMimeTypeSupported(mimeType: string): boolean {
156156
const match = mimeTypeToImport.find(m => m.mimeType === mimeType);
157157
return match ? true : false;
158158
}
159+
160+
export function isIPyWidgetOutput(data: {}): boolean {
161+
return (
162+
data &&
163+
(data as Object).hasOwnProperty &&
164+
(data as Object).hasOwnProperty('application/vnd.jupyter.widget-view+json')
165+
);
166+
}

0 commit comments

Comments
 (0)