-
Notifications
You must be signed in to change notification settings - Fork 14.6k
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
Wrap <LoadableRenderer /> with <ErrorBoundary /> #6294
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { t } from '@superset-ui/translation'; | ||
import StackTraceMessage from './StackTraceMessage'; | ||
|
||
const propTypes = { | ||
children: PropTypes.node.isRequired, | ||
onError: PropTypes.func, | ||
showMessage: PropTypes.boolean, | ||
}; | ||
const defaultProps = { | ||
onError: () => {}, | ||
showMessage: true, | ||
}; | ||
|
||
export default class ErrorBoundary extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { error: null, info: null }; | ||
} | ||
|
||
componentDidCatch(error, info) { | ||
this.props.onError(error, info); | ||
this.setState({ hasError: true, error, info }); | ||
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. Is |
||
} | ||
|
||
render() { | ||
const { error, info } = this.state; | ||
if (error) { | ||
const firstLine = error ? error.toString() : null; | ||
const message = ( | ||
<span> | ||
<strong>{t('Unexpected error')}</strong>{firstLine ? `: ${firstLine}` : ''} | ||
</span>); | ||
if (this.props.showMessage) { | ||
return ( | ||
<StackTraceMessage message={message} stacktrace={info ? info.componentStack : null} />); | ||
} | ||
return null; | ||
} | ||
return this.props.children; | ||
} | ||
} | ||
ErrorBoundary.propTypes = propTypes; | ||
ErrorBoundary.defaultProps = defaultProps; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,15 @@ import PropTypes from 'prop-types'; | |
import { Alert, Collapse } from 'react-bootstrap'; | ||
|
||
const propTypes = { | ||
message: PropTypes.string, | ||
queryResponse: PropTypes.object, | ||
message: PropTypes.node.isRequired, | ||
link: PropTypes.string, | ||
stacktrace: PropTypes.string, | ||
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. camelcase |
||
showStackTrace: PropTypes.bool, | ||
}; | ||
const defaultProps = { | ||
showStackTrace: false, | ||
link: null, | ||
stacktrace: null, | ||
}; | ||
|
||
class StackTraceMessage extends React.PureComponent { | ||
|
@@ -21,36 +24,28 @@ class StackTraceMessage extends React.PureComponent { | |
}; | ||
} | ||
|
||
hasTrace() { | ||
return this.props.queryResponse && this.props.queryResponse.stacktrace; | ||
} | ||
|
||
hasLink() { | ||
return this.props.queryResponse && this.props.queryResponse.link; | ||
} | ||
|
||
render() { | ||
return ( | ||
<div className={`stack-trace-container${this.hasTrace() ? ' has-trace' : ''}`}> | ||
<div className={`stack-trace-container${this.props.stacktrace ? ' has-trace' : ''}`}> | ||
<Alert | ||
bsStyle="warning" | ||
onClick={() => this.setState({ showStackTrace: !this.state.showStackTrace })} | ||
> | ||
{this.props.message} | ||
{this.hasLink() && | ||
{this.props.link && | ||
<a | ||
href={this.props.queryResponse.link} | ||
href={this.props.link} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
(Request Access) | ||
</a> | ||
} | ||
</Alert> | ||
{this.hasTrace() && | ||
{this.props.stacktrace && | ||
<Collapse in={this.state.showStackTrace}> | ||
<pre> | ||
{this.props.queryResponse.stacktrace} | ||
{this.props.stacktrace} | ||
</pre> | ||
</Collapse> | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
export default function transformProps(chartProps) { | ||
const { height, datasource, formData, payload } = chartProps; | ||
const columnCollection = formData.columnCollection || []; | ||
const { | ||
columnCollection, | ||
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. Can do |
||
groupby, | ||
metrics, | ||
url, | ||
|
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.
PropTypes.bool