1 import React from 'react';
2 import Crouton from 'react-crouton';
3 import NETCONF_ERRORS from './netConfErrors.js';
5 class SkyquakeNotification extends React.Component {
9 this.state.displayNotification = props.visible;
10 this.state.notificationMessage = '';
11 this.state.notificationType = 'error';
13 componentWillReceiveProps(props) {
15 this.processMessage(props.data);
17 this.setState({displayNotification: props.visible});
20 buildNetconfError(data) {
23 let info = JSON.parse(data);
24 let rpcError = info.body || info.errorMessage.body || info.errorMessage.error;
25 if (rpcError && typeof rpcError === 'string') {
26 const index = rpcError.indexOf('{');
28 rpcError = JSON.parse(rpcError.substr(index));
36 info = rpcError["rpc-reply"]["rpc-error"];
37 let errorTag = info['error-tag']
39 ${NETCONF_ERRORS[errorTag] && NETCONF_ERRORS[errorTag].description || 'Unknown NETCONF Error'}
40 PATH: ${info['error-path']}
41 INFO: ${JSON.stringify(info['error-info'])}
44 console.log('Unexpected string sent to buildNetconfError: ', e);
48 processMessage(data) {
50 displayNotification: true,
51 notificationMessage: data,
52 notificationType: 'error',
53 displayScreenLoader: false
55 if(typeof(data) == 'string') {
56 //netconf errors will be json strings
57 state.notificationMessage = this.buildNetconfError(data);
59 let message = data.msg || '';
61 state.notificationType = data.type;
64 message += " " + this.buildNetconfError(data.rpcError);
66 state.notificationMessage = message;
68 console.log('NOTIFICATION: ', state.notificationMessage)
72 const {displayNotification, notificationMessage, notificationType, ...state} = this.state;
76 message={notificationMessage}
77 type={notificationType}
78 hidden={!(displayNotification && notificationMessage)}
79 onDismiss={this.props.onDismiss}
85 SkyquakeNotification.defaultProps = {
87 onDismiss: function(){}
89 export default SkyquakeNotification;