Skip to content

Commit

Permalink
fix: better 404 handling for model and system (should no longer crash…
Browse files Browse the repository at this point in the history
… the frontend)
  • Loading branch information
Tethik committed Nov 1, 2023
1 parent db36690 commit 5b2b77d
Show file tree
Hide file tree
Showing 16 changed files with 48 additions and 119 deletions.
2 changes: 1 addition & 1 deletion app/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { getAuthToken } from "./api/gram/util/authToken";
import "./App.css";
import AdminPage from "./components/admin/AdminPage";
import { ModalManager } from "./components/elements/modal/ModalManager";
import ErrorPage from "./components/error-page";
import { ErrorPage } from "./components/elements/ErrorPage";
import Home from "./components/home/Home";
import { Login } from "./components/login/Login";
import { LoginCallback } from "./components/login/LoginCallback";
Expand Down
File renamed without changes.
6 changes: 6 additions & 0 deletions app/src/components/elements/ErrorLine.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from "react";
import "./ErrorLine.css";

export function ErrorLine({ message }) {
return <div className="error-line">{message}</div>;
}
File renamed without changes.
20 changes: 20 additions & 0 deletions app/src/components/elements/ErrorPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from "react";
import "./ErrorPage.css";
import { useTitle } from "../../hooks/useTitle";

const desc = {
404: "The page you are looking for does not exist",
403: "You are not allowed to access this resource",
500: "Something went terribly wrong. Try checking browser console for errors",
};

export function ErrorPage({ code }) {
useTitle("Page not found");

return (
<div id="error-page">
<p className="big">{code.toString()}</p>
<p className="desc">{desc[code.toString()]}</p>
</div>
);
}
2 changes: 1 addition & 1 deletion app/src/components/elements/list/ModelList.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from "react";
import ErrorLine from "../../error-line";
import Loading from "../../loading";
import {
Card,
Expand All @@ -12,6 +11,7 @@ import { Link } from "react-router-dom";
import { SystemName } from "../../reviews/SystemName";
import { DateLabel } from "../DateLabel";
import { ModelComplianceBadge } from "../ModelComplianceBadge";
import { ErrorLine } from "../ErrorLine";

export function ModelList({
models = [],
Expand Down
15 changes: 0 additions & 15 deletions app/src/components/error-line/ErrorLine.js

This file was deleted.

14 changes: 0 additions & 14 deletions app/src/components/error-line/ErrorLine.spec.js

This file was deleted.

3 changes: 0 additions & 3 deletions app/src/components/error-line/index.js

This file was deleted.

26 changes: 0 additions & 26 deletions app/src/components/error-page/ErrorPage.js

This file was deleted.

45 changes: 0 additions & 45 deletions app/src/components/error-page/ErrorPage.spec.js

This file was deleted.

3 changes: 0 additions & 3 deletions app/src/components/error-page/index.js

This file was deleted.

12 changes: 6 additions & 6 deletions app/src/components/model/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ import { PERMISSIONS } from "./constants";
import "./Model.css";
import { LeftPanel } from "./panels/left/LeftPanel";
import { RightPanel } from "./panels/right/RightPanel";
import { ErrorPage } from "../elements/ErrorPage";

export function Model() {
const dispatch = useDispatch();

const { id } = useParams("/model/:id");
const { data: model } = useGetModelQuery(id);
const { data: model, isError, error } = useGetModelQuery(id);

useEffect(() => {
model && dispatch(loadModel(model));
Expand All @@ -50,11 +51,10 @@ export function Model() {

// if write permission sync model changes (patch component) to the backend
useModelSync();
// useEffect(() => {
// if (id && writeAllowed) {
// return store.subscribe(useModelSyncListener(store, dispatch));
// }
// }, [store, id, writeAllowed]);

if (isError) {
return <ErrorPage code={error.originalStatus} />;
}

if (model?.id !== id) return <LoadingPage isLoading={true} />;

Expand Down
2 changes: 1 addition & 1 deletion app/src/components/model/New.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
useListModelsQuery,
} from "../../api/gram/model";
import { useGetSystemQuery } from "../../api/gram/system";
import ErrorLine from "../error-line";
import Loading from "../loading";
import "./New.css";
import InputLabel from "@mui/material/InputLabel";
Expand All @@ -17,6 +16,7 @@ import Select from "@mui/material/Select";
import TextField from "@mui/material/TextField";
import Button from "@mui/material/Button";
import Divider from "@mui/material/Divider";
import { ErrorLine } from "../elements/ErrorLine";

export function NewWizard() {
const [version, setVersion] = useState(
Expand Down
2 changes: 1 addition & 1 deletion app/src/components/model/panels/left/SystemProperties.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Card, CardContent, Skeleton, Typography } from "@mui/material";
import { uniqueId } from "lodash";
import { useGetSystemPropertiesQuery } from "../../../../api/gram/system-properties";
import ErrorLine from "../../../error-line";
import { ErrorLine } from "../../../elements/ErrorLine";

export function SystemProperties({ modelId }) {
const {
Expand Down
15 changes: 12 additions & 3 deletions app/src/components/system/System.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from "../../api/gram/system";
import { useTitle } from "../../hooks/useTitle";
import { ModelList } from "../elements/list/ModelList";
import ErrorPage from "../error-page";
import { ErrorPage } from "../elements/ErrorPage";
import Loading from "../loading";
import { PERMISSIONS } from "../model/constants";
import "./System.css";
Expand All @@ -19,15 +19,20 @@ export function System() {

const { data: permissions, isLoading: isLoadingPermissions } =
useGetSystemPermissionsQuery({ systemId });
const { data: system, isLoading: isLoadingSystem } = useGetSystemQuery({
const {
data: system,
isLoading: isLoadingSystem,
isError,
error,
} = useGetSystemQuery({
systemId,
});
const { data: models, isLoading: isLoadingModels } = useListModelsQuery({
filter: "system",
systemId,
});

useTitle(isLoadingSystem ? "Loading..." : "System: " + system.displayName);
useTitle(isLoadingSystem ? "Loading..." : "System: " + system?.displayName);

if (isLoadingPermissions || isLoadingSystem) {
return (
Expand All @@ -38,6 +43,10 @@ export function System() {
);
}

if (isError) {
return <ErrorPage code={error.originalStatus} />;
}

if (!permissions.includes(PERMISSIONS.READ)) {
return <ErrorPage code={403} />;
}
Expand Down

0 comments on commit 5b2b77d

Please sign in to comment.