fix head to home console error from error page (#2304)

This commit is contained in:
IMRAN KHAN 2019-05-31 17:57:49 +05:30 committed by Rikin Kachhia
parent 8282e92408
commit 17b5dc0e9c
2 changed files with 22 additions and 4 deletions

View File

@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
import { import {
loadInconsistentObjects, loadInconsistentObjects,
redirectToMetadataStatus, redirectToMetadataStatus,
isMetadataStatusPage,
} from '../Services/Metadata/Actions'; } from '../Services/Metadata/Actions';
import Spinner from '../Common/Spinner/Spinner'; import Spinner from '../Common/Spinner/Spinner';
@ -12,17 +13,25 @@ import Helmet from 'react-helmet';
class ErrorBoundary extends React.Component { class ErrorBoundary extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { hasError: false, info: null, error: null }; this.state = { hasError: false, info: null, error: null };
} }
resetState = () => {
this.setState({ hasError: false, info: null, error: null });
};
componentDidCatch(error, info) { componentDidCatch(error, info) {
this.setState({ hasError: true, info: info, error: error }); this.setState({ hasError: true, info: info, error: error });
// TODO logErrorToMyService(error, info); // TODO logErrorToMyService(error, info);
const { dispatch } = this.props; const { dispatch } = this.props;
dispatch(loadInconsistentObjects(true)).then(() => { dispatch(loadInconsistentObjects(true)).then(() => {
if (this.props.metadata.inconsistentObjects.length > 0) { if (this.props.metadata.inconsistentObjects.length > 0) {
if (!window.location.pathname.includes('/metadata/status')) { if (!isMetadataStatusPage()) {
this.setState({ hasError: false, info: null, error: null }); this.resetState();
this.props.dispatch(redirectToMetadataStatus()); this.props.dispatch(redirectToMetadataStatus());
} }
} else { } else {
@ -35,6 +44,7 @@ class ErrorBoundary extends React.Component {
const errorImage = require('./error-logo.png'); const errorImage = require('./error-logo.png');
const styles = require('./ErrorPage.scss'); const styles = require('./ErrorPage.scss');
const { metadata } = this.props; const { metadata } = this.props;
if (this.state.hasError && metadata.ongoingRequest) { if (this.state.hasError && metadata.ongoingRequest) {
return ( return (
<div> <div>
@ -54,7 +64,11 @@ class ErrorBoundary extends React.Component {
<h1>Error</h1> <h1>Error</h1>
<br /> <br />
<div> <div>
Something went wrong. Head back <Link to="/">Home</Link>. Something went wrong. Head back{' '}
<Link to="/" onClick={this.resetState}>
Home
</Link>
.
</div> </div>
<br /> <br />
<div> <div>

View File

@ -151,6 +151,10 @@ export const dropInconsistentObjects = () => {
}; };
}; };
export const isMetadataStatusPage = () => {
return window.location.pathname.includes('/metadata/status');
};
export const redirectToMetadataStatus = () => { export const redirectToMetadataStatus = () => {
return dispatch => { return dispatch => {
return dispatch( return dispatch(
@ -469,7 +473,7 @@ export const metadataReducer = (state = defaultState, action) => {
...state, ...state,
allowedQueries: [ allowedQueries: [
...state.allowedQueries.map(q => ...state.allowedQueries.map(q =>
(q.name === action.data.queryName ? action.data.newQuery : q) q.name === action.data.queryName ? action.data.newQuery : q
), ),
], ],
}; };