Skip to content

Commit 1d76977

Browse files
committed
feat(RHIDP-1317): Add custom 404 page
1 parent 1f7b33d commit 1d76977

File tree

4 files changed

+66
-0
lines changed

4 files changed

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

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

0 commit comments

Comments
 (0)