import React from 'react' ; import { render , unmountComponentAtNode } from 'react-dom' ; import { VisualizationController } from '../types' ; import { getI18n , getUISettings } from '../services' ; import { ExprVis } from '../expressions/vis' ; export class ReactVisController implements VisualizationController { constructor ( private element , private vis ) { } public render ( visData , visParams ) { const I18nContext = getI18n ( ) . Context ; return new Promise ( ( resolve , reject ) => { if ( ! this . vis . type || ! this . vis . type . visConfig || ! this . vis . type . visConfig . component ) { reject ( 'Missing component for ReactVisType' ) ; } const Component = this . vis . type . visConfig . component ; const config = getUISettings ( ) ; render ( < I18nContext > < Component config = { config } vis = { this . vis } visData = { visData } visParams = { visParams } renderComplete = { resolve } / > < /I18nContext>, this.element); } ) ; } public destroy ( ) { unmountComponentAtNode ( this . element ) ; } }