-
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.
- Loading branch information
Showing
9 changed files
with
103 additions
and
6 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
24 changes: 24 additions & 0 deletions
24
frontend-react/src/app/widgets/error-widget/error-widget.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,24 @@ | ||
import { useEffect, useState } from 'react'; | ||
|
||
export function ErrorWidget() { | ||
const [showError, setShowError] = useState(false); | ||
useEffect(() => { | ||
const timeout = setTimeout(() => { | ||
setShowError(true); | ||
}, 3_000); | ||
return () => clearTimeout(timeout); | ||
}, []); | ||
|
||
if (showError) { | ||
throw new Error( | ||
`Test error thrown by the error widget at ${new Date().toISOString()}` | ||
); | ||
} | ||
|
||
return ( | ||
<div> | ||
<h1>This widget will throw an error after three seconds</h1> | ||
<p>It is used to test the error handling of the dashboard.</p> | ||
</div> | ||
); | ||
} |
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,14 @@ | ||
import { ErrorWidget } from './error-widget.tsx'; | ||
import { Widget } from '../../../lib'; | ||
|
||
export const errorWidget: Widget = { | ||
id: 'error-widget', | ||
label: 'Error Widget', | ||
|
||
createConfig() { | ||
return {}; | ||
}, | ||
|
||
element: <ErrorWidget />, | ||
configElement: <div>Config</div> | ||
}; |
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
5 changes: 5 additions & 0 deletions
5
frontend-react/src/lib/widget/component/error-fallback.module.css
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,5 @@ | ||
.alert { | ||
height: 100%; | ||
margin: 0; | ||
overflow-y: auto; | ||
} |
31 changes: 31 additions & 0 deletions
31
frontend-react/src/lib/widget/component/error-fallback.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,31 @@ | ||
import { Alert, AlertHeading, Button } from 'react-bootstrap'; | ||
import styles from './error-fallback.module.css'; | ||
|
||
export function ErrorFallback({ | ||
error, | ||
resetErrorBoundary | ||
}: { | ||
error: Error; | ||
resetErrorBoundary: () => void; | ||
}) { | ||
return ( | ||
<Alert variant="danger" className={styles.alert}> | ||
<AlertHeading>Widget Error</AlertHeading> | ||
<p> | ||
Unfortunately, the widget encountered an error and cannot be displayed. | ||
</p> | ||
<p>Please try again or contact your developer if the problem persists.</p> | ||
<details> | ||
<summary>Details</summary> | ||
<pre>{error.stack}</pre> | ||
</details> | ||
<Button | ||
className={'mt-4'} | ||
variant={'outline-light'} | ||
onClick={resetErrorBoundary} | ||
> | ||
Reload the widget | ||
</Button> | ||
</Alert> | ||
); | ||
} |
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