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 * as React from 'react';
20 import { withRouter, RouteComponentProps } from 'react-router-dom';
22 import { MaterialTable, ColumnType, ColumnModel, MaterialTableCtorType } from '../../../../framework/src/components/material-table';
23 import { IApplicationStoreState } from '../../../../framework/src/store/applicationStore';
24 import connect, { Connect, IDispatcher } from '../../../../framework/src/flux/connect';
26 import { TemperatureDataType, TemperatureDatabaseDataType } from '../models/temperatureDataType';
27 import { IDataSet, IDataSetsObject } from '../models/chartTypes';
28 import { createTemperatureProperties, createTemperatureActions } from '../handlers/temperatureHandler';
29 import { lineChart, sortDataByTimeStamp } from '../utils/chartUtils';
30 import { addColumnLabels } from '../utils/tableUtils';
31 import ToggleContainer from './toggleContainer';
32 import { SetSubViewAction, SetFilterVisibility } from '../actions/toggleActions';
34 const mapProps = (state: IApplicationStoreState) => ({
35 temperatureProperties: createTemperatureProperties(state),
36 currentView: state.performanceHistory.subViews.temperatur.subView,
37 isFilterVisible: state.performanceHistory.subViews.temperatur.isFilterVisible,
38 existingFilter: state.performanceHistory.temperature.filter
41 const mapDisp = (dispatcher: IDispatcher) => ({
42 temperatureActions: createTemperatureActions(dispatcher.dispatch),
43 setSubView: (value: "chart" | "table") => dispatcher.dispatch(new SetSubViewAction("Temp", value)),
44 toggleFilterButton: (value: boolean) => { dispatcher.dispatch(new SetFilterVisibility("Temp", value)) },
48 type TemperatureComponentProps = RouteComponentProps & Connect<typeof mapProps, typeof mapDisp> & {
49 selectedTimePeriod: string
52 const TemperatureTable = MaterialTable as MaterialTableCtorType<TemperatureDataType>;
55 * The Component which gets the temperature data from the database based on the selected time period.
57 class TemperatureComponent extends React.Component<TemperatureComponentProps>{
59 onToggleFilterButton = () => {
60 this.props.toggleFilterButton(!this.props.isFilterVisible);
64 onChange = (value: "chart" | "table") => {
65 this.props.setSubView(value);
68 onFilterChanged = (property: string, filterTerm: string) => {
69 this.props.temperatureActions.onFilterChanged(property, filterTerm);
70 if (!this.props.temperatureProperties.showFilter)
71 this.props.temperatureActions.onToggleFilter(false);
74 render(): JSX.Element {
75 const properties = this.props.temperatureProperties;
76 const actions = this.props.temperatureActions;
78 const chartPagedData = this.getChartDataValues(properties.rows);
79 const temperatureColumns: ColumnModel<TemperatureDataType>[] = [
80 { property: "radioSignalId", title: "Radio signal", type: ColumnType.text },
81 { property: "scannerId", title: "Scanner ID", type: ColumnType.text },
82 { property: "timeStamp", title: "End Time", type: ColumnType.text },
84 property: "suspectIntervalFlag", title: "Suspect Interval", type: ColumnType.boolean
88 chartPagedData.datasets.forEach(ds => {
89 temperatureColumns.push(addColumnLabels<TemperatureDataType>(ds.name, ds.columnLabel));
94 <ToggleContainer onToggleFilterButton={this.onToggleFilterButton} showFilter={this.props.isFilterVisible} existingFilter={this.props.temperatureProperties.filter} onFilterChanged={this.onFilterChanged} selectedValue={this.props.currentView} onChange={this.onChange}>
95 {lineChart(chartPagedData)}
96 <TemperatureTable stickyHeader idProperty={"_id"} tableId="temperature-table" columns={temperatureColumns} {...properties} {...actions} />
103 * This function gets the performance values for Temperature according on the chartjs dataset structure
104 * which is to be sent to the chart.
107 private getChartDataValues = (rows: TemperatureDataType[]): IDataSetsObject => {
108 const _rows = [...rows];
109 sortDataByTimeStamp(_rows);
111 const datasets: IDataSet[] = [{
113 label: "rf-temp-min",
114 borderColor: '#0e17f3de',
119 columnLabel: "Rf Temp Min[deg C]"
122 label: "rf-temp-avg",
123 borderColor: '#08edb6de',
128 columnLabel: "Rf Temp Avg[deg C]"
131 label: "rf-temp-max",
132 borderColor: '#b308edde',
137 columnLabel: "Rf Temp Max[deg C]"
140 _rows.forEach(row => {
141 row.rfTempMin = row.performanceData.rfTempMin;
142 row.rfTempAvg = row.performanceData.rfTempAvg;
143 row.rfTempMax = row.performanceData.rfTempMax;
144 datasets.forEach(ds => {
146 x: row["timeStamp" as keyof TemperatureDataType] as string,
147 y: row.performanceData[ds.name as keyof TemperatureDatabaseDataType] as string
157 const Temperature = withRouter(connect(mapProps, mapDisp)(TemperatureComponent));
158 export default Temperature;