Skip to content

Hide raw text if output is an ipywidget #10620

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
8 changes: 5 additions & 3 deletions src/datascience-ui/interactive-common/cellOutput.tsx
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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')
);
}