forked from woocommerce/woocommerce-blocks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Storybook and TS migration of
ErrorPlaceholder
component (woocommer…
…ce#5294) * Convert `ErrorPlaceholder` and `ErrorMessage` to TypeScript * Add stories for `ErrorPlaceholder` and `ErrorMessage` (woocommerce#5255) Stories include: * Default generic error * API error * Unknown error * Error without possibility to retry * Base Error atom Where applicable, the **Retry** button will not only trigger the appropriate action, but also simulate the loading state of the error component. * Update references to `ErrorMessage` component to leave the file extension out Fix woocommerce#5255 Refs woocommerce#5249
- Loading branch information
1 parent
3291cc7
commit 59662fb
Showing
11 changed files
with
485 additions
and
83 deletions.
There are no files selected for viewing
This file contains 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 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
27 changes: 27 additions & 0 deletions
27
assets/js/editor-components/error-placeholder/stories/error-message.tsx
This file contains 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,27 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { Story, Meta } from '@storybook/react'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import ErrorMessage, { ErrorMessageProps } from '../error-message'; | ||
|
||
export default { | ||
title: 'WooCommerce Blocks/editor-components/Errors/Base Error Atom', | ||
component: ErrorMessage, | ||
} as Meta< ErrorMessageProps >; | ||
|
||
const Template: Story< ErrorMessageProps > = ( args ) => ( | ||
<ErrorMessage { ...args } /> | ||
); | ||
|
||
export const BaseErrorAtom = Template.bind( {} ); | ||
BaseErrorAtom.args = { | ||
error: { | ||
message: | ||
'A very generic and unhelpful error. Please try again later. Or contact support. Or not.', | ||
type: 'general', | ||
}, | ||
}; |
70 changes: 70 additions & 0 deletions
70
assets/js/editor-components/error-placeholder/stories/error-placeholder.tsx
This file contains 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,70 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { Story, Meta } from '@storybook/react'; | ||
import { useArgs } from '@storybook/client-api'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import ErrorPlaceholder, { ErrorPlaceholderProps } from '..'; | ||
|
||
export default { | ||
title: 'WooCommerce Blocks/editor-components/Errors', | ||
component: ErrorPlaceholder, | ||
} as Meta< ErrorPlaceholderProps >; | ||
|
||
const Template: Story< ErrorPlaceholderProps > = ( args ) => { | ||
const [ { isLoading }, setArgs ] = useArgs(); | ||
|
||
const onRetry = args.onRetry | ||
? () => { | ||
setArgs( { isLoading: true } ); | ||
|
||
setTimeout( () => setArgs( { isLoading: false } ), 3500 ); | ||
} | ||
: undefined; | ||
|
||
return ( | ||
<ErrorPlaceholder | ||
{ ...args } | ||
onRetry={ onRetry } | ||
isLoading={ isLoading } | ||
/> | ||
); | ||
}; | ||
|
||
export const Default = Template.bind( {} ); | ||
Default.args = { | ||
error: { | ||
message: | ||
'A very generic and unhelpful error. Please try again later. Or contact support. Or not.', | ||
type: 'general', | ||
}, | ||
}; | ||
|
||
export const APIError = Template.bind( {} ); | ||
APIError.args = { | ||
error: { | ||
message: 'Server refuses to comply. It is a teapot.', | ||
type: 'api', | ||
}, | ||
}; | ||
|
||
export const UnknownError = Template.bind( {} ); | ||
UnknownError.args = { | ||
error: { | ||
message: '', | ||
type: 'general', | ||
}, | ||
}; | ||
|
||
export const NoRetry: Story< ErrorPlaceholderProps > = ( args ) => { | ||
return <ErrorPlaceholder { ...args } onRetry={ undefined } />; | ||
}; | ||
NoRetry.args = { | ||
error: { | ||
message: '', | ||
type: 'general', | ||
}, | ||
}; |
19 changes: 0 additions & 19 deletions
19
assets/js/editor-components/error-placeholder/stories/index.js
This file was deleted.
Oops, something went wrong.
This file contains 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 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 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 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
Oops, something went wrong.