williaster commented on a change in pull request #5398: Re-add dashboard short 
links
URL: 
https://github.com/apache/incubator-superset/pull/5398#discussion_r207462531
 
 

 ##########
 File path: superset/assets/src/components/URLShortLinkModal.jsx
 ##########
 @@ -0,0 +1,77 @@
+import React from 'react';
+import PropTypes from 'prop-types';
+import CopyToClipboard from './CopyToClipboard';
+import { getShortUrl } from '../utils/common';
+import { t } from '../locales';
+import withToasts from '../messageToasts/enhancers/withToasts';
+import ModalTrigger from './ModalTrigger';
+
+const propTypes = {
+  url: PropTypes.string,
+  emailSubject: PropTypes.string,
+  emailContent: PropTypes.string,
+  addDangerToast: PropTypes.func.isRequired,
+  isMenuItem: PropTypes.bool,
+  triggerNode: PropTypes.node.isRequired,
+};
+
+class URLShortLinkModal extends React.Component {
+  constructor(props) {
+    super(props);
+    this.state = {
+      shortUrl: '',
+    };
+    this.modal = null;
+    this.setModalRef = this.setModalRef.bind(this);
+    this.onShortUrlSuccess = this.onShortUrlSuccess.bind(this);
+  }
+
+  onShortUrlSuccess(data) {
+    this.setState({
+      shortUrl: data,
+    });
+  }
+
+  setModalRef(ref) {
+    this.modal = ref;
+  }
+
+  getCopyUrl() {
+    getShortUrl(this.props.url, this.onShortUrlSuccess, 
this.props.addDangerToast);
+  }
+
+  render() {
+    const emailBody = t('%s%s', this.props.emailContent, this.state.shortUrl);
+    return (
+      <ModalTrigger
+        ref={this.setModalRef}
+        isMenuItem={this.props.isMenuItem}
+        triggerNode={this.props.triggerNode}
+        beforeOpen={this.getCopyUrl.bind(this)}
 
 Review comment:
   I would bind this in the constructor, otherwise it's a new function per 
render. not a huge deal since this isn't rendered a lot, but we'll have a lint 
rule soon to enforce.

----------------------------------------------------------------
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