import * as React from 'react' ; import { richestMimetype , transforms } from 'transformime-react' ; import JSONTree from 'react-json-tree' ; const Immutable = require ( 'immutable' ) ; interface ResultListProps { result : NotebookOutput ; } interface ResultListState { } class ResultList extends React . Component < ResultListProps , ResultListState > { render ( ) { let data = this . props . result . value ; if ( data === 'ok' ) { return < div />; } if ( data && data [ 'application/json' ] ) { return < JSONTree data = { data [ 'application/json' ] } />; } const bundle = new Immutable . Map ( data ) ; const mimetype = richestMimetype ( bundle ) ; let Transform = transforms . get ( mimetype ) ; if ( typeof mimetype !== 'string' ) { return < div > Unknown Mime Type < /div>; } let style = { } ; if ( mimetype . startsWith ( 'image' ) ) { style [ 'backgroundColor' ] = 'white' ; } if ( mimetype === 'text/plain' ) { style [ 'white-space' ] = 'pre' ; } try { return < div style = { style } > < Transform data = { bundle . get ( mimetype ) } /></div > ; } catch ( ex ) { console . log ( 'Error in rendering' ) ; console . log ( ex ) ; return < div > < /div>; } } } export default ResultList ;