/** * External dependencies */ import { HotTable } from '@handsontable/react'; import 'handsontable/dist/handsontable.full.css'; /** * WordPress dependencies */ const { __ } = wp.i18n; const { Component } = wp.element; const { Button, ButtonGroup } = wp.components; class ChartEditor extends Component { constructor() { super( ...arguments ); this.data = []; this.dates = []; this.types = [ 'string', 'number', 'boolean', 'date', 'datetime', 'timeofday' ]; } componentWillMount() { this.data[this.data.length] = []; this.data[this.data.length] = []; this.props.chart['visualizer-series'].map( ( i, index ) => { this.data[0][ index ] = i.label; this.data[1][ index ] = i.type; if ( 'date' === i.type ) { this.dates.push( index ); } }); this.props.chart['visualizer-data'].map( ( i ) => { this.data[this.data.length] = i; }); } render() { return (
{ let cellProperties; if ( 1 === row ) { cellProperties = { type: 'autocomplete', source: this.types, strict: false }; } if ( 0 <= ( this.dates ).indexOf( col ) && 1 < row ) { cellProperties = { type: 'date', dateFormat: 'YYYY-MM-DD', correctFormat: true }; } return cellProperties; } } />
); } } export default ChartEditor;