2 * ============LICENSE_START===================================================
3 * SPARKY (AAI UI service)
4 * ============================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
8 * ============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=====================================================
22 * ECOMP and OpenECOMP are trademarks
23 * and service marks of AT&T Intellectual Property.
26 import React, {Component} from 'react';
27 import {connect} from 'react-redux';
28 import Grid from 'react-bootstrap/lib/Grid';
29 import Row from 'react-bootstrap/lib/Row';
30 import Col from 'react-bootstrap/lib/Col';
31 import Clearfix from 'react-bootstrap/lib/Clearfix';
33 LineChart, Line, XAxis, YAxis, CartesianGrid,
34 Tooltip, ResponsiveContainer, Brush
36 import i18n from 'utils/i18n/i18n';
38 import TopographicMap from 'generic-components/map/TopographicMap.jsx';
40 onTopographicMapMounted, onCountByTypeLoad, onLoadTotalCountByDate
41 } from 'app/inventory/InventoryActions.js';
44 TOTAL_ENTITY_COUNTS_BY_DATE_CHART,
45 COMPLEX_BY_LOCATION_TITLE,
46 ENTITIES_BY_TYPE_TITLE,
47 TOTAL_ENTITY_COUNT_TITLE
48 } from 'app/inventory/InventoryConstants.js';
49 import InlineMessage from 'generic-components/InlineMessage/InlineMessage.jsx';
50 import PaginatedTable from 'generic-components/paginatedTable/PaginatedTable.jsx';
52 dateFormatLocalTimeZoneMMDDYYYY, getTicks, getTicksData, sortDataByField
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 dateFormatLocalTimeZoneMMDDYYYY(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={dateFormatLocalTimeZoneMMDDYYYY}/>
167 <CartesianGrid strokeDasharray='3 3'/>
168 <Tooltip labelFormatter={dateFormatLocalTimeZoneMMDDYYYY}/>
169 <Brush dataKey={xAxisAttrName}
170 tickFormatter={dateFormatLocalTimeZoneMMDDYYYY}
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);