mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 09:22:43 +03:00
console: migrate ErrorBoundary to TS (#4542)
This commit is contained in:
parent
a2a492e5d9
commit
61349c091a
@ -1,5 +1,4 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import {
|
||||
loadInconsistentObjects,
|
||||
redirectToMetadataStatus,
|
||||
@ -11,25 +10,40 @@ import PageNotFound, { NotFoundError } from './PageNotFound';
|
||||
import RuntimeError from './RuntimeError';
|
||||
import { registerRunTimeError } from '../Main/Actions';
|
||||
|
||||
class ErrorBoundary extends React.Component {
|
||||
initialState = {
|
||||
hasError: false,
|
||||
info: null,
|
||||
error: null,
|
||||
type: '500',
|
||||
};
|
||||
export interface Metadata {
|
||||
inconsistentObjects: object[];
|
||||
ongoingRequest: boolean;
|
||||
allowedQueries: object[];
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
export interface ErrorBoundaryProps {
|
||||
metadata: Metadata;
|
||||
dispatch: (arg: unknown) => Promise<unknown>; // TODO update when Redux is migrated to TS;
|
||||
}
|
||||
|
||||
interface ErrorBoundaryState {
|
||||
hasError: boolean;
|
||||
error: Error | null;
|
||||
type: string;
|
||||
}
|
||||
|
||||
const initialState: ErrorBoundaryState = {
|
||||
hasError: false,
|
||||
error: null,
|
||||
type: '500',
|
||||
};
|
||||
|
||||
class ErrorBoundary extends React.Component<
|
||||
ErrorBoundaryProps,
|
||||
ErrorBoundaryState
|
||||
> {
|
||||
constructor(props: ErrorBoundaryProps) {
|
||||
super(props);
|
||||
|
||||
this.state = this.initialState;
|
||||
this.state = initialState;
|
||||
}
|
||||
|
||||
resetState = () => {
|
||||
this.setState({ ...this.initialState });
|
||||
};
|
||||
|
||||
componentDidCatch(error, info) {
|
||||
componentDidCatch(error: Error) {
|
||||
const { dispatch } = this.props;
|
||||
|
||||
// for invalid path segment errors
|
||||
@ -39,7 +53,7 @@ class ErrorBoundary extends React.Component {
|
||||
});
|
||||
}
|
||||
|
||||
this.setState({ hasError: true, info: info, error: error });
|
||||
this.setState({ hasError: true, error });
|
||||
|
||||
// trigger telemetry
|
||||
dispatch(
|
||||
@ -60,16 +74,16 @@ class ErrorBoundary extends React.Component {
|
||||
);
|
||||
}
|
||||
|
||||
resetState = () => {
|
||||
this.setState(initialState);
|
||||
};
|
||||
|
||||
render() {
|
||||
const { metadata } = this.props;
|
||||
const { hasError, type, error } = this.state;
|
||||
|
||||
if (hasError && metadata.ongoingRequest) {
|
||||
return (
|
||||
<div>
|
||||
<Spinner />
|
||||
</div>
|
||||
);
|
||||
return <Spinner />;
|
||||
}
|
||||
|
||||
if (hasError) {
|
||||
@ -84,8 +98,4 @@ class ErrorBoundary extends React.Component {
|
||||
}
|
||||
}
|
||||
|
||||
ErrorBoundary.propTypes = {
|
||||
children: PropTypes.element,
|
||||
};
|
||||
|
||||
export default ErrorBoundary;
|
Loading…
Reference in New Issue
Block a user