11import * as React from 'react' ;
22import { ExpandableSection , Title } from '@patternfly/react-core' ;
3+ import { createUseStyles } from 'react-jss' ;
34import ErrorState from '../ErrorState' ;
45import ErrorStack from '../ErrorStack' ;
56
6- export interface ErrorPageProps {
7+ const useStyles = createUseStyles ( {
8+ expandableSectionToggle : {
9+ "& > .pf-v5-c-expandable-section__toggle" : {
10+ margin : "auto" ,
11+ }
12+ } ,
13+ } )
14+
15+ export interface ErrorBoundaryProps {
716 /** The title text to display on the error page */
817 headerTitle : string ;
918 /** Indicates if the error is silent */
@@ -22,7 +31,7 @@ export interface ErrorPageProps {
2231 ouiaId ?: string | number ;
2332}
2433
25- export interface ErrorPageState {
34+ export interface ErrorBoundaryState {
2635 /** Indicates if there is currently an error */
2736 hasError : boolean ;
2837 /** Error */
@@ -31,8 +40,18 @@ export interface ErrorPageState {
3140 historyState : History [ 'state' ] ;
3241}
3342
43+ interface ErrorPageProps extends ErrorBoundaryProps {
44+ /** JSS classes */
45+ classes : Record < string | number | symbol , string > ;
46+ }
47+
48+ export const ErrorBoundary : React . FunctionComponent < ErrorBoundaryProps > = ( props : ErrorBoundaryProps ) => {
49+ const classes = useStyles ( ) ;
50+ return < ErrorBoundaryContent classes = { classes } { ...props } />
51+ }
52+
3453// As of time of writing, React only supports error boundaries in class components
35- class ErrorBoundary extends React . Component < ErrorPageProps , ErrorPageState > {
54+ class ErrorBoundaryContent extends React . Component < ErrorPageProps , ErrorBoundaryState > {
3655 constructor ( props : Readonly < ErrorPageProps > ) {
3756 super ( props ) ;
3857 this . state = {
@@ -41,7 +60,7 @@ class ErrorBoundary extends React.Component<ErrorPageProps, ErrorPageState> {
4160 } ;
4261 }
4362
44- static getDerivedStateFromError ( error : Error ) : ErrorPageState {
63+ static getDerivedStateFromError ( error : Error ) : ErrorBoundaryState {
4564 return { hasError : true , error, historyState : history . state } ;
4665 }
4766
@@ -79,7 +98,7 @@ class ErrorBoundary extends React.Component<ErrorPageProps, ErrorPageState> {
7998 < >
8099 < span > { props . errorDescription } </ span >
81100 { this . state . error && (
82- < ExpandableSection toggleText = { props . errorToggleText ? props . errorToggleText : "Show details" } data-ouia-component-id = { `${ ouiaId } -toggle` } >
101+ < ExpandableSection className = { props . classes . expandableSectionToggle } toggleText = { props . errorToggleText ? props . errorToggleText : "Show details" } data-ouia-component-id = { `${ ouiaId } -toggle` } >
83102 < ErrorStack error = { this . state . error } data-ouia-component-id = { `${ ouiaId } -stack` } />
84103 </ ExpandableSection >
85104 ) }
0 commit comments