import React from 'react'; import PropTypes from 'prop-types'; import { ButtonGroup } from 'react-bootstrap'; import Button from '../../components/Button'; import CssEditor from './CssEditor'; import RefreshIntervalModal from './RefreshIntervalModal'; import SaveModal from './SaveModal'; import CodeModal from './CodeModal'; import SliceAdder from './SliceAdder'; const $ = window.$ = require('jquery'); const propTypes = { dashboard: PropTypes.object.isRequired, }; class Controls extends React.PureComponent { constructor(props) { super(props); this.state = { css: props.dashboard.css || '', cssTemplates: [], }; } componentWillMount() { $.get('/csstemplateasyncmodelview/api/read', (data) => { const cssTemplates = data.result.map(row => ({ value: row.template_name, css: row.css, label: row.template_name, })); this.setState({ cssTemplates }); }); } refresh() { this.props.dashboard.sliceObjects.forEach((slice) => { slice.render(true); }); } changeCss(css) { this.setState({ css }); this.props.dashboard.onChange(); } render() { const dashboard = this.props.dashboard; const emailBody = `Checkout this dashboard: ${window.location.href}`; const emailLink = 'mailto:?Subject=Superset%20Dashboard%20' + `${dashboard.dashboard_title}&Body=${emailBody}`; return ( } /> dashboard.startPeriodicRender(refreshInterval * 1000)} triggerNode={ } /> } /> } initialCss={dashboard.css} templates={this.state.cssTemplates} onChange={this.changeCss.bind(this)} /> } /> ); } } Controls.propTypes = propTypes; export default Controls;