File tree Expand file tree Collapse file tree 2 files changed +27
-9
lines changed
site/src/components/ErrorSummary Expand file tree Collapse file tree 2 files changed +27
-9
lines changed Original file line number Diff line number Diff line change
1
+ import { action } from "@storybook/addon-actions"
1
2
import { ComponentMeta , Story } from "@storybook/react"
2
3
import React from "react"
3
4
import { ErrorSummary , ErrorSummaryProps } from "./ErrorSummary"
@@ -14,4 +15,12 @@ WithError.args = {
14
15
error : new Error ( "Something went wrong!" ) ,
15
16
}
16
17
18
+ export const WithRetry = Template . bind ( { } )
19
+ WithRetry . args = {
20
+ error : new Error ( "Failed to fetch something!" ) ,
21
+ retry : ( ) => {
22
+ action ( "retry" )
23
+ } ,
24
+ }
25
+
17
26
export const WithUndefined = Template . bind ( { } )
Original file line number Diff line number Diff line change
1
+ import Button from "@material-ui/core/Button"
2
+ import RefreshIcon from "@material-ui/icons/Refresh"
1
3
import React from "react"
4
+ import { Stack } from "../Stack/Stack"
2
5
3
6
const Language = {
4
- unknownErrorMessage : "Unknown error" ,
7
+ retryMessage : "Retry" ,
8
+ unknownErrorMessage : "An unknown error has occurred" ,
5
9
}
6
10
7
11
export interface ErrorSummaryProps {
8
12
error : Error | unknown
13
+ retry ?: ( ) => void
9
14
}
10
15
11
- export const ErrorSummary : React . FC < ErrorSummaryProps > = ( { error } ) => {
12
- // TODO: More interesting error page
16
+ export const ErrorSummary : React . FC < ErrorSummaryProps > = ( { error, retry } ) => (
17
+ < Stack >
18
+ { ! ( error instanceof Error ) ? < div > { Language . unknownErrorMessage } </ div > : < div > { error . toString ( ) } </ div > }
13
19
14
- if ( ! ( error instanceof Error ) ) {
15
- return < div > { Language . unknownErrorMessage } </ div >
16
- } else {
17
- return < div > { error . toString ( ) } </ div >
18
- }
19
- }
20
+ { retry && (
21
+ < div >
22
+ < Button onClick = { retry } startIcon = { < RefreshIcon /> } variant = "outlined" >
23
+ { Language . retryMessage }
24
+ </ Button >
25
+ </ div >
26
+ ) }
27
+ </ Stack >
28
+ )
You can’t perform that action at this time.
0 commit comments