changed the header and license
[aai/sparky-fe.git] / src / app / tierSupport / launchExternalResource / LaunchExternalResource.jsx
1 /*
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017-2018 Amdocs
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21 import {connect} from 'react-redux';
22 import React, {Component} from 'react';
23 import {isEmpty} from 'lodash';
24 import Button from 'react-bootstrap/lib/Button.js';
25
26 let mapStateToProps = ({tierSupport: {launchExternalResourceReducer}}) => {
27   let {externalResourcePayload = {}} = launchExternalResourceReducer;
28
29   return {
30     externalResourcePayload
31   };
32 };
33
34 class LaunchExternalResource extends Component {
35   static propTypes = {
36     externalResourcePayload: React.PropTypes.object
37   };
38
39   render() {
40     const {externalResourcePayload} = this.props;
41
42     let launchExternalResourceClass = 'hidden';
43     if(!isEmpty(externalResourcePayload) && (externalResourcePayload.message.payload.params.objectName.length > 0)){
44       launchExternalResourceClass = '';
45     }
46
47     return (
48       <div className={launchExternalResourceClass}>
49         <Button
50           bsClass='launch-external-resource-button'
51           onClick={this.handleClick} />
52       </div>
53     );
54   }
55   handleClick = () => {
56     var getWindowUrl = function (url) {
57       var split = url.split('/');
58       return split[0] + '//' + split[2];
59     };
60     if(document.referrer) {
61       window.parent.postMessage(JSON.stringify(this.props.externalResourcePayload), getWindowUrl(document.referrer));
62     }
63   }
64 }
65 export default connect(mapStateToProps)(LaunchExternalResource);