From 418d3f30ba49e8bce89cdfc8cd01bafa5ca7a511 Mon Sep 17 00:00:00 2001 From: Victor Malai Date: Wed, 9 Dec 2020 09:32:12 +0200 Subject: [PATCH 1/2] Transform jsx modal to tsx modal --- ...ortLinkModal.jsx => URLShortLinkModal.tsx} | 46 +++++++++++-------- 1 file changed, 26 insertions(+), 20 deletions(-) rename superset-frontend/src/components/{URLShortLinkModal.jsx => URLShortLinkModal.tsx} (78%) diff --git a/superset-frontend/src/components/URLShortLinkModal.jsx b/superset-frontend/src/components/URLShortLinkModal.tsx similarity index 78% rename from superset-frontend/src/components/URLShortLinkModal.jsx rename to superset-frontend/src/components/URLShortLinkModal.tsx index 2b5bbfca8bdd5..ccdff87696336 100644 --- a/superset-frontend/src/components/URLShortLinkModal.jsx +++ b/superset-frontend/src/components/URLShortLinkModal.tsx @@ -17,24 +17,38 @@ * under the License. */ import React from 'react'; -import PropTypes from 'prop-types'; import { t } from '@superset-ui/core'; import CopyToClipboard from './CopyToClipboard'; import { getShortUrl } from '../utils/common'; 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, - title: PropTypes.string, - triggerNode: PropTypes.node.isRequired, +type URLShortLinkModalProps = { + url?: string; + emailSubject?: string; + emailContent?: string; + title?: string; + addDangerToast: (msg: string) => void; + triggerNode: JSX.Element; }; -class URLShortLinkModal extends React.Component { - constructor(props) { +type URLShortLinkModalState = { + shortUrl: string; +}; + +class URLShortLinkModal extends React.Component< + URLShortLinkModalProps, + URLShortLinkModalState +> { + static defaultProps = { + url: window.location.href.substring(window.location.origin.length), + emailSubject: '', + emailContent: '', + }; + + modal: ModalTrigger | null; + + constructor(props: URLShortLinkModalProps) { super(props); this.state = { shortUrl: '', @@ -45,11 +59,11 @@ class URLShortLinkModal extends React.Component { this.getCopyUrl = this.getCopyUrl.bind(this); } - onShortUrlSuccess(shortUrl) { + onShortUrlSuccess(shortUrl: string) { this.setState(() => ({ shortUrl })); } - setModalRef(ref) { + setModalRef(ref: ModalTrigger | null) { this.modal = ref; } @@ -88,12 +102,4 @@ class URLShortLinkModal extends React.Component { } } -URLShortLinkModal.defaultProps = { - url: window.location.href.substring(window.location.origin.length), - emailSubject: '', - emailContent: '', -}; - -URLShortLinkModal.propTypes = propTypes; - export default withToasts(URLShortLinkModal); From 8a1797dbd0e51ec920b7a3c0277de2fe5afcc731 Mon Sep 17 00:00:00 2001 From: maloun96 Date: Fri, 11 Dec 2020 12:28:05 +0200 Subject: [PATCH 2/2] Change required type --- superset-frontend/src/components/URLShortLinkModal.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/superset-frontend/src/components/URLShortLinkModal.tsx b/superset-frontend/src/components/URLShortLinkModal.tsx index ccdff87696336..40e9b4521b817 100644 --- a/superset-frontend/src/components/URLShortLinkModal.tsx +++ b/superset-frontend/src/components/URLShortLinkModal.tsx @@ -24,9 +24,9 @@ import withToasts from '../messageToasts/enhancers/withToasts'; import ModalTrigger from './ModalTrigger'; type URLShortLinkModalProps = { - url?: string; - emailSubject?: string; - emailContent?: string; + url: string; + emailSubject: string; + emailContent: string; title?: string; addDangerToast: (msg: string) => void; triggerNode: JSX.Element;