Skip to content
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

chore: migrate ErrorBoundary component from jsx to tsx #17908

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,35 @@
* under the License.
*/
import React from 'react';
import PropTypes from 'prop-types';
import { t } from '@superset-ui/core';
import ErrorMessageWithStackTrace from 'src/components/ErrorMessage/ErrorMessageWithStackTrace';

const propTypes = {
children: PropTypes.node.isRequired,
onError: PropTypes.func,
showMessage: PropTypes.bool,
};
const defaultProps = {
onError: () => {},
showMessage: true,
};
interface ErrorBoundaryProps {
children: React.ReactNode;
onError?: Function;
showMessage?: boolean;
}

interface ErrorBoundaryState {
error: Error | null;
info: React.ErrorInfo | null;
}

export default class ErrorBoundary extends React.Component<
ErrorBoundaryProps,
ErrorBoundaryState
> {
static defaultProps = {
onError: () => {},
showMessage: true,
};

export default class ErrorBoundary extends React.Component {
constructor(props) {
constructor(props: ErrorBoundaryProps) {
super(props);
this.state = { error: null, info: null };
}

componentDidCatch(error, info) {
componentDidCatch(error: Error, info: React.ErrorInfo) {
if (this.props.onError) this.props.onError(error, info);
this.setState({ error, info });
}
Expand Down Expand Up @@ -66,5 +74,3 @@ export default class ErrorBoundary extends React.Component {
return this.props.children;
}
}
ErrorBoundary.propTypes = propTypes;
ErrorBoundary.defaultProps = defaultProps;
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const LeftSideContent = styled.div`

interface ErrorAlertProps {
body: ReactNode;
copyText?: string;
copyText?: string | JSX.Element;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this change intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the typescript infers const message on line 52 as a JSX.Element.

Screen Shot 2022-01-14 at 8 54 54 PM

Copy link
Contributor Author

@Damans227 Damans227 Jan 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type for copyText becomes invalid if type JSX.Element is not set. Following error gets thrown in the ErrorMessageWithStack Component and the index.tsx file eventually:

(JSX attribute) copyText?: string | undefined
Type 'Element' is not assignable to type 'string'.ts(2322)
ErrorMessageWithStackTrace.tsx(33, 3): The expected type comes from property 'copyText' which is declared here on type 'IntrinsicAttributes & Props' 

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, thanks!

level: ErrorLevel;
source?: ErrorSource;
subtitle: ReactNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ type Props = {
error?: SupersetError;
link?: string;
subtitle?: React.ReactNode;
copyText?: string;
stackTrace?: string;
copyText?: string | JSX.Element;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same question here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same reason as above

stackTrace?: string | null;
source?: ErrorSource;
};

Expand Down