2 * ============LICENSE_START=======================================================
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
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 import React, {Component} from 'react';
22 import {connect} from 'react-redux';
23 import Grid from 'react-bootstrap/lib/Grid';
24 import Row from 'react-bootstrap/lib/Row';
25 import Col from 'react-bootstrap/lib/Col';
26 import Clearfix from 'react-bootstrap/lib/Clearfix';
28 LineChart, Line, XAxis, YAxis, CartesianGrid,
29 Tooltip, ResponsiveContainer, Brush
31 import i18n from 'utils/i18n/i18n';
33 import TopographicMap from 'generic-components/map/TopographicMap.jsx';
35 onTopographicMapMounted, onCountByTypeLoad, onLoadTotalCountByDate
36 } from 'app/inventory/InventoryActions.js';
39 TOTAL_ENTITY_COUNTS_BY_DATE_CHART,
40 COMPLEX_BY_LOCATION_TITLE,
41 ENTITIES_BY_TYPE_TITLE,
42 TOTAL_ENTITY_COUNT_TITLE
43 } from 'app/inventory/InventoryConstants.js';
44 import InlineMessage from 'generic-components/InlineMessage/InlineMessage.jsx';
45 import PaginatedTable from 'generic-components/paginatedTable/PaginatedTable.jsx';
47 dateFormatLocalTimeZoneYYYYMMDD,
51 } from 'utils/DateTimeChartUtil.js';
52 import TitledContainer from 'generic-components/titledContainer/TitledContainer.jsx';
53 import {COLOR_BLUE} from 'utils/GlobalConstants.js';
55 const mapStateToProps = ({inventoryReducer}) => {
57 mapPlotPoints = [], countByType = [], countByDate = [],
58 feedbackMsgText = '', feedbackMsgSeverity = ''
70 const mapActionToProps = (dispatch) => {
72 onMountQueryTopographicVisualization: (requestObject) => {
73 dispatch(onTopographicMapMounted(requestObject));
74 }, onLoadCountByType: () => {
75 dispatch(onCountByTypeLoad());
76 }, onLoadTotalCountByDate: () => {
77 dispatch(onLoadTotalCountByDate());
82 class Inventory extends Component {
88 this.props.onMountQueryTopographicVisualization(requestObject);
89 this.props.onLoadCountByType();
90 this.props.onLoadTotalCountByDate();
95 mapPlotPoints, countByType, onLoadCountByType, countByDate,
96 feedbackMsgSeverity, feedbackMsgText
99 let tableDefinition = {
100 key: {name: 'Entity'},
101 doc_count: {name: 'Count'}
103 let paginationClasses = 'audit-pagination';
105 'inventory-table table table-striped table-bordered table-condensed';
107 const xAxisAttrName = 'date';
108 const yAxisAttrName = 'count';
109 const sortedData = sortDataByField(countByDate, xAxisAttrName);
110 const ticksArr = getTicks(sortedData, xAxisAttrName);
111 const completeData = getTicksData(sortedData, ticksArr, xAxisAttrName);
112 const completeSortedData = sortDataByField(completeData, xAxisAttrName);
114 let totalEntities = 0;
116 if (sortedData.length > 0) {
118 dateFormatLocalTimeZoneYYYYMMDD(sortedData[sortedData.length - 1]
120 totalEntities = sortedData[sortedData.length - 1].count;
125 <div className='secondary-header'>
126 <span className='secondary-title'>{i18n(INVENTORY_TITLE)}</span>
127 <InlineMessage level={feedbackMsgSeverity}
128 messageTxt={feedbackMsgText}/>
132 <Col xs={3} sm={3} md={3}>
133 <TitledContainer title={TOTAL_ENTITY_COUNT_TITLE}>
134 <div className='total-entity-count'>
136 <span>{lastDate}</span>
139 <TitledContainer title={ENTITIES_BY_TYPE_TITLE}>
141 tableHeaders={tableDefinition}
142 displayHeader={false}
143 tableData={countByType}
146 onPageIndexSelected={ () => onLoadCountByType()}
147 paginationClass={paginationClasses}
148 tableClass={tableClasses}
149 maxPaginationLinks={25}/>
152 <Clearfix visibleSmBlock/>
153 <Col xs={9} sm={9} md={9}>
155 title={i18n(TOTAL_ENTITY_COUNTS_BY_DATE_CHART.title)}>
156 <ResponsiveContainer width='100%' height={250}>
157 <LineChart data={completeSortedData}
159 top: 10, bottom: 10, left: 10, right: 70
161 <XAxis dataKey={xAxisAttrName} ticks={ticksArr}
162 tickCount={ticksArr.length}
163 tickFormatter={dateFormatLocalTimeZoneYYYYMMDD}/>
165 <CartesianGrid strokeDasharray='3 3'/>
166 <Tooltip labelFormatter={dateFormatLocalTimeZoneYYYYMMDD}/>
167 <Brush dataKey={xAxisAttrName}
168 tickFormatter={dateFormatLocalTimeZoneYYYYMMDD}
169 height={20} stroke={COLOR_BLUE}/>
171 name={i18n(TOTAL_ENTITY_COUNTS_BY_DATE_CHART.yAxisLabel)}
172 type='monotone' dataKey={yAxisAttrName}
174 connectNulls={true} activeDot={{r: 6}}/>
176 </ResponsiveContainer>
178 <TitledContainer title={i18n(COMPLEX_BY_LOCATION_TITLE)}>
179 <TopographicMap pointArray={mapPlotPoints}/>
188 export default connect(mapStateToProps, mapActionToProps)(Inventory);