-
Notifications
You must be signed in to change notification settings - Fork 22
chore(ErrorWrapper): Error wrapper story update #1319
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
Draft
KrotovPetr
wants to merge
2
commits into
gravity-ui:main
Choose a base branch
from
KrotovPetr:error-wrepper-story-update
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| # ErrorWrapper | ||
|
|
||
| The `ErrorWrapper` component is used to gracefully handle and display local errors in UI sections. | ||
| When the `isError` flag is set to `true`, it shows an error message and an optional retry button. | ||
| When `isError` is `false`, it renders its children content. | ||
|
|
||
| ## Installation / Import | ||
|
|
||
| ```tsx | ||
| import ErrorWrapper from './ErrorWrapper'; | ||
| ``` | ||
|
|
||
| ## When to Use | ||
|
|
||
| - Show a clear error state for a specific part of the interface (e.g., failed data load). | ||
|
|
||
| - Wrap a component to display either content or an error depending on state. | ||
|
|
||
| - Provide an inline retry mechanism. | ||
|
|
||
| ## Props | ||
|
|
||
| | Name | Type | Required | Default | Description | | ||
| | ------------ | ----------------- | -------- | ------- | ------------------------------------------ | | ||
| | `text` | `string` | ✅ | — | Error message text. | | ||
| | `buttonText` | `string` | ✅ | — | Text for the retry button. | | ||
| | `handler` | `() => void` | ✅ | — | Callback triggered on retry button click. | | ||
| | `isError` | `boolean` | ✅ | — | Show error (`true`) or children (`false`). | | ||
| | `children` | `React.ReactNode` | ✅ | — | Content rendered when no error occurs. | | ||
| | `className` | `string` | ❌ | — | Optional CSS class for additional styling. | | ||
|
|
||
| ## Example | ||
|
|
||
| ```tsx | ||
| import React from 'react'; | ||
| import ErrorWrapper from './ErrorWrapper'; | ||
|
|
||
| function DataPanel() { | ||
| const [isError, setIsError] = React.useState(true); | ||
|
|
||
| const handleRetry = () => { | ||
| console.log('Retry clicked'); | ||
| setIsError(false); | ||
| }; | ||
|
|
||
| return ( | ||
| <ErrorWrapper | ||
| text="Something went wrong" | ||
| buttonText="Try again" | ||
| isError={isError} | ||
| handler={handleRetry} | ||
| > | ||
| <div>Data loaded successfully!</div> | ||
| </ErrorWrapper> | ||
| ); | ||
| } | ||
| ``` |
Binary file added
BIN
+116 Bytes
...ual.test.tsx-snapshots/ErrorWrapper-render-CustomClass-light-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+192 Bytes
...isual.test.tsx-snapshots/ErrorWrapper-render-CustomClass-light-webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+116 Bytes
....visual.test.tsx-snapshots/ErrorWrapper-render-Default-light-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+192 Bytes
...er.visual.test.tsx-snapshots/ErrorWrapper-render-Default-light-webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+116 Bytes
...ual.test.tsx-snapshots/ErrorWrapper-render-Interactive-light-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+192 Bytes
...isual.test.tsx-snapshots/ErrorWrapper-render-Interactive-light-webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+116 Bytes
....visual.test.tsx-snapshots/ErrorWrapper-render-NoError-light-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+192 Bytes
...er.visual.test.tsx-snapshots/ErrorWrapper-render-NoError-light-webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+116 Bytes
...isual.test.tsx-snapshots/ErrorWrapper-render-NoHandler-light-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+192 Bytes
....visual.test.tsx-snapshots/ErrorWrapper-render-NoHandler-light-webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/components/ErrorWrapper/__tests__/ErrorWrapper.visual.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import {composeStories} from '@storybook/react'; | ||
|
|
||
| import {test} from '../../../../playwright/core/index'; | ||
| import * as ErrorWrapperStories from '../__stories__/ErrorWrapper.stories'; | ||
|
|
||
| export const {Default, NoError, CustomClass, NoHandler, Interactive} = | ||
| composeStories(ErrorWrapperStories); | ||
|
|
||
| test.describe('ErrorWrapper', () => { | ||
| test('render <Default>', async ({mount, expectScreenshot, defaultDelay}) => { | ||
| await mount(<Default />); | ||
| await defaultDelay(); | ||
| await expectScreenshot({skipTheme: 'dark'}); | ||
| }); | ||
|
|
||
| test('render <NoError>', async ({mount, expectScreenshot, defaultDelay}) => { | ||
| await mount(<NoError />); | ||
| await defaultDelay(); | ||
| await expectScreenshot({skipTheme: 'dark'}); | ||
| }); | ||
|
|
||
| test('render <CustomClass>', async ({mount, expectScreenshot, defaultDelay}) => { | ||
| await mount(<CustomClass />); | ||
| await defaultDelay(); | ||
| await expectScreenshot({skipTheme: 'dark'}); | ||
| }); | ||
|
|
||
| test('render <NoHandler>', async ({mount, expectScreenshot, defaultDelay}) => { | ||
| await mount(<NoHandler />); | ||
| await defaultDelay(); | ||
| await expectScreenshot({skipTheme: 'dark'}); | ||
| }); | ||
|
|
||
| test('render <Interactive>', async ({mount, expectScreenshot, defaultDelay}) => { | ||
| await mount(<Interactive />); | ||
| await defaultDelay(); | ||
| await expectScreenshot({skipTheme: 'dark'}); | ||
| }); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should work automatically. If it doesn't work, then you need to understand why.
Look at the reasons that I described in the comments, maybe it's them?
#1322