You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ru...@apache.org on 2024/03/22 18:51:06 UTC
(superset) branch master updated: refactor: Migrate CopyToClipboard to typescript (#27309)
This is an automated email from the ASF dual-hosted git repository.
rusackas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new 3f073dcd98 refactor: Migrate CopyToClipboard to typescript (#27309)
3f073dcd98 is described below
commit 3f073dcd98290b1c2022d758ac0ed482b8658cab
Author: Enzo Martellucci <52...@users.noreply.github.com>
AuthorDate: Fri Mar 22 19:51:00 2024 +0100
refactor: Migrate CopyToClipboard to typescript (#27309)
---
.../CopyToClipboard/{index.jsx => index.tsx} | 54 ++++++++++------------
1 file changed, 25 insertions(+), 29 deletions(-)
diff --git a/superset-frontend/src/components/CopyToClipboard/index.jsx b/superset-frontend/src/components/CopyToClipboard/index.tsx
similarity index 74%
rename from superset-frontend/src/components/CopyToClipboard/index.jsx
rename to superset-frontend/src/components/CopyToClipboard/index.tsx
index d4f74904db..6cdc5c084a 100644
--- a/superset-frontend/src/components/CopyToClipboard/index.jsx
+++ b/superset-frontend/src/components/CopyToClipboard/index.tsx
@@ -17,26 +17,25 @@
* under the License.
*/
import React from 'react';
-import PropTypes from 'prop-types';
import { t } from '@superset-ui/core';
import { Tooltip } from 'src/components/Tooltip';
import withToasts from 'src/components/MessageToasts/withToasts';
import copyTextToClipboard from 'src/utils/copy';
-const propTypes = {
- copyNode: PropTypes.node,
- getText: PropTypes.func,
- onCopyEnd: PropTypes.func,
- shouldShowText: PropTypes.bool,
- text: PropTypes.string,
- wrapped: PropTypes.bool,
- tooltipText: PropTypes.string,
- addDangerToast: PropTypes.func.isRequired,
- addSuccessToast: PropTypes.func.isRequired,
- hideTooltip: PropTypes.bool,
-};
+export interface CopyToClipboardProps {
+ copyNode?: React.ReactNode;
+ getText?: (callback: (data: string) => void) => void;
+ onCopyEnd?: () => void;
+ shouldShowText?: boolean;
+ text?: string;
+ wrapped?: boolean;
+ tooltipText?: string;
+ addDangerToast: (msg: string) => void;
+ addSuccessToast: (msg: string) => void;
+ hideTooltip?: boolean;
+}
-const defaultProps = {
+const defaultProps: Partial<CopyToClipboardProps> = {
copyNode: <span>{t('Copy')}</span>,
onCopyEnd: () => {},
shouldShowText: true,
@@ -45,33 +44,33 @@ const defaultProps = {
hideTooltip: false,
};
-class CopyToClipboard extends React.Component {
- constructor(props) {
- super(props);
+class CopyToClipboard extends React.Component<CopyToClipboardProps> {
+ static defaultProps = defaultProps;
- // bindings
+ constructor(props: CopyToClipboardProps) {
+ super(props);
this.copyToClipboard = this.copyToClipboard.bind(this);
this.onClick = this.onClick.bind(this);
}
onClick() {
if (this.props.getText) {
- this.props.getText(d => {
+ this.props.getText((d: string) => {
this.copyToClipboard(Promise.resolve(d));
});
} else {
- this.copyToClipboard(Promise.resolve(this.props.text));
+ this.copyToClipboard(Promise.resolve(this.props.text || ''));
}
}
getDecoratedCopyNode() {
- return React.cloneElement(this.props.copyNode, {
+ return React.cloneElement(this.props.copyNode as React.ReactElement, {
style: { cursor: 'pointer' },
onClick: this.onClick,
});
}
- copyToClipboard(textToCopy) {
+ copyToClipboard(textToCopy: Promise<string>) {
copyTextToClipboard(() => textToCopy)
.then(() => {
this.props.addSuccessToast(t('Copied to clipboard!'));
@@ -84,11 +83,11 @@ class CopyToClipboard extends React.Component {
);
})
.finally(() => {
- this.props.onCopyEnd();
+ if (this.props.onCopyEnd) this.props.onCopyEnd();
});
}
- renderTooltip(cursor) {
+ renderTooltip(cursor: string) {
return (
<>
{!this.props.hideTooltip ? (
@@ -96,7 +95,7 @@ class CopyToClipboard extends React.Component {
id="copy-to-clipboard-tooltip"
placement="topRight"
style={{ cursor }}
- title={this.props.tooltipText}
+ title={this.props.tooltipText || ''}
trigger={['hover']}
arrowPointAtCenter
>
@@ -121,7 +120,7 @@ class CopyToClipboard extends React.Component {
{this.props.text}
</span>
)}
- {this.renderTooltip()}
+ {this.renderTooltip('pointer')}
</span>
);
}
@@ -136,6 +135,3 @@ class CopyToClipboard extends React.Component {
}
export default withToasts(CopyToClipboard);
-
-CopyToClipboard.propTypes = propTypes;
-CopyToClipboard.defaultProps = defaultProps;