Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] fix broken story in Prompt Custom Actions #149992

Merged
merged 4 commits into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
24 changes: 24 additions & 0 deletions packages/shared-ux/prompt/not_found/README.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,27 @@ date: 2022-02-09
Sometimes the user tries to go to a page that doesn't exist, because the URL is broken or because they try to load a resource that does not exist. For those cases we want to show a standard 404 error.

The default call to action is a "Go back" button that simulates the browser's "Back" behaviour. Consumers can specify their own CTA's with the `actions` prop.

The NotFoundPrompt component also has the prop `actions` that takes in an array of components.
For example:

```jsx
<EuiPageTemplate>
<EuiPageTemplate.Section alignment="center">
<NotFoundPrompt
actions={
[
<EuiButton fill color="primary" onClick={onClickHandler}>
Go home
</EuiButton>,
<EuiButton iconType="search">
Go to discover
</EuiButton>
]
}
title="Customizable Title"
body="Customizable Body"
/>
</EuiPageTemplate.Section>
</EuiPageTemplate>
```
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { EuiButton, EuiButtonEmpty, EuiPageTemplate } from '@elastic/eui';
import { EuiButton, EuiPageTemplate } from '@elastic/eui';
import React from 'react';
import { Meta, Story } from '@storybook/react';
import mdx from '../README.mdx';
Expand Down Expand Up @@ -51,14 +51,18 @@ export const CustomActions: Story = (args) => {
<EuiPageTemplate>
<EuiPageTemplate.Section alignment="center">
<NotFoundPrompt
actions={[
<EuiButton fill color="primary" onClick={args.onClick}>
Go home
</EuiButton>,
<EuiButtonEmpty iconType="search" onClick={args.onClick}>
Go to discover
</EuiButtonEmpty>,
]}
actions={
<>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a storybook issue in not being able to read the values of the array. I added the test to confirm that the component does render as expected.

<EuiButton fill color="primary" onClick={args.onClick}>
Go home
</EuiButton>
<EuiButton iconType="search" onClick={args.onClick}>
Go to discover
</EuiButton>
</>
}
title="Customizable Title"
body="Customizable Body"
/>
</EuiPageTemplate.Section>
</EuiPageTemplate>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,11 @@ describe('<NotFoundPrompt />', () => {
const component = render(<NotFoundPrompt actions={actions} />);
expect(component.text()).toContain('I am a button');
});

it('Renders custom actions with an array with multiple buttons', () => {
const actions = [<button>I am a button</button>, <button>I am a second button</button>];
const component = render(<NotFoundPrompt actions={actions} />);
expect(component.text()).toContain('I am a button');
expect(component.text()).toContain('I am a second button');
});
});