| 1 |
/** |
| 2 |
* External dependencies |
| 3 |
*/ |
| 4 |
import JSONInput from 'react-json-editor-ajrm'; |
| 5 |
|
| 6 |
import locale from 'react-json-editor-ajrm/locale/en'; |
| 7 |
|
| 8 |
import { isValidJSON } from '../../utils.js'; |
| 9 |
|
| 10 |
/** |
| 11 |
* WordPress dependencies |
| 12 |
*/ |
| 13 |
const { __ } = wp.i18n; |
| 14 |
|
| 15 |
const { Component } = wp.element; |
| 16 |
|
| 17 |
const { |
| 18 |
ExternalLink, |
| 19 |
PanelBody |
| 20 |
} = wp.components; |
| 21 |
|
| 22 |
class ManualConfiguration extends Component { |
| 23 |
constructor() { |
| 24 |
super( ...arguments ); |
| 25 |
|
| 26 |
this.isValidJSON = this.isValidJSON.bind( this ); |
| 27 |
} |
| 28 |
|
| 29 |
isValidJSON( obj ) { |
| 30 |
try { |
| 31 |
JSON.parse( obj ); |
| 32 |
} catch ( e ) { |
| 33 |
return false; |
| 34 |
} |
| 35 |
return true; |
| 36 |
} |
| 37 |
|
| 38 |
render() { |
| 39 |
|
| 40 |
let chart; |
| 41 |
|
| 42 |
const settings = this.props.chart['visualizer-settings']; |
| 43 |
|
| 44 |
if ( 0 <= [ 'gauge', 'tabular', 'timeline' ].indexOf( this.props.chart['visualizer-chart-type']) ) { |
| 45 |
chart = this.props.chart['visualizer-chart-type']; |
| 46 |
} else { |
| 47 |
chart = `${ this.props.chart['visualizer-chart-type'] }chart`; |
| 48 |
} |
| 49 |
|
| 50 |
return ( |
| 51 |
<PanelBody |
| 52 |
title={ __( 'Manual Configuration' ) } |
| 53 |
initialOpen={ false } |
| 54 |
className="visualizer-advanced-panel" |
| 55 |
> |
| 56 |
|
| 57 |
<p>{ __( 'Configure the graph by providing configuration variables right from the Google Visualization API.' ) }</p> |
| 58 |
|
| 59 |
<p> |
| 60 |
<ExternalLink href={ `https://developers.google.com/chart/interactive/docs/gallery/${chart}#configuration-options` }> |
| 61 |
{ __( 'Google Visualization API' ) } |
| 62 |
</ExternalLink> |
| 63 |
</p> |
| 64 |
|
| 65 |
<JSONInput |
| 66 |
locale={ locale } |
| 67 |
theme="light_mitsuketa_tribute" |
| 68 |
placeholder={ |
| 69 |
isValidJSON( settings.manual ) ? |
| 70 |
JSON.parse( settings.manual ) : |
| 71 |
{} |
| 72 |
} |
| 73 |
width="100%" |
| 74 |
height="250px" |
| 75 |
style={ { |
| 76 |
errorMessage: { |
| 77 |
height: '100%', |
| 78 |
fontSize: '10px' |
| 79 |
}, |
| 80 |
container: { |
| 81 |
border: '1px solid #ddd', |
| 82 |
boxShadow: 'inset 0 1px 2px rgba(0,0,0,.07)' |
| 83 |
}, |
| 84 |
labelColumn: { |
| 85 |
background: '#F5F5F5', |
| 86 |
width: 'auto', |
| 87 |
padding: '5px 10px 5px 10px' |
| 88 |
} |
| 89 |
} } |
| 90 |
onChange={ e => { |
| 91 |
if ( false === e.error ) { |
| 92 |
settings.manual = e.json; |
| 93 |
this.props.edit( settings ); |
| 94 |
} |
| 95 |
} } |
| 96 |
/> |
| 97 |
|
| 98 |
|
| 99 |
</PanelBody> |
| 100 |
); |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
export default ManualConfiguration; |
| 105 |
|