Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c465f8a

Browse files
authored
feat: add retry to ErrorSummary (#1690)
Summary: The ErrorSummary accepts a retry callback and received improvements to style and product copy Impact: This allows xstate-controlled pages to send re-fetch events
1 parent dd4bb07 commit c465f8a

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

site/src/components/ErrorSummary/ErrorSummary.stories.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { action } from "@storybook/addon-actions"
12
import { ComponentMeta, Story } from "@storybook/react"
23
import React from "react"
34
import { ErrorSummary, ErrorSummaryProps } from "./ErrorSummary"
@@ -14,4 +15,12 @@ WithError.args = {
1415
error: new Error("Something went wrong!"),
1516
}
1617

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+
1726
export const WithUndefined = Template.bind({})
Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
1+
import Button from "@material-ui/core/Button"
2+
import RefreshIcon from "@material-ui/icons/Refresh"
13
import React from "react"
4+
import { Stack } from "../Stack/Stack"
25

36
const Language = {
4-
unknownErrorMessage: "Unknown error",
7+
retryMessage: "Retry",
8+
unknownErrorMessage: "An unknown error has occurred",
59
}
610

711
export interface ErrorSummaryProps {
812
error: Error | unknown
13+
retry?: () => void
914
}
1015

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>}
1319

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+
)

0 commit comments

Comments
 (0)