-
Notifications
You must be signed in to change notification settings - Fork 14.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: Transform URLShortLinkModal to Typescript #11971
Merged
etr2460
merged 2 commits into
apache:master
from
maloun96:hotfix/url-short-link-modal-typescript
Dec 15, 2020
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: '', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we default this to empty string, can we make the props type themselves non-undefined? Or maybe get rid of the empty string default val There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changed! |
||
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); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason for
JSX.Element
and notReact.ReactNode
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what are the differences? I checked and it's not clear
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ReactNode includes JSX.Element (an alias of ReactElement<any, any>), as well as string, null, undefined and node arrays.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case it’s probably better to use JSX.Element since you’d want the trigger element to always exist and not be a text node.