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 (
{code}{title}{children}{actions ?? }
);
}
export function NotFoundPage() {
const loc = useLocation();
return (
There is nothing at {loc.pathname}. The link may be old, or the test run or report may have been removed.
);
}
/** 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 (
>}>
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.
);
}
}