Skip to content

Commit

Permalink
feat: parsing errors page (#186)
Browse files Browse the repository at this point in the history
* feat: show error count in table

* add errors page to navbar

* add error page

* link to errors page

* review

* merge main and update import utils

* review
  • Loading branch information
diivi committed Jan 24, 2023
1 parent f778e1b commit 68b64ec
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 2 deletions.
5 changes: 5 additions & 0 deletions taxonomy-editor-frontend/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
import ResponsiveAppBar from "./components/ResponsiveAppBar";
import Entry from "./pages/allentries";
import EditEntry from "./pages/editentry";
import Errors from "./pages/errors";
import ExportTaxonomy from "./pages/export";
import GotoProject from "./pages/gotoproject";
import Home from "./pages/home";
Expand Down Expand Up @@ -51,6 +52,10 @@ function App() {
path=":taxonomyName/:branchName/search"
element={<SearchNode setDisplayedPages={setDisplayedPages} />}
/>
<Route
path=":taxonomyName/:branchName/errors"
element={<Errors setDisplayedPages={setDisplayedPages} />}
/>
</Routes>
</div>
</Router>
Expand Down
1 change: 1 addition & 0 deletions taxonomy-editor-frontend/src/pages/allentries/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const Entry = ({ setDisplayedPages }) => {
setDisplayedPages([
{ url: urlPrefix + "entry", translationKey: "Nodes" },
{ url: urlPrefix + "search", translationKey: "Search" },
{ url: urlPrefix + "errors", translationKey: "Errors" },
{ url: urlPrefix + "export", translationKey: "Export" },
]);
},
Expand Down
1 change: 1 addition & 0 deletions taxonomy-editor-frontend/src/pages/editentry/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const EditEntry = ({ setDisplayedPages }) => {
setDisplayedPages([
{ url: urlPrefix + "entry", translationKey: "Nodes" },
{ url: urlPrefix + "search", translationKey: "Search" },
{ url: urlPrefix + "errors", translationKey: "Errors" },
{ url: urlPrefix + "export", translationKey: "Export" },
]);
},
Expand Down
117 changes: 117 additions & 0 deletions taxonomy-editor-frontend/src/pages/errors/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import useFetch from "../../components/useFetch";
import { toTitleCase } from "../../utils";
import { createBaseURL } from "../editentry/createURL";
import { useParams } from "react-router-dom";
import {
Box,
Typography,
Table,
TableCell,
TableBody,
TableHead,
TableContainer,
} from "@mui/material";
import MaterialTable from "@material-table/core";
import { useState, useEffect } from "react";

const Errors = ({ setDisplayedPages }) => {
const { taxonomyName, branchName } = useParams();
const baseUrl = createBaseURL(taxonomyName, branchName);
const urlPrefix = `${taxonomyName}/${branchName}/`;
const [errors, setErrors] = useState([]);
const {
data: errorData,
isPending,
isError,
} = useFetch(`${baseUrl}parsing_errors`);

useEffect(() => {
if (!errorData) return;
const newErrors = errorData.errors.map((error, index) => ({
id: index + 1,
error: error,
}));
setErrors(newErrors);
}, [errorData]);

useEffect(
function addLinksToNavbar() {
setDisplayedPages([
{ url: urlPrefix + "entry", translationKey: "Nodes" },
{ url: urlPrefix + "search", translationKey: "Search" },
{ url: urlPrefix + "errors", translationKey: "Errors" },
{ url: urlPrefix + "export", translationKey: "Export" },
]);
},
[urlPrefix, setDisplayedPages]
);

if (isError) {
return (
<Box>
<Typography variant="h5">Unable to load errors.</Typography>
</Box>
);
}
if (isPending) {
return (
<Box>
<Typography variant="h5">Loading...</Typography>
</Box>
);
}

return (
<>
<TableContainer sx={{ ml: 2, width: 375, mt: 2 }}>
<Table style={{ border: "solid", borderWidth: 1.5 }}>
<TableHead>
<TableCell align="left">
<Typography variant="h6">Taxonony Name</Typography>
</TableCell>
<TableCell align="left">
<Typography variant="h6">Branch Name</Typography>
</TableCell>
</TableHead>
<TableBody>
<TableCell align="left" component="td" scope="row">
<Typography variant="body1">
{toTitleCase(taxonomyName)}
</Typography>
</TableCell>
<TableCell align="left" component="td" scope="row">
<Typography variant="body1">{branchName}</Typography>
</TableCell>
</TableBody>
</Table>
</TableContainer>
<Box
sx={{
width: 500,
ml: 2,
mt: 2,
border: "solid",
borderWidth: 1.5,
}}
>
<MaterialTable
data={errors}
columns={[
{
title: "No.",
field: "id",
width: "10%",
},
{ title: "Error", field: "error" },
]}
title="Errors"
options={{
tableLayout: "fixed",
}}
/>
</Box>
</>
);
};

export default Errors;
1 change: 1 addition & 0 deletions taxonomy-editor-frontend/src/pages/export/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const ExportTaxonomy = ({ setDisplayedPages }) => {
setDisplayedPages([
{ url: urlPrefix + "entry", translationKey: "Nodes" },
{ url: urlPrefix + "search", translationKey: "Search" },
{ url: urlPrefix + "errors", translationKey: "Errors" },
{ url: urlPrefix + "export", translationKey: "Export" },
]);
}, [urlPrefix, setDisplayedPages]);
Expand Down
23 changes: 21 additions & 2 deletions taxonomy-editor-frontend/src/pages/gotoproject/index.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Typography, Box, Grid } from "@mui/material";
import { Typography, Box, Grid, Link as MuiLink } from "@mui/material";
import { useState } from "react";
import { useNavigate } from "react-router-dom";
import useFetch from "../../components/useFetch";
Expand Down Expand Up @@ -31,6 +31,7 @@ const GotoProject = () => {
taxonomyName: toTitleCase(projectNode["taxonomy_name"]),
branchName: projectNode["branch_name"],
description: projectNode["description"],
errors_count: projectNode["errors_count"],
});
});
}
Expand Down Expand Up @@ -65,7 +66,25 @@ const GotoProject = () => {
{ title: "Project", field: "projectName" },
{ title: "Taxonomy", field: "taxonomyName" },
{ title: "Branch", field: "branchName" },
{ title: "Description", field: "description", width: "15vw" },
{ title: "Description", field: "description", width: "10vw" },
{
title: "Errors",
field: "errors_count",
render: (rowData) => {
if (rowData["errors_count"] > 0) {
return (
<MuiLink
color="error"
href={`/${toSnakeCase(rowData["taxonomyName"])}/${
rowData["branchName"]
}/errors`}
>
{rowData["errors_count"] + " errors"}
</MuiLink>
);
}
},
},
]}
options={{
actionsColumnIndex: -1,
Expand Down
1 change: 1 addition & 0 deletions taxonomy-editor-frontend/src/pages/search/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const SearchNode = ({ setDisplayedPages }) => {
setDisplayedPages([
{ url: urlPrefix + "entry", translationKey: "Nodes" },
{ url: urlPrefix + "search", translationKey: "Search" },
{ url: urlPrefix + "errors", translationKey: "Errors" },
{ url: urlPrefix + "export", translationKey: "Export" },
]);
},
Expand Down

0 comments on commit 68b64ec

Please sign in to comment.