betodealmeida commented on a change in pull request #5186: Implement a 
React-based table editor
URL: 
https://github.com/apache/incubator-superset/pull/5186#discussion_r206948043
 
 

 ##########
 File path: superset/assets/src/datasource/DatasourceModal.jsx
 ##########
 @@ -0,0 +1,162 @@
+import React from 'react';
+import PropTypes from 'prop-types';
+import { Alert, Button, Modal } from 'react-bootstrap';
+import Dialog from 'react-bootstrap-dialog';
+
+import { t } from '../locales';
+import DatasourceEditor from '../datasource/DatasourceEditor';
+import withToasts from '../messageToasts/enhancers/withToasts';
+
+const $ = window.$ = require('jquery');
+
+const propTypes = {
+  onChange: PropTypes.func,
+  datasource: PropTypes.object,
+  show: PropTypes.bool.isRequired,
+  onHide: PropTypes.func,
+  onDatasourceSave: PropTypes.func,
+  addSuccessToast: PropTypes.func.isRequired,
+};
+
+const defaultProps = {
+  onChange: () => {},
+  onHide: () => {},
+  onDatasourceSave: () => {},
+};
+
+class DatasourceModal extends React.PureComponent {
+  constructor(props) {
+    super(props);
+    this.state = {
+      showEditDatasource: false,
+      filter: '',
+      loading: true,
+      errors: [],
+      showDatasource: false,
+      datasource: props.datasource,
+    };
+    this.toggleShowDatasource = this.toggleShowDatasource.bind(this);
+    this.changeSearch = this.changeSearch.bind(this);
+    this.setSearchRef = this.setSearchRef.bind(this);
+    this.onDatasourceChange = this.onDatasourceChange.bind(this);
+    this.onClickSave = this.onClickSave.bind(this);
+    this.onConfirmSave = this.onConfirmSave.bind(this);
+  }
+  onClickSave() {
+    this.dialog.show({
+      title: 'Confirm save',
+      bsSize: 'medium',
+      actions: [
+        Dialog.CancelAction(),
+        Dialog.OKAction(this.onConfirmSave),
+      ],
+      body: this.renderSaveDialog(),
+    });
+  }
+  onConfirmSave() {
+    const url = '/datasource/save/';
+    const that = this;
+    $.ajax({
+      url,
+      type: 'POST',
+      data: {
+        data: JSON.stringify(this.state.datasource),
+      },
+      success: (data) => {
+        this.props.addSuccessToast(t('The datasource has been saved'));
+        this.props.onDatasourceSave(data);
+        this.props.onHide();
+      },
+      error(err) {
+        let msg = t('An error has occurred');
+        if (err.responseJSON && err.responseJSON.error) {
+          msg = err.responseJSON.error;
+        }
+        that.dialog.show({
+          title: 'Error',
+          bsSize: 'medium',
+          bsStyle: 'danger',
+          actions: [
+            Dialog.DefaultAction('Ok', () => {}, 'btn-danger'),
+          ],
+          body: msg,
+        });
+      },
+    });
+  }
+  onDatasourceChange(datasource, errors) {
+    this.setState({ datasource, errors });
+  }
+  setSearchRef(searchRef) {
+    this.searchRef = searchRef;
+  }
+  toggleShowDatasource() {
+    this.setState({ showDatasource: !this.state.showDatasource });
+  }
+  changeSearch(event) {
+    this.setState({ filter: event.target.value });
+  }
+  renderSaveDialog() {
+    return (
+      <div>
+        <Alert bsStyle="warning" className="pointer" onClick={this.hideAlert}>
+          <div>
+            <i className="fa fa-exclamation-triangle" />{' '}
+            {t('The data source configuration exposed here ')}
+            <strong>{t('affects all the charts using this datasource. ')} 
</strong>
 
 Review comment:
   Nit: for translation it's **way better** to keep the phrase together. 
Unfortunately there doesn't seem to be a good way of doing it here because of 
the `<strong>` tag. The alternatives seem to be using (1) Markdown or (2) 
allowing unsafe HTML in translation strings.
   
   Also nit, remove the space after `}`.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to