Download web/src/components/ErrorPages.tsx from EnergyVenom/patchwise-agent-studio: direct link, hf CLI and curl.
- Browser
- Download file 2.59 kB
-
https://huggingface.co/spaces/EnergyVenom/patchwise-agent-studio/resolve/main/web/src/components/ErrorPages.tsx
- Command line
-
hf download hf://spaces/EnergyVenom/patchwise-agent-studio/web/src/components/ErrorPages.tsx
-
curl -L -o ErrorPages.tsx https://huggingface.co/spaces/EnergyVenom/patchwise-agent-studio/resolve/main/web/src/components/ErrorPages.tsx
2.59 kB
| import { Button, Group, Stack, Text, Title } from '@mantine/core'; | |
| import { Component, type ErrorInfo, type ReactNode } from 'react'; | |
| import { Link, useLocation } from 'react-router-dom'; | |
| /** One layout for "page not found", "no access" and "something broke": what happened, and a way on. */ | |
| export function ProblemPage({ code, title, children, actions }: { code: string; title: string; children: ReactNode; actions?: ReactNode }) { | |
| return ( | |
| <section className="fpt-problem" aria-labelledby="problem-title" data-testid={`problem-${code}`}> | |
| <Stack gap="sm" maw={520} mx="auto" py={64} px="md"> | |
| <Text size="sm" c="dimmed" fw={600}>{code}</Text> | |
| <Title order={1} id="problem-title">{title}</Title> | |
| <Text>{children}</Text> | |
| <Group gap="sm" mt="md">{actions ?? <Button component={Link} to="/" variant="filled">Go to Home</Button>}</Group> | |
| </Stack> | |
| </section> | |
| ); | |
| } | |
| export function NotFoundPage() { | |
| const loc = useLocation(); | |
| return ( | |
| <ProblemPage code="404" title="This page does not exist"> | |
| There is nothing at <code>{loc.pathname}</code>. The link may be old, or the test run or report may have been removed. | |
| </ProblemPage> | |
| ); | |
| } | |
| /** Catches a screen that crashed while drawing, so the rest of the app keeps working and the person can recover. */ | |
| export class ScreenErrorBoundary extends Component<{ children: ReactNode; resetKey?: string }, { error: Error | null }> { | |
| state: { error: Error | null } = { error: null }; | |
| static getDerivedStateFromError(error: Error) { | |
| return { error }; | |
| } | |
| componentDidCatch(error: Error, info: ErrorInfo) { | |
| // the browser console is the only place the details go: nothing is sent anywhere | |
| console.error('Screen error', error, info.componentStack); | |
| } | |
| componentDidUpdate(prev: { resetKey?: string }) { | |
| if (this.state.error && prev.resetKey !== this.props.resetKey) this.setState({ error: null }); // navigated away | |
| } | |
| render() { | |
| if (!this.state.error) return this.props.children; | |
| return ( | |
| <ProblemPage code="Error" title="This screen stopped working" | |
| actions={<><Button variant="filled" onClick={() => window.location.reload()}>Reload the page</Button><Button component={Link} to="/" variant="default">Go to Home</Button></>}> | |
| Something went wrong while showing this page. Your test runs are not affected: they keep running on the server. | |
| Reload the page; if it happens again, tell your administrator what you were doing. | |
| </ProblemPage> | |
| ); | |
| } | |
| } | |