[AAI-92 Amsterdam] Update license
[aai/sparky-fe.git] / src / app / tierSupport / selectedNodeDetails / SelectedNodeDetails.jsx
1 /*
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017 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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  */
23 import {connect} from 'react-redux';
24 import React, {Component} from 'react';
25 import Table from 'react-bootstrap/lib/Table';
26 import i18n from 'utils/i18n/i18n';
27 import {
28   SELECTED_NODE_TITLE,
29   NO_SELECTION,
30   SELECTED_NODE_TABLE_COLUMN_NAMES
31 } from 'app/tierSupport/selectedNodeDetails/SelectedNodeDetailsConstants.js';
32
33 let mapStateToProps = ({tierSupport: {selectedNodeDetails}}) => {
34   let {nodeData = [], nodeType = '', uid = ''} = selectedNodeDetails;
35
36   return {
37     nodeData,
38     nodeType,
39     uid
40   };
41 };
42
43 class SelectedNodeDetails extends Component {
44   static propTypes = {
45     nodeData: React.PropTypes.array,
46     nodeType: React.PropTypes.string,
47     uid: React.PropTypes.string
48   };
49
50   render() {
51     const {nodeData, nodeType, uid} = this.props;
52
53     let tableClass = 'ts-selected-node-table';
54     let noSelectionMessageClass = 'hidden';
55     let tableColumns = [];
56     let tableRows = [];
57
58     if (Object.keys(nodeData).length > 0) {
59       let cellClassName = '';
60       for (let i = 1; i <= SELECTED_NODE_TABLE_COLUMN_NAMES.length; i++) {
61         cellClassName = (i % 2 ? 'left-column-cell' : 'right-column-cell');
62         tableColumns.push(<th className={cellClassName} key={i}>
63           {i18n(SELECTED_NODE_TABLE_COLUMN_NAMES[i - 1])}
64         </th>);
65       }
66
67       for (var key in nodeData) {
68         let value = nodeData[key];
69         tableRows.push(
70           <tr key={key}>
71             <td className='left-column-cell'>{key}</td>
72             <td className='right-column-cell'>{value}</td>
73           </tr>
74         );
75       }
76     } else {
77       tableClass = 'hidden';
78       noSelectionMessageClass = '';
79     }
80
81     return (
82       <div className='ts-selected-node-details'>
83         <h1>{i18n(SELECTED_NODE_TITLE)}</h1>
84         <h2>{nodeType}</h2>
85         <span>{uid}</span>
86         <Table bsClass={tableClass}>
87           <thead>
88           <tr>
89             {tableColumns}
90           </tr>
91           </thead>
92           <tbody>
93           {tableRows}
94           </tbody>
95         </Table>
96         <p className={noSelectionMessageClass}>{i18n(NO_SELECTION)}</p>
97       </div>
98     );
99   }
100 }
101 export default connect(mapStateToProps)(SelectedNodeDetails);