From 34da15fd6a67cac25fa5c8907297bce12a0a4db0 Mon Sep 17 00:00:00 2001 From: Ran Byron Date: Mon, 4 Mar 2019 21:51:48 +0200 Subject: [PATCH] Migrated AddTextboxDialog to AntD (#3524) --- .../dashboards/AddTextboxDialog.jsx | 195 +++++++----------- .../dashboards/AddTextboxDialog.less | 18 ++ .../components/dashboards/AddWidgetDialog.jsx | 2 +- client/app/pages/dashboards/dashboard.js | 45 ++-- 4 files changed, 123 insertions(+), 137 deletions(-) create mode 100644 client/app/components/dashboards/AddTextboxDialog.less diff --git a/client/app/components/dashboards/AddTextboxDialog.jsx b/client/app/components/dashboards/AddTextboxDialog.jsx index 4a92c0793f..c7424293c1 100644 --- a/client/app/components/dashboards/AddTextboxDialog.jsx +++ b/client/app/components/dashboards/AddTextboxDialog.jsx @@ -2,72 +2,49 @@ import { markdown } from 'markdown'; import { debounce } from 'lodash'; import React from 'react'; import PropTypes from 'prop-types'; -import { react2angular } from 'react2angular'; +import Modal from 'antd/lib/modal'; +import Input from 'antd/lib/input'; +import Tooltip from 'antd/lib/tooltip'; +import Divider from 'antd/lib/divider'; +import { wrap as wrapDialog, DialogPropType } from '@/components/DialogWrapper'; import { toastr } from '@/services/ng'; -import { Widget } from '@/services/widget'; + +import './AddTextboxDialog.less'; 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: () => {}, + dashboard: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types + dialog: DialogPropType.isRequired, + onConfirm: PropTypes.func.isRequired, }; - constructor(props) { - super(props); - this.state = { - saveInProgress: false, - text: '', - preview: '', - }; + state = { + saveInProgress: false, + text: '', + preview: '', + } - const updatePreview = debounce(() => { - const text = this.state.text; - this.setState({ - preview: markdown.toHTML(text), - }); - }, 100); + updatePreview = debounce(() => { + const text = this.state.text; + this.setState({ + preview: markdown.toHTML(text), + }); + }, 100); - this.onTextChanged = (event) => { - this.setState({ text: event.target.value }); - updatePreview(); - }; - } + onTextChanged = (event) => { + this.setState({ text: event.target.value }); + this.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() + this.props.onConfirm(this.state.text) .then(() => { - dashboard.widgets.push(widget); - this.props.close(); + this.props.dialog.close(); }) .catch(() => { - toastr.error('Widget can not be added'); + toastr.error('Widget could not be added'); }) .finally(() => { this.setState({ saveInProgress: false }); @@ -75,81 +52,53 @@ class AddTextboxDialog extends React.Component { } render() { - return ( -
-
- -

Add Textbox

-
-
-
-