import { markdown } from 'markdown'; import { debounce } from 'lodash'; import React from 'react'; import PropTypes from 'prop-types'; import { react2angular } from 'react2angular'; import { toastr } from '@/services/ng'; import { Widget } from '@/services/widget'; class AddTextboxDialog extends React.Component { static propTypes = { dashboard: PropTypes.object, // eslint-disable-line react/forbid-prop-types close: PropTypes.func, dismiss: PropTypes.func, }; static defaultProps = { dashboard: null, close: () => {}, dismiss: () => {}, }; constructor(props) { super(props); this.state = { saveInProgress: false, text: '', preview: '', }; const updatePreview = debounce(() => { const text = this.state.text; this.setState({ preview: markdown.toHTML(text), }); }, 100); this.onTextChanged = (event) => { this.setState({ text: event.target.value }); updatePreview(); }; } saveWidget() { const dashboard = this.props.dashboard; this.setState({ saveInProgress: true }); const widget = new Widget({ visualization_id: null, dashboard_id: dashboard.id, options: { isHidden: false, position: {}, }, visualization: null, text: this.state.text, }); const position = dashboard.calculateNewWidgetPosition(widget); widget.options.position.col = position.col; widget.options.position.row = position.row; widget .save() .then(() => { dashboard.widgets.push(widget); this.props.close(); }) .catch(() => { toastr.error('Widget can not be added'); }) .finally(() => { this.setState({ saveInProgress: false }); }); } render() { return (

Add Textbox