ee8dd4f2cca56e84883c97deaa21e76a6f392b05
[aai/sparky-fe.git] / src / app / vnfSearch / VnfSearchNfRoleVisualization.jsx
1 /* eslint-disable max-len,max-len,max-len,max-len,max-len,max-len */
2 /*
3  * ============LICENSE_START===================================================
4  * SPARKY (AAI UI service)
5  * ============================================================================
6  * Copyright © 2017 AT&T Intellectual Property.
7  * Copyright © 2017 Amdocs
8  * All rights reserved.
9  * ============================================================================
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  * ============LICENSE_END=====================================================
22  *
23  * ECOMP and OpenECOMP are trademarks
24  * and service marks of AT&T Intellectual Property.
25  */
26
27 import React, {Component} from 'react';
28 import {connect} from 'react-redux';
29 import {
30   BarChart,
31   Bar,
32   XAxis,
33   YAxis,
34   CartesianGrid,
35   Tooltip,
36   ResponsiveContainer,
37 } from 'recharts';
38
39 import i18n from 'utils/i18n/i18n';
40
41 import {CHART_NF_ROLE} from 'app/vnfSearch/VnfSearchConstants.js';
42 import {COLOR_BLUE} from 'utils/GlobalConstants.js';
43
44 let mapStateToProps = ({vnfSearch}) => {
45   let {
46         processedNfRoleCountChartData = CHART_NF_ROLE.emptyData
47       } = vnfSearch;
48
49   return {
50     processedNfRoleCountChartData
51   };
52 };
53
54 class VnfSearchNfRoleVisualization extends Component {
55   static propTypes = {
56     processedNfRoleCountChartData: React.PropTypes.object
57   };
58
59   render() {
60     let {
61           processedNfRoleCountChartData
62         } = this.props;
63
64     let visualizationClass = 'visualizations';
65
66     if (processedNfRoleCountChartData.values ===
67       null ||
68       processedNfRoleCountChartData.values.size <=
69       0) {
70       visualizationClass = 'visualizations hidden';
71     }
72
73     const xAxisAttrName = 'x';
74     const yAxisAttrName = 'y';
75
76     return (
77       <div id='audit-visualizations' className={visualizationClass}>
78         <div className='visualization-charts'>
79           <div>
80             <h3>{i18n(CHART_NF_ROLE.title)}</h3>
81             <ResponsiveContainer width='100%' height={300}>
82               <BarChart data={processedNfRoleCountChartData.values}>
83                 <XAxis dataKey={xAxisAttrName}/>
84                 <YAxis/>
85                 <CartesianGrid strokeDasharray='3 3'/>
86                 <Tooltip/>
87                 <Bar name={i18n(CHART_NF_ROLE.yAxisLabel)}
88                      dataKey={yAxisAttrName} fill={COLOR_BLUE}/>
89               </BarChart>
90             </ResponsiveContainer>
91           </div>
92         </div>
93       </div>
94     );
95   }
96 }
97
98 export default connect(mapStateToProps)(VnfSearchNfRoleVisualization);