1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
/*
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
* Copyright © 2017 AT&T Intellectual Property. All rights reserved.
* Copyright © 2017 Amdocs
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
*
* ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
import React, {Component} from 'react';
import {connect} from 'react-redux';
import Grid from 'react-bootstrap/lib/Grid';
import Row from 'react-bootstrap/lib/Row';
import Col from 'react-bootstrap/lib/Col';
import Clearfix from 'react-bootstrap/lib/Clearfix';
import {
LineChart, Line, XAxis, YAxis, CartesianGrid,
Tooltip, ResponsiveContainer, Brush
} from 'recharts';
import i18n from 'utils/i18n/i18n';
import TopographicMap from 'generic-components/map/TopographicMap.jsx';
import {
onTopographicMapMounted, onCountByTypeLoad, onLoadTotalCountByDate
} from 'app/inventory/InventoryActions.js';
import {
INVENTORY_TITLE,
TOTAL_ENTITY_COUNTS_BY_DATE_CHART,
COMPLEX_BY_LOCATION_TITLE,
ENTITIES_BY_TYPE_TITLE,
TOTAL_ENTITY_COUNT_TITLE
} from 'app/inventory/InventoryConstants.js';
import InlineMessage from 'generic-components/InlineMessage/InlineMessage.jsx';
import PaginatedTable from 'generic-components/paginatedTable/PaginatedTable.jsx';
import {
dateFormatLocalTimeZoneMMDDYYYY, getTicks, getTicksData, sortDataByField
} from 'utils/DateTimeChartUtil.js';
import TitledContainer from 'generic-components/titledContainer/TitledContainer.jsx';
import {COLOR_BLUE} from 'utils/GlobalConstants.js';
const mapStateToProps = ({inventoryReducer}) => {
let {
mapPlotPoints = [], countByType = [], countByDate = [],
feedbackMsgText = '', feedbackMsgSeverity = ''
} = inventoryReducer;
return {
mapPlotPoints,
countByType,
countByDate,
feedbackMsgText,
feedbackMsgSeverity
};
};
const mapActionToProps = (dispatch) => {
return {
onMountQueryTopographicVisualization: (requestObject) => {
dispatch(onTopographicMapMounted(requestObject));
}, onLoadCountByType: () => {
dispatch(onCountByTypeLoad());
}, onLoadTotalCountByDate: () => {
dispatch(onLoadTotalCountByDate());
}
};
};
class Inventory extends Component {
componentDidMount() {
let requestObject = {
entityType: 'complex'
};
this.props.onMountQueryTopographicVisualization(requestObject);
this.props.onLoadCountByType();
this.props.onLoadTotalCountByDate();
}
render() {
let {
mapPlotPoints, countByType, onLoadCountByType, countByDate,
feedbackMsgSeverity, feedbackMsgText
} = this.props;
let tableDefinition = {
key: {name: 'Entity'},
doc_count: {name: 'Count'}
};
let paginationClasses = 'audit-pagination';
let tableClasses =
'inventory-table table table-striped table-bordered table-condensed';
const xAxisAttrName = 'date';
const yAxisAttrName = 'count';
const sortedData = sortDataByField(countByDate, xAxisAttrName);
const ticksArr = getTicks(sortedData, xAxisAttrName);
const completeData = getTicksData(sortedData, ticksArr, xAxisAttrName);
const completeSortedData = sortDataByField(completeData, xAxisAttrName);
let totalEntities = 0;
let lastDate = '';
if (sortedData.length > 0) {
lastDate =
dateFormatLocalTimeZoneMMDDYYYY(sortedData[sortedData.length - 1]
.date);
totalEntities = sortedData[sortedData.length - 1].count;
}
return (
<div>
<div className='secondary-header'>
<span className='secondary-title'>{i18n(INVENTORY_TITLE)}</span>
<InlineMessage level={feedbackMsgSeverity}
messageTxt={feedbackMsgText}/>
</div>
<Grid fluid={true}>
<Row>
<Col xs={3} sm={3} md={3}>
<TitledContainer title={TOTAL_ENTITY_COUNT_TITLE}>
<div className='total-entity-count'>
{totalEntities}
<span>{lastDate}</span>
</div>
</TitledContainer>
<TitledContainer title={ENTITIES_BY_TYPE_TITLE}>
<PaginatedTable
tableHeaders={tableDefinition}
displayHeader={false}
tableData={countByType}
activePage={1}
pageCount={1}
onPageIndexSelected={ () => onLoadCountByType()}
paginationClass={paginationClasses}
tableClass={tableClasses}
maxPaginationLinks={25}/>
</TitledContainer>
</Col>
<Clearfix visibleSmBlock/>
<Col xs={9} sm={9} md={9}>
<TitledContainer
title={i18n(TOTAL_ENTITY_COUNTS_BY_DATE_CHART.title)}>
<ResponsiveContainer width='100%' height={250}>
<LineChart data={completeSortedData}
margin={{
top: 10, bottom: 10, left: 10, right: 70
}}>
<XAxis dataKey={xAxisAttrName} ticks={ticksArr}
tickCount={ticksArr.length}
tickFormatter={dateFormatLocalTimeZoneMMDDYYYY}/>
<YAxis/>
<CartesianGrid strokeDasharray='3 3'/>
<Tooltip labelFormatter={dateFormatLocalTimeZoneMMDDYYYY}/>
<Brush dataKey={xAxisAttrName}
tickFormatter={dateFormatLocalTimeZoneMMDDYYYY}
height={20} stroke={COLOR_BLUE}/>
<Line
name={i18n(TOTAL_ENTITY_COUNTS_BY_DATE_CHART.yAxisLabel)}
type='monotone' dataKey={yAxisAttrName}
stroke={COLOR_BLUE}
connectNulls={true} activeDot={{r: 6}}/>
</LineChart>
</ResponsiveContainer>
</TitledContainer>
<TitledContainer title={i18n(COMPLEX_BY_LOCATION_TITLE)}>
<TopographicMap pointArray={mapPlotPoints}/>
</TitledContainer>
</Col>
</Row>
</Grid>
</div>
);
}
}
export default connect(mapStateToProps, mapActionToProps)(Inventory);
|