2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt odlux
4 * =================================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6 * =================================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software distributed under the License
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing permissions and limitations under
16 * ============LICENSE_END==========================================================================
18 import * as React from 'react';
19 import { withStyles, WithStyles, createStyles, Theme } from '@material-ui/core/styles';
21 import Modal from '@material-ui/core/Modal';
22 import Button from '@material-ui/core/Button';
23 import Card from '@material-ui/core/Card';
24 import CardActions from '@material-ui/core/CardActions';
25 import CardContent from '@material-ui/core/CardContent';
26 import Typography from '@material-ui/core/Typography';
28 import { ClearErrorInfoAction, RemoveErrorInfoAction } from '../actions/errorActions';
30 import connect, { Connect } from '../flux/connect';
32 const styles = (theme: Theme) => createStyles({
36 justifyContent: "center",
39 width: theme.spacing.unit * 50,
40 backgroundColor: theme.palette.background.paper,
41 boxShadow: theme.shadows[5],
42 padding: theme.spacing.unit * 4,
48 display: 'inline-block',
50 transform: 'scale(0.8)',
61 type ErrorDisplayProps = WithStyles<typeof styles> & Connect;
63 // function getModalStyle() {
64 // const top = 50 + rand();
65 // const left = 50 + rand();
69 // left: `${ left }%`,
70 // transform: `translate(-${ top }%, -${ left }%)`,
75 * Represents a compnent for formaing and displaying errors.
77 class ErrorDisplayComponent extends React.Component<ErrorDisplayProps> {
78 render(): JSX.Element {
79 const { classes, state } = this.props;
80 const errorInfo = state.framework.applicationState.errors.length && state.framework.applicationState.errors[state.framework.applicationState.errors.length - 1];
82 <Modal className={ classes.modal }
83 aria-labelledby="simple-modal-title"
84 aria-describedby="simple-modal-description"
85 open={ state.framework.applicationState.errors && state.framework.applicationState.errors.length > 0 }
86 onClose={ () => this.props.dispatch(new ClearErrorInfoAction()) }
89 <div className={ classes.paper }>
90 <Card className={ classes.card }>
92 <Typography className={ classes.title } color="textSecondary">
95 <Typography variant="headline" component="h2">
96 { errorInfo.error && errorInfo.error.toString() }
98 <Typography className={ classes.pos } color="textSecondary">
99 { errorInfo.message && errorInfo.message .toString() }
101 <Typography component="p">
102 { errorInfo.info && errorInfo.info.componentStack && errorInfo.info.componentStack.split('\n').map(line => {
103 return [line, <br />];
105 { errorInfo.info && errorInfo.info.extra && errorInfo.info.extra.split('\n').map(line => {
106 return [line, <br />];
111 <Button size="small" onClick={ () => this.props.dispatch(new RemoveErrorInfoAction(errorInfo)) } >Close</Button>
121 export const ErrorDisplay = withStyles(styles)(connect()(ErrorDisplayComponent));
122 export default ErrorDisplay;