Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,11 @@ To provide users with error details, a basic error state should contain an appro
```js file="./ErrorStateExample.tsx"

```

### Custom footer

To override default action button, specify your own using `customFooter`.

```js file="./ErrorStateFooterExample.tsx"

```
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import ErrorState from "@patternfly/react-component-groups/dist/dynamic/ErrorState";

export const BasicExample: React.FunctionComponent = () => <ErrorState errorTitle='A Basic Error' errorDescription='The following is an example of a basic error' />;
export const BasicExample: React.FunctionComponent = () => <ErrorState errorTitle='Sample error title' errorDescription='Sample error description' />;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react';
import { Button } from '@patternfly/react-core';
import ErrorState from "@patternfly/react-component-groups/dist/dynamic/ErrorState";

// eslint-disable-next-line no-console
export const BasicExample: React.FunctionComponent = () => <ErrorState errorTitle='Sample error title' errorDescription='Sample error description' customFooter={<Button variant="secondary" onClick={() => console.log("Custom button clicked")}>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to block the onClick and console log the "button clicked?"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an example for the docs

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, yeah! Feel free to merge!

Custom action
</Button>}/>;
5 changes: 3 additions & 2 deletions packages/module/src/ErrorState/ErrorState.test.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import * as React from 'react';
import ErrorState from './ErrorState';
import { render, screen } from '@testing-library/react';
import { Button } from '@patternfly/react-core';

describe('ErrorState component', () => {

it('should render correctly', () => {
render(<ErrorState errorTitle='A Basic Error' errorDescription='The following is an example of a basic error' />);
render(<ErrorState errorTitle='A Basic Error' errorDescription='The following is an example of a basic error' customFooter={<Button>Custom button</Button>} />);

expect(screen.getByText('A Basic Error')).toBeVisible();
expect(screen.getByText('The following is an example of a basic error')).toBeVisible();
expect(screen.getByText('Go to home page')).toBeVisible();
expect(screen.getByText('Custom button')).toBeVisible();
});

it('should render correctly with default props', () => {
Expand Down
19 changes: 11 additions & 8 deletions packages/module/src/ErrorState/ErrorState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ export interface ErrorStateProps extends Omit<EmptyStateProps, 'children'> {
errorDescription?: React.ReactNode;
/** A default description of the error used if no errorDescription is provided. */
defaultErrorDescription?: React.ReactNode;
/** Custom footer content */
customFooter?: React.ReactNode;
}

const ErrorState: React.FunctionComponent<ErrorStateProps> = ({ errorTitle = 'Something went wrong', errorDescription, defaultErrorDescription, ...props }: ErrorStateProps) => {
const ErrorState: React.FunctionComponent<ErrorStateProps> = ({ errorTitle = 'Something went wrong', errorDescription, defaultErrorDescription, customFooter, ...props }: ErrorStateProps) => {
const classes = useStyles();
return (
<EmptyState variant={EmptyStateVariant.lg} {...props}>
Expand All @@ -40,15 +42,16 @@ const ErrorState: React.FunctionComponent<ErrorStateProps> = ({ errorTitle = 'So
</Stack>
</EmptyStateBody>
<EmptyStateFooter>
{document.referrer ? (
<Button variant="primary" onClick={() => history.back()}>
{ customFooter ||
(document.referrer ? (
<Button variant="primary" onClick={() => history.back()}>
Return to last page
</Button>
) : (
<Button variant="primary" component="a" href="." target="_blank" rel="noopener noreferrer">
</Button>
) : (
<Button variant="primary" component="a" href="." target="_blank" rel="noopener noreferrer">
Go to home page
</Button>
)}
</Button>
))}
</EmptyStateFooter>
</EmptyState>
);
Expand Down