2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 import React, {Component} from 'react';
24 import {connect} from 'react-redux';
25 import Grid from 'react-bootstrap/lib/Grid';
26 import Row from 'react-bootstrap/lib/Row';
27 import Col from 'react-bootstrap/lib/Col';
28 import Clearfix from 'react-bootstrap/lib/Clearfix';
30 LineChart, Line, XAxis, YAxis, CartesianGrid,
31 Tooltip, ResponsiveContainer, Brush
33 import i18n from 'utils/i18n/i18n';
35 import TopographicMap from 'generic-components/map/TopographicMap.jsx';
37 onTopographicMapMounted, onCountByTypeLoad, onLoadTotalCountByDate
38 } from 'app/inventory/InventoryActions.js';
41 TOTAL_ENTITY_COUNTS_BY_DATE_CHART,
42 COMPLEX_BY_LOCATION_TITLE,
43 ENTITIES_BY_TYPE_TITLE,
44 TOTAL_ENTITY_COUNT_TITLE
45 } from 'app/inventory/InventoryConstants.js';
46 import InlineMessage from 'generic-components/InlineMessage/InlineMessage.jsx';
47 import PaginatedTable from 'generic-components/paginatedTable/PaginatedTable.jsx';
49 dateFormatLocalTimeZoneYYYYMMDD,
53 } from 'utils/DateTimeChartUtil.js';
54 import TitledContainer from 'generic-components/titledContainer/TitledContainer.jsx';
55 import {COLOR_BLUE} from 'utils/GlobalConstants.js';
57 const mapStateToProps = ({inventoryReducer}) => {
59 mapPlotPoints = [], countByType = [], countByDate = [],
60 feedbackMsgText = '', feedbackMsgSeverity = ''
72 const mapActionToProps = (dispatch) => {
74 onMountQueryTopographicVisualization: (requestObject) => {
75 dispatch(onTopographicMapMounted(requestObject));
76 }, onLoadCountByType: () => {
77 dispatch(onCountByTypeLoad());
78 }, onLoadTotalCountByDate: () => {
79 dispatch(onLoadTotalCountByDate());
84 class Inventory extends Component {
90 this.props.onMountQueryTopographicVisualization(requestObject);
91 this.props.onLoadCountByType();
92 this.props.onLoadTotalCountByDate();
97 mapPlotPoints, countByType, onLoadCountByType, countByDate,
98 feedbackMsgSeverity, feedbackMsgText
101 let tableDefinition = {
102 key: {name: 'Entity'},
103 doc_count: {name: 'Count'}
105 let paginationClasses = 'audit-pagination';
107 'inventory-table table table-striped table-bordered table-condensed';
109 const xAxisAttrName = 'date';
110 const yAxisAttrName = 'count';
111 const sortedData = sortDataByField(countByDate, xAxisAttrName);
112 const ticksArr = getTicks(sortedData, xAxisAttrName);
113 const completeData = getTicksData(sortedData, ticksArr, xAxisAttrName);
114 const completeSortedData = sortDataByField(completeData, xAxisAttrName);
116 let totalEntities = 0;
118 if (sortedData.length > 0) {
120 dateFormatLocalTimeZoneYYYYMMDD(sortedData[sortedData.length - 1]
122 totalEntities = sortedData[sortedData.length - 1].count;
127 <div className='secondary-header'>
128 <span className='secondary-title'>{i18n(INVENTORY_TITLE)}</span>
129 <InlineMessage level={feedbackMsgSeverity}
130 messageTxt={feedbackMsgText}/>
134 <Col xs={3} sm={3} md={3}>
135 <TitledContainer title={TOTAL_ENTITY_COUNT_TITLE}>
136 <div className='total-entity-count'>
138 <span>{lastDate}</span>
141 <TitledContainer title={ENTITIES_BY_TYPE_TITLE}>
143 tableHeaders={tableDefinition}
144 displayHeader={false}
145 tableData={countByType}
148 onPageIndexSelected={ () => onLoadCountByType()}
149 paginationClass={paginationClasses}
150 tableClass={tableClasses}
151 maxPaginationLinks={25}/>
154 <Clearfix visibleSmBlock/>
155 <Col xs={9} sm={9} md={9}>
157 title={i18n(TOTAL_ENTITY_COUNTS_BY_DATE_CHART.title)}>
158 <ResponsiveContainer width='100%' height={250}>
159 <LineChart data={completeSortedData}
161 top: 10, bottom: 10, left: 10, right: 70
163 <XAxis dataKey={xAxisAttrName} ticks={ticksArr}
164 tickCount={ticksArr.length}
165 tickFormatter={dateFormatLocalTimeZoneYYYYMMDD}/>
167 <CartesianGrid strokeDasharray='3 3'/>
168 <Tooltip labelFormatter={dateFormatLocalTimeZoneYYYYMMDD}/>
169 <Brush dataKey={xAxisAttrName}
170 tickFormatter={dateFormatLocalTimeZoneYYYYMMDD}
171 height={20} stroke={COLOR_BLUE}/>
173 name={i18n(TOTAL_ENTITY_COUNTS_BY_DATE_CHART.yAxisLabel)}
174 type='monotone' dataKey={yAxisAttrName}
176 connectNulls={true} activeDot={{r: 6}}/>
178 </ResponsiveContainer>
180 <TitledContainer title={i18n(COMPLEX_BY_LOCATION_TITLE)}>
181 <TopographicMap pointArray={mapPlotPoints}/>
190 export default connect(mapStateToProps, mapActionToProps)(Inventory);