Skip to content

Commit

Permalink
Merge pull request #65 from ceph/null-jobid
Browse files Browse the repository at this point in the history
Improve error handling and fix a crash
  • Loading branch information
zmc authored Feb 22, 2024
2 parents 249a7b5 + 5d91123 commit 07e51f2
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 36 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"react": "^18.2.0",
"react-cookie": "^5.0.0",
"react-dom": "^18.2.0",
"react-error-boundary": "^4.0.11",
"react-helmet": "^6.1.0",
"react-router-dom": "^6.14.1",
"react-simple-code-editor": "^0.13.1",
Expand Down
30 changes: 17 additions & 13 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,19 +39,21 @@ function App(props: AppProps) {
</header>
<Drawer drawerOpen={drawerOpen} setDrawerOpen={setDrawerOpen} />
<div className="App-body">
<Routes>
<Route path="/" element={<Runs />} />
<Route path="/nodes" element={<Nodes />} />
<Route path="/nodes/:name" element={<Node />} />
<Route path="/stats/nodes/jobs" element={<StatsNodesJobs />} />
<Route path="/stats/nodes/lock" element={<StatsNodesLock />} />
<Route path="/runs" element={<Runs />} />
<Route path="/runs/:name" element={<Run />} />
<Route path="/runs/:name/jobs/:job_id" element={<Job />} />
<Route path="/queue" element={<Queue />} />
<Route path="/:name" element={<Run />} />
<Route path="/:name/:job_id" element={<Job />} />
</Routes>
<ErrorBoundary FallbackComponent={ErrorFallback} >
<Routes>
<Route path="/" element={<Runs />} />
<Route path="/nodes" element={<Nodes />} />
<Route path="/nodes/:name" element={<Node />} />
<Route path="/stats/nodes/jobs" element={<StatsNodesJobs />} />
<Route path="/stats/nodes/lock" element={<StatsNodesLock />} />
<Route path="/runs" element={<Runs />} />
<Route path="/runs/:name" element={<Run />} />
<Route path="/runs/:name/jobs/:job_id" element={<Job />} />
<Route path="/queue" element={<Queue />} />
<Route path="/:name" element={<Run />} />
<Route path="/:name/:job_id" element={<Job />} />
</Routes>
</ErrorBoundary>
</div>
</div>
);
Expand Down
34 changes: 34 additions & 0 deletions src/components/CodeBlock/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import Editor from "react-simple-code-editor";
import { highlight, languages } from "prismjs/components/prism-core";
import 'prismjs/components/prism-clike';
import "prismjs/components/prism-yaml";
import 'prismjs/components/prism-javascript';

export default function CodeBlock(props) {
const language = languages[props.language];
if ( ! props.value ) return null;
return (
<Editor
value={props.value}
readOnly={true}
highlight={(code) => {
if (!! language ) return highlight(code, language);
return code;
}}
style={{
fontFamily: [
"ui-monospace",
"SFMono-Regular",
'"SF Mono"',
"Menlo",
"Consolas",
"Liberation Mono",
'"Lucida Console"',
"Courier",
"monospace",
].join(","),
textAlign: "initial",
}}
/>
)
}
24 changes: 24 additions & 0 deletions src/components/ErrorFallback/index.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<div>
<Typography
color="textPrimary"
variant="h5"
>
Apologies - the component encountered an error. Please&nbsp;
<Link
to="https://github.com/ceph/pulpito-ng/issues/new"
>
file an issue
</Link>
&nbsp;including this error message:
</Typography>
<CodeBlock value={props.error?.message || ""} language="js" />
</div>
);
}
2 changes: 1 addition & 1 deletion src/components/JobList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ type JobListProps = {

export default function JobList({ query, sortMode }: JobListProps) {
const options = useDefaultTableOptions<Job>();
const data = query.data?.jobs || [];
const data = (query.data?.jobs || []).filter(item => item.id);
const table = useMaterialReactTable({
...options,
columns,
Expand Down
24 changes: 2 additions & 22 deletions src/pages/Job/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ import HighlightOffIcon from "@mui/icons-material/HighlightOff";
import FolderIcon from '@mui/icons-material/Folder';
import formatDuration from "date-fns/formatDuration";
import { isValid, parse } from "date-fns";
import Editor from "react-simple-code-editor";
import { highlight, languages } from "prismjs/components/prism-core";
import "prismjs/components/prism-yaml";
import "prismjs/themes/prism-tomorrow.css";
import { Helmet } from "react-helmet";
import YAML from "json-to-pretty-yaml";

import Link from "../../components/Link";
import CodeBlock from "../../components/CodeBlock";
import { useJob } from "../../lib/paddles";
import { getDuration, dirName } from "../../lib/utils";

Expand Down Expand Up @@ -150,25 +148,7 @@ function JobDetails({ query }) {
if (query.isError) return "!!!";
const code = YAML.stringify(query.data);
return (
<Editor
value={code}
readOnly={true}
highlight={(code) => highlight(code, languages.yaml)}
style={{
fontFamily: [
"ui-monospace",
"SFMono-Regular",
'"SF Mono"',
"Menlo",
"Consolas",
"Liberation Mono",
'"Lucida Console"',
"Courier",
"monospace",
].join(","),
textAlign: "initial",
}}
/>
<CodeBlock value={code} language="yaml" />
);
}

Expand Down

0 comments on commit 07e51f2

Please sign in to comment.