1 import * as React from 'react';
2 import { withStyles, WithStyles, createStyles, Theme } from '@material-ui/core/styles';
4 import Modal from '@material-ui/core/Modal';
5 import Button from '@material-ui/core/Button';
6 import Card from '@material-ui/core/Card';
7 import CardActions from '@material-ui/core/CardActions';
8 import CardContent from '@material-ui/core/CardContent';
9 import Typography from '@material-ui/core/Typography';
11 import { ClearErrorInfoAction, RemoveErrorInfoAction } from '../actions/errorActions';
13 import connect, { Connect } from '../flux/connect';
15 const styles = (theme: Theme) => createStyles({
19 justifyContent: "center",
22 width: theme.spacing.unit * 50,
23 backgroundColor: theme.palette.background.paper,
24 boxShadow: theme.shadows[5],
25 padding: theme.spacing.unit * 4,
31 display: 'inline-block',
33 transform: 'scale(0.8)',
44 type ErrorDisplayProps = WithStyles<typeof styles> & Connect;
46 // function getModalStyle() {
47 // const top = 50 + rand();
48 // const left = 50 + rand();
52 // left: `${ left }%`,
53 // transform: `translate(-${ top }%, -${ left }%)`,
58 * Represents a compnent for formaing and displaying errors.
60 class ErrorDisplayComponent extends React.Component<ErrorDisplayProps> {
61 render(): JSX.Element {
62 const { classes, state } = this.props;
63 const errorInfo = state.framework.applicationState.errors.length && state.framework.applicationState.errors[state.framework.applicationState.errors.length - 1];
65 <Modal className={ classes.modal }
66 aria-labelledby="simple-modal-title"
67 aria-describedby="simple-modal-description"
68 open={ state.framework.applicationState.errors && state.framework.applicationState.errors.length > 0 }
69 onClose={ () => this.props.dispatch(new ClearErrorInfoAction()) }
72 <div className={ classes.paper }>
73 <Card className={ classes.card }>
75 <Typography className={ classes.title } color="textSecondary">
78 <Typography variant="headline" component="h2">
79 { errorInfo.error && errorInfo.error.toString() }
81 <Typography className={ classes.pos } color="textSecondary">
82 { errorInfo.message && errorInfo.message .toString() }
84 <Typography component="p">
85 { errorInfo.info && errorInfo.info.componentStack && errorInfo.info.componentStack.split('\n').map(line => {
86 return [line, <br />];
88 { errorInfo.info && errorInfo.info.extra && errorInfo.info.extra.split('\n').map(line => {
89 return [line, <br />];
94 <Button size="small" onClick={ () => this.props.dispatch(new RemoveErrorInfoAction(errorInfo)) } >Close</Button>
104 export const ErrorDisplay = withStyles(styles)(connect()(ErrorDisplayComponent));
105 export default ErrorDisplay;