X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=skyquake%2Fframework%2Fwidgets%2Fskyquake_notification%2FskyquakeNotification.jsx;fp=skyquake%2Fframework%2Fwidgets%2Fskyquake_notification%2FskyquakeNotification.jsx;h=c8ce1577c4920fbd16e8d6630691db9534783681;hb=03156e335275de1dafbc2a816e98006afdf249bf;hp=0000000000000000000000000000000000000000;hpb=f2dc2462571800e62cba969964de621dca09299c;p=osm%2FUI.git diff --git a/skyquake/framework/widgets/skyquake_notification/skyquakeNotification.jsx b/skyquake/framework/widgets/skyquake_notification/skyquakeNotification.jsx new file mode 100644 index 000000000..c8ce1577c --- /dev/null +++ b/skyquake/framework/widgets/skyquake_notification/skyquakeNotification.jsx @@ -0,0 +1,89 @@ +import React from 'react'; +import Crouton from 'react-crouton'; +import NETCONF_ERRORS from './netConfErrors.js'; + +class SkyquakeNotification extends React.Component { + constructor(props) { + super(props); + this.state = {}; + this.state.displayNotification = props.visible; + this.state.notificationMessage = ''; + this.state.notificationType = 'error'; + } + componentWillReceiveProps(props) { + if(props.visible) { + this.processMessage(props.data); + } else { + this.setState({displayNotification: props.visible}); + } + } + buildNetconfError(data) { + let error = data; + try { + let info = JSON.parse(data); + let rpcError = info.body || info.errorMessage.body || info.errorMessage.error; + if (rpcError && typeof rpcError === 'string') { + const index = rpcError.indexOf('{'); + if (index >= 0) { + rpcError = JSON.parse(rpcError.substr(index)); + } else { + return rpcError; + } + } + if (!rpcError) { + return error; + } + info = rpcError["rpc-reply"]["rpc-error"]; + let errorTag = info['error-tag'] + error = ` + ${NETCONF_ERRORS[errorTag] && NETCONF_ERRORS[errorTag].description || 'Unknown NETCONF Error'} + PATH: ${info['error-path']} + INFO: ${JSON.stringify(info['error-info'])} + ` + } catch (e) { + console.log('Unexpected string sent to buildNetconfError: ', e); + } + return error; + } + processMessage(data) { + let state = { + displayNotification: true, + notificationMessage: data, + notificationType: 'error', + displayScreenLoader: false + } + if(typeof(data) == 'string') { + //netconf errors will be json strings + state.notificationMessage = this.buildNetconfError(data); + } else { + let message = data.msg || ''; + if(data.type) { + state.notificationType = data.type; + } + if(data.rpcError){ + message += " " + this.buildNetconfError(data.rpcError); + } + state.notificationMessage = message; + } + console.log('NOTIFICATION: ', state.notificationMessage) + this.setState(state); + } + render() { + const {displayNotification, notificationMessage, notificationType, ...state} = this.state; + return ( +