diff --git a/extensions/default/src/ViewerLayout/index.jsx b/extensions/default/src/ViewerLayout/index.jsx index cf2c11826..cbf414efc 100644 --- a/extensions/default/src/ViewerLayout/index.jsx +++ b/extensions/default/src/ViewerLayout/index.jsx @@ -1,7 +1,6 @@ import React, { useEffect, useState } from 'react'; -import classnames from 'classnames'; import PropTypes from 'prop-types'; -import { SidePanel } from '@ohif/ui'; +import { SidePanel, ErrorBoundary } from '@ohif/ui'; import Header from './Header.jsx'; import NestedMenu from './ToolbarButtonNestedMenu.jsx'; @@ -93,27 +92,28 @@ function ViewerLayout({ return (
-
- {toolbars.primary.map(toolDef => { - const isNested = Array.isArray(toolDef); - - if (!isNested) { - const { id, Component, componentProps } = toolDef; - return ; - } else { - return ( - -
- {toolDef.map(x => { - const { id, Component, componentProps } = x; - return ; - })} -
-
- ); - } - })} -
+ +
+ {toolbars.primary.map(toolDef => { + const isNested = Array.isArray(toolDef); + if (!isNested) { + const { id, Component, componentProps } = toolDef; + return ; + } else { + return ( + +
+ {toolDef.map(x => { + const { id, Component, componentProps } = x; + return ; + })} +
+
+ ); + } + })} +
+
{/* LEFT SIDEPANELS */} {leftPanelComponents.length && ( - + + + )} {/* TOOLBAR + GRID */}
-
- {toolbars.secondary.map(toolDef => { - const { id, Component, componentProps } = toolDef; - - return ; - })} -
+ +
+ {toolbars.secondary.map(toolDef => { + const { id, Component, componentProps } = toolDef; + return ; + })} +
+
- + + +
{rightPanelComponents.length && ( - + + + )}
diff --git a/platform/ui/src/components/ErrorBoundary/ErrorBoundary.jsx b/platform/ui/src/components/ErrorBoundary/ErrorBoundary.jsx index 905570910..f6915592c 100644 --- a/platform/ui/src/components/ErrorBoundary/ErrorBoundary.jsx +++ b/platform/ui/src/components/ErrorBoundary/ErrorBoundary.jsx @@ -1,46 +1,86 @@ -import React from 'react'; +import React, { useState } from 'react'; import { ErrorBoundary as ReactErrorBoundary } from 'react-error-boundary'; import PropTypes from 'prop-types'; -import './ErrorFallback.css'; +import Modal from '../Modal'; const isProduction = process.env.NODE_ENV === 'production'; -const ErrorFallback = ({ error, componentStack, resetErrorBoundary }) => { +const DefaultFallback = ({ error, componentStack, context, resetErrorBoundary, fallbackRoute }) => { + const title = `Something went wrong${!isProduction && ` in ${context}`}.`; + const subtitle = `Sorry, something went wrong there. Try again.`; return ( -
-

Something went wrong.

- {isProduction && ( - Sorry, something went wrong there. Try again. +
+

{title}

+

{subtitle}

+ {!isProduction && ( +
+
Context: {context}
+
Error Message: {error.message}
+
Stack: {componentStack}
+
)} - {!isProduction &&
{error.message}
} - {!isProduction &&
{componentStack}
}
); }; -ErrorFallback.propTypes = { - resetErrorBoundary: PropTypes +const noop = () => { }; + +DefaultFallback.propTypes = { + error: PropTypes.object.isRequired, + resetErrorBoundary: PropTypes.func, + componentStack: PropTypes.string, +}; + +DefaultFallback.defaultProps = { + resetErrorBoundary: noop }; const ErrorBoundary = ({ - context = 'RCT', - onReset = () => { }, - onError = () => { }, - fallbackComponent, - children + context, + onReset, + onError, + fallbackComponent: FallbackComponent, + children, + fallbackRoute, + isPage }) => { + const [isOpen, setIsOpen] = useState(true); + const onErrorHandler = (error, componentStack) => { - console.error(`${context} Error Boundary`, error, componentStack); - onError(error, componentStack); + console.error(`${context} Error Boundary`, error, componentStack, context); + onError(error, componentStack, context); }; - const onResetHandler = () => { - onReset(); - }; + const onResetHandler = (...args) => onReset(...args); + + const withModal = (Component) => props => ( + { + setIsOpen(false); + if (fallbackRoute) { + window.location = fallbackRoute; + } + }} + > + + + ); + + const Fallback = isPage ? FallbackComponent : withModal(FallbackComponent); return ( ( + + )} onReset={onResetHandler} onError={onErrorHandler} > @@ -49,4 +89,21 @@ const ErrorBoundary = ({ ); }; +ErrorBoundary.propTypes = { + context: PropTypes.string, + onReset: PropTypes.func, + onError: PropTypes.func, + fallbackComponent: PropTypes.oneOfType([PropTypes.node, PropTypes.func]), + children: PropTypes.node.isRequired, + fallbackRoute: PropTypes.string +}; + +ErrorBoundary.defaultProps = { + context: 'OHIF', + onReset: noop, + onError: noop, + fallbackComponent: DefaultFallback, + fallbackRoute: null +}; + export default ErrorBoundary; diff --git a/platform/ui/src/components/ErrorBoundary/ErrorFallback.css b/platform/ui/src/components/ErrorBoundary/ErrorFallback.css deleted file mode 100644 index 34d62ccf4..000000000 --- a/platform/ui/src/components/ErrorBoundary/ErrorFallback.css +++ /dev/null @@ -1,21 +0,0 @@ -.ErrorFallback { - padding: 10px; - - &, - pre { - color: #7cc5e9; - } - - p { - font-weight: bold; - } - - span { - color: gray; - } - - pre { - background-color: black; - border: none; - } -} diff --git a/platform/ui/src/components/ViewportActionBar/ViewportActionBar.jsx b/platform/ui/src/components/ViewportActionBar/ViewportActionBar.jsx index 9129d871c..12f052e76 100644 --- a/platform/ui/src/components/ViewportActionBar/ViewportActionBar.jsx +++ b/platform/ui/src/components/ViewportActionBar/ViewportActionBar.jsx @@ -136,7 +136,7 @@ const ViewportActionBar = ({
)} -
+
)} > -
+
{allRoutes.map((route, i) => { + console.log(route); return ( ( // eslint-disable-next-line react/jsx-props-no-spreading - + + + )} /> );