Skip to content

Commit

Permalink
[3951] Provide an error page to redirect users in case of error
Browse files Browse the repository at this point in the history
Bug: #3951
Signed-off-by: Stéphane Bégaudeau <[email protected]>
  • Loading branch information
sbegaudeau committed Sep 5, 2024
1 parent e5fbf3c commit 0a4f6ba
Show file tree
Hide file tree
Showing 9 changed files with 179 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ A migration participant has been added to automatically keep compatible all diag
- https://github.com/eclipse-sirius/sirius-web/issues/3927[#3927] [sirius-web] Make the viewer object configurable
- https://github.com/eclipse-sirius/sirius-web/issues/3928[#3928] [sirius-web] Derive the read-only state from the project GraphQL query
- https://github.com/eclipse-sirius/sirius-web/issues/3932[#3932] [forms] Do not display the 'Delete' button (even disabled) for non-deletable lists
- https://github.com/eclipse-sirius/sirius-web/issues/3951[#3951] [sirius-web] Provide an error page to redirect users in case of error


== v2024.7.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
* Obeo - initial API and implementation
*******************************************************************************/
import Link from '@mui/material/Link';
import { makeStyles } from 'tss-react/mui';
import Typography from '@mui/material/Typography';
import { makeStyles } from 'tss-react/mui';
import { FooterProps } from './Footer.types';

const useFooterStyles = makeStyles()((theme) => ({
footer: {
display: 'flex',
justifyContent: 'center',
gap: theme.spacing(0.5),
margin: theme.spacing(2),
'& > *': {
marginLeft: theme.spacing(0.5),
Expand All @@ -31,7 +32,7 @@ export const SiriusWebFooter = ({}: FooterProps) => {
const { classes } = useFooterStyles();
return (
<footer className={classes.footer}>
<Typography variant="caption">&copy; {new Date().getFullYear()} Obeo. Powered by </Typography>
<Typography variant="caption">&copy; {new Date().getFullYear()} Obeo. Powered by</Typography>
<Link variant="caption" href="https://www.eclipse.dev/sirius" rel="noopener noreferrer" target="_blank">
Sirius Web
</Link>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ export {
navigationBarLeftContributionExtensionPoint,
navigationBarRightContributionExtensionPoint,
} from './navigationBar/NavigationBarExtensionPoints';
export { type NavigationBarMenuIconProps } from './navigationBar/NavigationBarMenu.types';
export {
type NavigationBarMenuIconProps,
type NavigationBarMenuItemProps,
} from './navigationBar/NavigationBarMenu.types';
export {
navigationBarMenuEntryExtensionPoint,
navigationBarMenuHelpURLExtensionPoint,
Expand All @@ -58,8 +61,13 @@ export type { UseCurrentProjectValue } from './views/edit-project/useCurrentProj
export type { GQLProject } from './views/edit-project/useProjectAndRepresentationMetadata.types';
export { DetailsView } from './views/edit-project/workbench-views/DetailsView';
export type { GQLDetailsEventPayload } from './views/edit-project/workbench-views/useDetailsViewSubscription.types';
export { ErrorView } from './views/error/ErrorView';
export { type ErrorMessageProvider } from './views/error/ErrorView.types';
export { errorMessageProvidersExtensionPoint } from './views/error/ErrorViewExtensionPoints';
export { type CreateProjectAreaCardProps } from './views/project-browser/create-projects-area/CreateProjectArea.types';
export { createProjectAreaCardExtensionPoint } from './views/project-browser/create-projects-area/CreateProjectAreaExtensionPoints';
export { ProjectActionButton } from './views/project-browser/list-projects-area/ProjectActionButton';
export { type ProjectActionButtonProps } from './views/project-browser/list-projects-area/ProjectActionButton.types';
export { projectActionButtonMenuItemExtensionPoint } from './views/project-browser/list-projects-area/ProjectActionButtonExtensionPoints';
export { type ProjectRowProps } from './views/project-browser/list-projects-area/ProjectRow.types';
export { projectsTableRowExtensionPoint } from './views/project-browser/list-projects-area/ProjectsTableExtensionPoints';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import Link from '@mui/material/Link';
import Toolbar from '@mui/material/Toolbar';
import Tooltip from '@mui/material/Tooltip';
import { emphasize } from '@mui/material/styles';
import { makeStyles } from 'tss-react/mui';
import { Link as RouterLink } from 'react-router-dom';
import { makeStyles } from 'tss-react/mui';
import { NavigationBarProps } from './NavigationBar.types';
import {
navigationBarIconExtensionPoint,
Expand Down Expand Up @@ -81,7 +81,7 @@ export const NavigationBar = ({ children }: NavigationBarProps) => {
<Toolbar className={classes.toolbar} variant="dense">
<div className={classes.left}>
<Tooltip title="Back to the homepage">
<Link component={RouterLink} to="/" className={classes.link} color="inherit">
<Link component={RouterLink} to="/projects" className={classes.link} color="inherit">
<IconButton className={classes.onDarkBackground} color="inherit">
<Icon />
</IconButton>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { useData } from '@eclipse-sirius/sirius-components-core';
import { Redirect, Route, Switch } from 'react-router-dom';
import { withErrorBoundary } from '../errors/ErrorBoundary';
import { EditProjectView } from '../views/edit-project/EditProjectView';
import { ErrorView } from '../views/error/ErrorView';
import { NewProjectView } from '../views/new-project/NewProjectView';
import { ProjectBrowser } from '../views/project-browser/ProjectBrowser';
import { ProjectSettingsView } from '../views/project-settings/ProjectSettingsView';
Expand All @@ -29,10 +30,11 @@ export const Router = () => {
<Route exact path="/projects" component={withErrorBoundary(ProjectBrowser)} />
<Route exact path="/projects/:projectId/edit/:representationId?" component={withErrorBoundary(EditProjectView)} />
<Route exact path="/projects/:projectId/settings" component={withErrorBoundary(ProjectSettingsView)} />
<Route exact path="/errors/:code" component={ErrorView} />
{routes.map((props, index) => (
<Route key={index} {...props} />
))}
<Redirect to="/projects" />
<Redirect to="/errors/404" />
</Switch>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/

import { useComponent, useData } from '@eclipse-sirius/sirius-components-core';
import ErrorOutlineIcon from '@mui/icons-material/ErrorOutline';
import Container from '@mui/material/Container';
import Link from '@mui/material/Link';
import Paper from '@mui/material/Paper';
import Typography from '@mui/material/Typography';
import { Link as RouterLink, useParams } from 'react-router-dom';
import { makeStyles } from 'tss-react/mui';
import { footerExtensionPoint } from '../../footer/FooterExtensionPoints';
import { NavigationBar } from '../../navigationBar/NavigationBar';
import { ErrorMessageProvider, ErrorViewParams } from './ErrorView.types';
import { errorMessageProvidersExtensionPoint } from './ErrorViewExtensionPoints';

const useErrorViewStyles = makeStyles()((theme) => ({
errorView: {
display: 'grid',
gridTemplateColumns: '1fr',
gridTemplateRows: 'min-content 1fr min-content',
minHeight: '100vh',
},
main: {
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
gap: theme.spacing(2),
height: '100%',
},
error: {
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
gap: theme.spacing(4),
paddingTop: theme.spacing(3),
paddingLeft: theme.spacing(2),
paddingRight: theme.spacing(2),
paddingBottom: theme.spacing(3),
minWidth: '500px',
},
title: {
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
gap: theme.spacing(1),
},
}));

const messageProvider = (code: string, errorMessageProviders: ErrorMessageProvider[]): string => {
let message: string | null = null;

let index: number = 0;
while (message === null && index < errorMessageProviders.length) {
const errorMessageProvider = errorMessageProviders[index];
message = errorMessageProvider(code);

index = index + 1;
}

// Fallback for the default messages
if (message === null) {
message = 'An unexpected error has occurred, please contact the server administrator for additional information';

if (code === '404') {
message = 'The content that you are looking for has not been found';
}
}

return message;
};

export const ErrorView = () => {
const { code } = useParams<ErrorViewParams>();
const { classes } = useErrorViewStyles();

const { data: errorMessageProviders } = useData(errorMessageProvidersExtensionPoint);
const message: string = messageProvider(code, errorMessageProviders);

const { Component: Footer } = useComponent(footerExtensionPoint);

return (
<div className={classes.errorView}>
<NavigationBar />
<Container maxWidth="sm">
<div className={classes.main}>
<Paper className={classes.error}>
<div className={classes.title}>
<ErrorOutlineIcon sx={{ fontSize: 40 }} />
<Typography variant="h2" align="center">
Error {code}
</Typography>
</div>
<Typography variant="body1" sx={{ fontSize: '1rem', textAlign: 'justify' }}>
{message}
</Typography>
</Paper>
<Link variant="body1" component={RouterLink} to="/projects">
Back to the homepage
</Link>
</div>
</Container>
<Footer />
</div>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/

export interface ErrorViewParams {
code: string;
}

export type ErrorMessageProvider = (code: string) => string | null;
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/

import { DataExtensionPoint } from '@eclipse-sirius/sirius-components-core';
import { ErrorMessageProvider } from './ErrorView.types';

export const errorMessageProvidersExtensionPoint: DataExtensionPoint<Array<ErrorMessageProvider>> = {
identifier: 'error#messageProviders',
fallback: [],
};
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ const createProjectMutation = gql`
`;

const useNewProjectViewStyles = makeStyles()((theme) => ({
newProjectViewContainer: {
display: 'flex',
flexDirection: 'column',
paddingTop: theme.spacing(8),
},
newProjectView: {
display: 'grid',
gridTemplateColumns: '1fr',
Expand All @@ -68,6 +63,11 @@ const useNewProjectViewStyles = makeStyles()((theme) => ({
paddingTop: theme.spacing(3),
paddingBottom: theme.spacing(3),
},
newProjectViewContainer: {
display: 'flex',
flexDirection: 'column',
paddingTop: theme.spacing(8),
},
titleContainer: {
display: 'flex',
flexDirection: 'column',
Expand Down

0 comments on commit 0a4f6ba

Please sign in to comment.