-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
convert ra-ui-materialui layout to typescript #4875
Changes from all commits
bcf850e
11ac651
cf8e9e6
fab3749
4e2532f
e244a9c
726c377
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import React, { Fragment } from 'react'; | ||
import React, { Fragment, FC, ErrorInfo } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import classnames from 'classnames'; | ||
import Button from '@material-ui/core/Button'; | ||
|
@@ -10,7 +10,7 @@ import ErrorIcon from '@material-ui/icons/Report'; | |
import ExpandMoreIcon from '@material-ui/icons/ExpandMore'; | ||
import History from '@material-ui/icons/History'; | ||
|
||
import Title, { TitlePropType } from './Title'; | ||
import Title, { TitlePropType, TitleProps } from './Title'; | ||
import { useTranslate } from 'ra-core'; | ||
|
||
const useStyles = makeStyles( | ||
|
@@ -52,7 +52,7 @@ function goBack() { | |
window.history.go(-1); | ||
} | ||
|
||
const Error = props => { | ||
const Error: FC<ErrorProps> = props => { | ||
const { | ||
error, | ||
errorInfo, | ||
|
@@ -88,8 +88,8 @@ const Error = props => { | |
<div className={classes.toolbar}> | ||
<Button | ||
variant="contained" | ||
icon={<History />} | ||
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. I think |
||
onClick={goBack} | ||
startIcon={<History />} | ||
> | ||
{translate('ra.action.back')} | ||
</Button> | ||
|
@@ -99,11 +99,19 @@ const Error = props => { | |
); | ||
}; | ||
|
||
export interface ErrorProps { | ||
className?: string; | ||
error: Error; | ||
errorInfo: ErrorInfo; | ||
title: TitleProps['defaultTitle']; | ||
classes?: object; | ||
} | ||
|
||
Error.propTypes = { | ||
classes: PropTypes.object, | ||
className: PropTypes.string, | ||
error: PropTypes.object.isRequired, | ||
errorInfo: PropTypes.object, | ||
error: PropTypes.any.isRequired, | ||
errorInfo: PropTypes.any, | ||
title: TitlePropType, | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { Component, ComponentType, createElement, ErrorInfo } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { ComponentPropType, TitleComponent } from 'ra-core'; | ||
import { withRouter, RouteComponentProps } from 'react-router'; | ||
|
||
import { ErrorProps } from './Error'; | ||
|
||
class _ErrorBoundary extends Component< | ||
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. We don't use the |
||
ErrorBoundaryProps & RouteComponentProps, | ||
ErrorBoundaryState | ||
> { | ||
static propTypes = { | ||
children: PropTypes.oneOfType([PropTypes.func, PropTypes.node]), | ||
error: ComponentPropType, | ||
title: PropTypes.element.isRequired, | ||
}; | ||
|
||
state = { hasError: false, errorMessage: null, errorInfo: null }; | ||
|
||
constructor(props) { | ||
super(props); | ||
/** | ||
* Reset the error state upon navigation | ||
* | ||
* @see https://stackoverflow.com/questions/48121750/browser-navigation-broken-by-use-of-react-error-boundaries | ||
*/ | ||
props.history.listen(() => { | ||
if (this.state.hasError) { | ||
this.setState({ hasError: false }); | ||
} | ||
}); | ||
} | ||
|
||
componentDidCatch(errorMessage, errorInfo) { | ||
this.setState({ hasError: true, errorMessage, errorInfo }); | ||
} | ||
|
||
render() { | ||
const { hasError, errorMessage, errorInfo } = this.state; | ||
const { children, error, title } = this.props; | ||
|
||
return hasError | ||
? createElement(error, { | ||
error: errorMessage, | ||
errorInfo, | ||
title, | ||
}) | ||
: children; | ||
} | ||
} | ||
|
||
export const ErrorBoundary = withRouter(_ErrorBoundary); | ||
|
||
export interface ErrorBoundaryProps { | ||
error: ComponentType<ErrorProps>; | ||
title?: TitleComponent; | ||
} | ||
|
||
interface ErrorBoundaryState { | ||
hasError?: boolean; | ||
errorMessage: Error | null; | ||
errorInfo: ErrorInfo | null; | ||
} |
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.
Why did you remove this one?
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.
I didn't mean to push that with this PR but I checked everywhere there is no use for variant
title