Add Statistics to NetworkMap
[ccsdk/features.git] / sdnr / wt / odlux / apps / networkMapApp / src / components / statistics.tsx
1 /**
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt odlux
4  * =================================================================================================
5  * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. All rights reserved.
6  * =================================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software distributed under the License
13  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14  * or implied. See the License for the specific language governing permissions and limitations under
15  * the License.
16  * ============LICENSE_END==========================================================================
17  */
18
19 import * as React from 'react';
20 import { Paper, Typography, Tooltip } from '@material-ui/core';
21 import InfoIcon from '@material-ui/icons/Info';
22
23 import { IApplicationStoreState } from '../../../../framework/src/store/applicationStore';
24 import connect, { IDispatcher, Connect } from '../../../../framework/src/flux/connect';
25
26 type props = Connect<typeof mapStateToProps, typeof mapDispatchToProps>;
27
28 const mapStateToProps = (state: IApplicationStoreState) => ({
29     linkCount: state.network.map.statistics.links,
30     siteCount: state.network.map.statistics.sites,
31     isTopoServerReachable: state.network.connectivity.isToplogyServerAvailable,
32     isTileServerReachable: state.network.connectivity.isTileServerAvailable,
33
34 });
35
36 const mapDispatchToProps = (dispatcher: IDispatcher) => ({
37 });
38
39 const Statistics: React.FunctionComponent<props> = (props: props) =>{
40
41     const reachabe = props.isTopoServerReachable && props.isTileServerReachable;
42
43
44     return (<Paper style={{ padding: 5, position: 'absolute', display: 'flex', flexDirection: "column", top: 70, width: 200, marginLeft: 5 }}>
45     <div style={{ display: 'flex', flexDirection: "row" }}>
46         <Typography style={{ fontWeight: "bold", flex: "1", color: reachabe ? "black" : "lightgrey" }} >Statistics</Typography>
47         <Tooltip style={{ alignSelf: "flex-end" }} title="Gets updated when the map stops moving.">
48             <InfoIcon fontSize="small" />
49         </Tooltip>
50     </div>
51
52     <Typography style={{ color: reachabe ? "black" : "lightgrey" }}>Sites: {props.siteCount}</Typography>
53     <Typography style={{ color: reachabe ? "black" : "lightgrey" }}>Links: {props.linkCount}</Typography>
54 </Paper>)
55 }
56
57 export default connect(mapStateToProps, mapDispatchToProps)(Statistics);