Skip to content

Commit eae8c87

Browse files
committed
feat(defaultAppComponents): add custom 404 page
Fixes issues.redhat.com/browse/RHIDP-1317
1 parent 1f7b33d commit eae8c87

File tree

4 files changed

+118
-0
lines changed

4 files changed

+118
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { AppComponents } from '@backstage/core-plugin-api';
22

3+
import { NotFoundErrorPage } from '../ErrorPages/NotFoundErrorPage';
34
import { SignInPage } from '../SignInPage/SignInPage';
45

56
const defaultAppComponents: Partial<AppComponents> = {
67
SignInPage: props => <SignInPage {...props} />,
8+
NotFoundErrorPage: props => <NotFoundErrorPage {...props} />,
79
};
810

911
export default defaultAppComponents;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import Box from '@mui/material/Box';
2+
import Grid from '@mui/material/Grid';
3+
import Typography from '@mui/material/Typography';
4+
5+
import ErrorImage from './collaboration.png';
6+
7+
interface ErrorPageProps {
8+
/** The title to display. */
9+
title: React.ReactNode | string;
10+
/** The message to display. */
11+
message: React.ReactNode | string;
12+
/** Additional actions to display below the message. */
13+
actions?: React.ReactNode;
14+
/** Additional content to display below the message and above the actions. */
15+
children?: React.ReactNode;
16+
/** The source URL of the image to display. Defaults to a Red Hat-branded image. */
17+
image?: string;
18+
}
19+
20+
const ErrorPageGutters = {
21+
xs: 3,
22+
md: 6,
23+
lg: 9,
24+
xl: 12,
25+
};
26+
27+
export const ErrorPage = ({
28+
title,
29+
message,
30+
actions,
31+
image = ErrorImage,
32+
children,
33+
}: ErrorPageProps) => (
34+
<Grid container sx={{ flexGrow: 1 }} spacing={0}>
35+
<Grid
36+
item
37+
xs={12}
38+
md={6}
39+
sx={{
40+
display: 'flex',
41+
flexDirection: 'column',
42+
justifyContent: 'center',
43+
}}
44+
>
45+
<Box
46+
sx={{
47+
px: ErrorPageGutters,
48+
display: 'flex',
49+
flexDirection: 'column',
50+
gap: 3,
51+
}}
52+
>
53+
<Typography variant="h1" gutterBottom>
54+
{title}
55+
</Typography>
56+
57+
<Typography variant="subtitle1" gutterBottom>
58+
{message}
59+
</Typography>
60+
61+
{children}
62+
<div data-testid="error-page-actions">{actions}</div>
63+
</Box>
64+
</Grid>
65+
<Grid item xs={12} md={6} sx={{ display: 'flex' }}>
66+
<Box
67+
component="img"
68+
src={image}
69+
alt=""
70+
aria-hidden="true"
71+
sx={{
72+
maxWidth: '100%',
73+
maxHeight: '100vh',
74+
objectFit: 'contain',
75+
px: ErrorPageGutters,
76+
}}
77+
/>
78+
</Grid>
79+
</Grid>
80+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import type { AppComponents } from '@backstage/core-plugin-api';
2+
3+
import Button from '@material-ui/core/Button'; // workaround for broken-looking MUI5 button
4+
5+
import { ErrorPage } from './ErrorPage';
6+
7+
export const NotFoundErrorPage: AppComponents['NotFoundErrorPage'] = ({
8+
children,
9+
}) => (
10+
<ErrorPage
11+
title={
12+
<>
13+
<strong>404</strong> We couldn't find that page
14+
</>
15+
}
16+
message={
17+
<>
18+
Try adding an <strong>index.md</strong> file in the root of the docs
19+
directory of this repository.
20+
</>
21+
}
22+
actions={
23+
<Button
24+
variant="outlined"
25+
color="primary"
26+
onClick={() => {
27+
window.history.back();
28+
}}
29+
>
30+
Go back
31+
</Button>
32+
}
33+
>
34+
{children}
35+
</ErrorPage>
36+
);
Loading

0 commit comments

Comments
 (0)