Skip to content

Commit c4d7448

Browse files
authored
fix(ErrorBoundary): Align "Show details" center (#133)
1 parent cee5e2c commit c4d7448

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

packages/module/src/ErrorBoundary/ErrorBoundary.tsx

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
import * as React from 'react';
22
import { ExpandableSection, Title } from '@patternfly/react-core';
3+
import { createUseStyles } from 'react-jss';
34
import ErrorState from '../ErrorState';
45
import 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
)}

packages/module/src/ErrorState/ErrorState.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ const useStyles = createUseStyles({
1818
errorIcon: {
1919
fill: 'var(--pf-v5-global--danger-color--100)',
2020
},
21+
errorDescription: {
22+
margin: 'auto'
23+
}
2124
})
2225

2326
export interface ErrorStateProps extends Omit<EmptyStateProps, 'children'> {
@@ -40,7 +43,7 @@ const ErrorState: React.FunctionComponent<ErrorStateProps> = ({ errorTitle = 'So
4043
<EmptyStateHeader titleText={<>{errorTitle}</>} icon={<EmptyStateIcon className={classes.errorIcon} icon={ExclamationCircleIcon} data-ouia-component-id={`${ouiaId}-icon`} />} headingLevel="h4" data-ouia-component-id={`${ouiaId}-header`}/>
4144
<EmptyStateBody data-ouia-component-id={`${ouiaId}-body`}>
4245
<Stack>
43-
{errorDescription ? <StackItem>{errorDescription}</StackItem> : defaultErrorDescription}
46+
{errorDescription ? <StackItem className={classes.errorDescription}>{errorDescription}</StackItem> : defaultErrorDescription}
4447
</Stack>
4548
</EmptyStateBody>
4649
<EmptyStateFooter data-ouia-component-id={`${ouiaId}-footer`}>

0 commit comments

Comments
 (0)