From 1c90e013b17cd9f944a022fc7c9bcc1e0452d203 Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Fri, 20 Oct 2023 12:45:59 -0600 Subject: [PATCH] Add ErrorFallback component And wrap both the main app body and the DataGrid component with it. Signed-off-by: Zack Cerza --- src/App.tsx | 32 +++++++++-------- src/components/DataGrid/index.jsx | 50 ++++++++++++++------------ src/components/ErrorFallback/index.tsx | 24 +++++++++++++ 3 files changed, 69 insertions(+), 37 deletions(-) create mode 100644 src/components/ErrorFallback/index.tsx diff --git a/src/App.tsx b/src/App.tsx index af528a1..bc7b28d 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,6 +1,6 @@ import { useState } from "react"; -import { Routes, Route, Navigate } from "react-router-dom"; +import { Routes, Route } from "react-router-dom"; import { Helmet } from "react-helmet"; import AppBar from "./components/AppBar"; @@ -13,8 +13,10 @@ import Nodes from "./pages/Nodes"; import Node from "./pages/Node"; import StatsNodesLock from "./pages/StatsNodesLock"; import StatsNodesJobs from "./pages/StatsNodesJobs"; +import { ErrorBoundary } from "react-error-boundary"; import "./App.css"; +import ErrorFallback from "./components/ErrorFallback"; type AppProps = { darkMode: boolean; @@ -37,19 +39,21 @@ function App(props: AppProps) {
- - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - + + + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + +
); diff --git a/src/components/DataGrid/index.jsx b/src/components/DataGrid/index.jsx index 5de3d38..4625d36 100644 --- a/src/components/DataGrid/index.jsx +++ b/src/components/DataGrid/index.jsx @@ -1,8 +1,10 @@ import { DataGrid as MuiDataGrid } from "@mui/x-data-grid"; +import { ErrorBoundary } from "react-error-boundary"; import { styled } from "@mui/material/styles"; import { darken, lighten } from "@mui/material/styles"; import { colorTint } from "../../lib/utils"; +import ErrorFallback from "../ErrorFallback"; const PREFIX = "index"; @@ -154,29 +156,31 @@ export default function DataGrid(props) {
- + + +
diff --git a/src/components/ErrorFallback/index.tsx b/src/components/ErrorFallback/index.tsx new file mode 100644 index 0000000..f5f5815 --- /dev/null +++ b/src/components/ErrorFallback/index.tsx @@ -0,0 +1,24 @@ +import Typography from "@mui/material/Typography"; +import Link from "../Link"; + +import CodeBlock from "../CodeBlock"; + +export default function ErrorFallback(props: {error: Error}) { + return ( +
+ + Apologies - the component encountered an error. Please  + + file an issue + +  including this error message: + + +
+ ); +}