Bugfixes for PerformanceApp
[ccsdk/features.git] / sdnr / wt / odlux / apps / performanceHistoryApp / src / handlers / performanceHistoryRootHandler.ts
1 /**
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
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 // main state handler
19
20 import { combineActionHandler } from '../../../../framework/src/flux/middleware';
21
22 // ** do not remove **
23 import { IApplicationStoreState } from '../../../../framework/src/store/applicationStore';
24 import { IActionHandler } from '../../../../framework/src/flux/action';
25
26 import { IConnectAppStoreState } from '../../../connectApp/src/handlers/connectAppRootHandler';
27 import { IPerformanceDataState, performanceDataActionHandler } from './performanceDataHandler';
28 import { IReceiveLevelState, receiveLevelActionHandler } from './receiveLevelHandler';
29 import { ITransmissionPowerState, transmissionPowerActionHandler } from './transmissionPowerHandler';
30 import { IAdaptiveModulationState, adaptiveModulationActionHandler } from './adaptiveModulationHandler';
31 import { ITemperatureState, temperatureActionHandler } from './temperatureHandler';
32 import { ISignalToInterferenceState, signalToInterferenceActionHandler } from './signalToInterferenceHandler';
33 import { ICrossPolarDiscriminationState, crossPolarDiscriminationActionHandler } from './crossPolarDiscriminationHandler';
34 import { SetPanelAction } from '../actions/panelChangeActions';
35 import { IDeviceListState, deviceListActionHandler } from './deviceListActionHandler';
36 import { IAvailableLtpsState, availableLtpsActionHandler } from './availableLtpsActionHandler';
37 import { PmDataInterval } from '../models/performanceDataType';
38 import { TimeChangeAction } from '../actions/timeChangeAction';
39 import { UpdateMountId } from '../actions/deviceListActions';
40 import { SetSubViewAction, ResetAllSubViewsAction, SetFilterVisibility } from '../actions/toggleActions';
41 import { SubTabType, currentViewType } from '../models/toggleDataType';
42 import { ReloadAction } from '../actions/reloadAction';
43
44 export interface IPerformanceHistoryStoreState {
45   nodeId: string;
46   networkElements: IDeviceListState;
47   ltps: IAvailableLtpsState;
48   performanceData: IPerformanceDataState;
49   receiveLevel: IReceiveLevelState;
50   transmissionPower: ITransmissionPowerState;
51   adaptiveModulation: IAdaptiveModulationState;
52   temperature: ITemperatureState;
53   signalToInterference: ISignalToInterferenceState;
54   crossPolarDiscrimination: ICrossPolarDiscriminationState;
55   currentOpenPanel: string | null;
56   pmDataIntervalType: PmDataInterval;
57   subViews: toggleViewDataType;
58   isReloadSchedueled: boolean;
59 }
60
61 const mountIdHandler: IActionHandler<string> = (state = "", action) => {
62   if (action instanceof UpdateMountId) {
63     state = "";
64     if (action.nodeId) {
65       state = action.nodeId;
66     }
67   }
68   return state;
69 }
70
71 const reloadHandler: IActionHandler<boolean> = (state = false, action) => {
72
73   if (action instanceof ReloadAction) {
74     state = action.show;
75   }
76   return state;
77 }
78
79
80 const currentOpenPanelHandler: IActionHandler<string | null> = (state = null, action) => {
81   if (action instanceof SetPanelAction) {
82     state = action.panelId;
83   }
84   return state;
85 }
86
87 const currentPMDataIntervalHandler: IActionHandler<PmDataInterval> = (state = PmDataInterval.pmInterval15Min, action) => {
88   if (action instanceof TimeChangeAction) {
89     state = action.time;
90   }
91   return state;
92 }
93
94 type filterableSubview = { subView: SubTabType, isFilterVisible: boolean };
95 type toggleViewDataType = { currentSubView: currentViewType, performanceData: filterableSubview, receiveLevel: filterableSubview, transmissionPower: filterableSubview, adaptiveModulation: filterableSubview, temperatur: filterableSubview, SINR: filterableSubview, CPD: filterableSubview };
96
97
98 const toogleViewDataHandler: IActionHandler<toggleViewDataType> = (state = { currentSubView: "performanceData", performanceData: { subView: "chart", isFilterVisible: true }, receiveLevel: { subView: "chart", isFilterVisible: true }, adaptiveModulation: { subView: "chart", isFilterVisible: true }, transmissionPower: { subView: "chart", isFilterVisible: true }, temperatur: { subView: "chart", isFilterVisible: true }, SINR: { subView: "chart", isFilterVisible: true }, CPD: { subView: "chart", isFilterVisible: true } }, action) => {
99
100   if (action instanceof SetSubViewAction) {
101     switch (action.currentView) {
102       case "performanceData": state = { ...state, performanceData: { ...state.performanceData, subView: action.selectedTab } }; break;
103       case "adaptiveModulation": state = { ...state, adaptiveModulation: { ...state.adaptiveModulation, subView: action.selectedTab } }; break;
104       case "receiveLevel": state = { ...state, receiveLevel: { ...state.receiveLevel, subView: action.selectedTab } }; break;
105       case "transmissionPower": state = { ...state, transmissionPower: { ...state.transmissionPower, subView: action.selectedTab } }; break;
106       case "Temp": state = { ...state, temperatur: { ...state.temperatur, subView: action.selectedTab } }; break;
107       case "SINR": state = { ...state, SINR: { ...state.SINR, subView: action.selectedTab } }; break;
108       case "CPD": state = { ...state, CPD: { ...state.CPD, subView: action.selectedTab } }; break;
109     }
110   }
111   else if (action instanceof SetFilterVisibility) {
112     switch (action.currentView) {
113       case "performanceData": state = {
114         ...state, performanceData: { ...state.performanceData, isFilterVisible: action.isVisible }
115       }; break;
116       case "adaptiveModulation": state = { ...state, adaptiveModulation: { ...state.performanceData, isFilterVisible: action.isVisible } }; break;
117       case "receiveLevel": state = { ...state, receiveLevel: { ...state.receiveLevel, isFilterVisible: action.isVisible } }; break;
118       case "transmissionPower": state = { ...state, transmissionPower: { ...state.transmissionPower, isFilterVisible: action.isVisible } }; break;
119       case "Temp": state = { ...state, temperatur: { ...state.temperatur, isFilterVisible: action.isVisible } }; break;
120       case "SINR": state = { ...state, SINR: { ...state.SINR, isFilterVisible: action.isVisible } }; break;
121       case "CPD": state = { ...state, CPD: { ...state.CPD, isFilterVisible: action.isVisible } }; break;
122     }
123
124   } else if (action instanceof ResetAllSubViewsAction) {
125     state = {
126       ...state, performanceData: { ...state.performanceData, subView: "chart" },
127       adaptiveModulation: { ...state.adaptiveModulation, subView: "chart" },
128       receiveLevel: { ...state.receiveLevel, subView: "chart" },
129       transmissionPower: { ...state.transmissionPower, subView: "chart" },
130       temperatur: { ...state.temperatur, subView: "chart" },
131       SINR: { ...state.SINR, subView: "chart" },
132       CPD: { ...state.CPD, subView: "chart" }
133     }
134   }
135
136   return state;
137 }
138
139 declare module '../../../../framework/src/store/applicationStore' {
140   interface IApplicationStoreState {
141     performanceHistory: IPerformanceHistoryStoreState;
142     connect: IConnectAppStoreState;
143   }
144 }
145
146 const actionHandlers = {
147   nodeId: mountIdHandler,
148   networkElements: deviceListActionHandler,
149   ltps: availableLtpsActionHandler,
150   performanceData: performanceDataActionHandler,
151   receiveLevel: receiveLevelActionHandler,
152   transmissionPower: transmissionPowerActionHandler,
153   adaptiveModulation: adaptiveModulationActionHandler,
154   temperature: temperatureActionHandler,
155   signalToInterference: signalToInterferenceActionHandler,
156   crossPolarDiscrimination: crossPolarDiscriminationActionHandler,
157   currentOpenPanel: currentOpenPanelHandler,
158   pmDataIntervalType: currentPMDataIntervalHandler,
159   subViews: toogleViewDataHandler,
160   isReloadSchedueled: reloadHandler
161 };
162
163 const performanceHistoryRootHandler = combineActionHandler<IPerformanceHistoryStoreState>(actionHandlers);
164 export default performanceHistoryRootHandler;
165