2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt odlux
4 * =================================================================================================
5 * Copyright (C) 2019 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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
16 * ============LICENSE_END==========================================================================
18 import React from 'react';
19 import { RouteComponentProps, withRouter } from 'react-router-dom';
21 import { ColumnModel, ColumnType, MaterialTable, MaterialTableCtorType } from '../../../../framework/src/components/material-table';
22 import { connect, Connect, IDispatcher } from '../../../../framework/src/flux/connect';
23 import { IApplicationStoreState } from '../../../../framework/src/store/applicationStore';
25 import { SetFilterVisibility, SetSubViewAction } from '../actions/toggleActions';
26 import { createTransmissionPowerActions, createTransmissionPowerProperties } from '../handlers/transmissionPowerHandler';
27 import { IDataSet, IDataSetsObject } from '../models/chartTypes';
28 import { TransmissionPowerDatabaseDataType, TransmissionPowerDataType } from '../models/transmissionPowerDataType';
29 import { lineChart, sortDataByTimeStamp } from '../utils/chartUtils';
30 import { addColumnLabels } from '../utils/tableUtils';
31 import ToggleContainer from './toggleContainer';
33 const mapProps = (state: IApplicationStoreState) => ({
34 transmissionPowerProperties: createTransmissionPowerProperties(state),
35 currentView: state.performanceHistory.subViews.transmissionPower.subView,
36 isFilterVisible: state.performanceHistory.subViews.transmissionPower.isFilterVisible,
37 existingFilter: state.performanceHistory.transmissionPower.filter,
40 const mapDisp = (dispatcher: IDispatcher) => ({
41 transmissionPowerActions: createTransmissionPowerActions(dispatcher.dispatch),
42 setSubView: (value: 'chart' | 'table') => dispatcher.dispatch(new SetSubViewAction('transmissionPower', value)),
43 toggleFilterButton: (value: boolean) => { dispatcher.dispatch(new SetFilterVisibility('transmissionPower', value)); },
48 type TransmissionPowerComponentProps = RouteComponentProps & Connect<typeof mapProps, typeof mapDisp> & {
49 selectedTimePeriod: string;
52 const TransmissionPowerTable = MaterialTable as MaterialTableCtorType<TransmissionPowerDataType>;
55 * The Component which gets the transmission power data from the database based on the selected time period.
57 class TransmissionPowerComponent extends React.Component<TransmissionPowerComponentProps> {
58 onToggleFilterButton = () => {
59 this.props.toggleFilterButton(!this.props.isFilterVisible);
62 onChange = (value: 'chart' | 'table') => {
63 this.props.setSubView(value);
66 onFilterChanged = (property: string, filterTerm: string) => {
67 this.props.transmissionPowerActions.onFilterChanged(property, filterTerm);
68 if (!this.props.transmissionPowerProperties.showFilter)
69 this.props.transmissionPowerActions.onToggleFilter(false);
72 render(): JSX.Element {
73 const properties = this.props.transmissionPowerProperties;
74 const actions = this.props.transmissionPowerActions;
76 const chartPagedData = this.getChartDataValues(properties.rows);
78 const transmissionColumns: ColumnModel<TransmissionPowerDataType>[] = [
79 { property: 'radioSignalId', title: 'Radio signal', type: ColumnType.text },
80 { property: 'scannerId', title: 'Scanner ID', type: ColumnType.text },
81 { property: 'timeStamp', title: 'End Time', type: ColumnType.text },
83 property: 'suspectIntervalFlag', title: 'Suspect Interval', type: ColumnType.boolean,
87 chartPagedData.datasets.forEach(ds => {
88 transmissionColumns.push(addColumnLabels<TransmissionPowerDataType>(ds.name, ds.columnLabel));
93 <ToggleContainer onChange={this.onChange} onToggleFilterButton={this.onToggleFilterButton} showFilter={this.props.isFilterVisible}
94 existingFilter={this.props.transmissionPowerProperties.filter} onFilterChanged={this.onFilterChanged} selectedValue={this.props.currentView} >
95 {lineChart(chartPagedData)}
96 <TransmissionPowerTable stickyHeader idProperty={'_id'} tableId="transmission-power-table" columns={transmissionColumns} {...properties} {...actions} />
103 * This function gets the performance values for TransmissionPower according on the chartjs dataset structure
104 * which is to be sent to the chart.
107 private getChartDataValues = (rows: TransmissionPowerDataType[]): IDataSetsObject => {
108 const data_rows = [...rows];
109 sortDataByTimeStamp(data_rows);
111 const datasets: IDataSet[] = [{
113 label: 'tx-level-min',
114 borderColor: '#0e17f3de',
119 columnLabel: 'Tx min',
122 label: 'tx-level-avg',
123 borderColor: '#08edb6de',
128 columnLabel: 'Tx avg',
131 label: 'tx-level-max',
132 borderColor: '#b308edde',
137 columnLabel: 'Tx max',
140 data_rows.forEach(row => {
141 row.txLevelMin = row.performanceData.txLevelMin;
142 row.txLevelAvg = row.performanceData.txLevelAvg;
143 row.txLevelMax = row.performanceData.txLevelMax;
144 datasets.forEach(ds => {
146 x: row['timeStamp' as keyof TransmissionPowerDataType] as string,
147 y: row.performanceData[ds.name as keyof TransmissionPowerDatabaseDataType] as string,
157 const TransmissionPower = withRouter(connect(mapProps, mapDisp)(TransmissionPowerComponent));
158 export default TransmissionPower;