Create wt-odlux directory
[ccsdk/features.git] / sdnr / wt-odlux / 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 { IActionHandler } from '../../../../framework/src/flux/action';
21 import { combineActionHandler } from '../../../../framework/src/flux/middleware';
22 // ** do not remove **
23 // eslint-disable-next-line @typescript-eslint/no-unused-vars
24 import { IApplicationStoreState } from '../../../../framework/src/store/applicationStore';
25
26 import { IConnectAppStoreState } from '../../../connectApp/src/handlers/connectAppRootHandler';
27 import { UpdateMountId } from '../actions/deviceListActions';
28 import { SetPanelAction } from '../actions/panelChangeActions';
29 import { ReloadAction } from '../actions/reloadAction';
30 import { TimeChangeAction } from '../actions/timeChangeAction';
31 import { ResetAllSubViewsAction, SetFilterVisibility, SetSubViewAction } from '../actions/toggleActions';
32 import { PmDataInterval } from '../models/performanceDataType';
33 import { currentViewType, SubTabType } from '../models/toggleDataType';
34 import { adaptiveModulationActionHandler, IAdaptiveModulationState } from './adaptiveModulationHandler';
35 import { availableLtpsActionHandler, IAvailableLtpsState } from './availableLtpsActionHandler';
36 import { crossPolarDiscriminationActionHandler, ICrossPolarDiscriminationState } from './crossPolarDiscriminationHandler';
37 import { deviceListActionHandler, IDeviceListState } from './deviceListActionHandler';
38 import { IPerformanceDataState, performanceDataActionHandler } from './performanceDataHandler';
39 import { IReceiveLevelState, receiveLevelActionHandler } from './receiveLevelHandler';
40 import { ISignalToInterferenceState, signalToInterferenceActionHandler } from './signalToInterferenceHandler';
41 import { ITemperatureState, temperatureActionHandler } from './temperatureHandler';
42 import { ITransmissionPowerState, transmissionPowerActionHandler } from './transmissionPowerHandler';
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 = {
96   currentSubView: currentViewType;
97   performanceData: filterableSubview;
98   receiveLevel: filterableSubview;
99   transmissionPower: filterableSubview;
100   adaptiveModulation: filterableSubview;
101   temperatur: filterableSubview;
102   SINR: filterableSubview;
103   CPD: filterableSubview;
104 };
105
106
107 const toogleViewDataHandler: IActionHandler<toggleViewDataType> = (
108   state = {
109     currentSubView: 'performanceData',
110     performanceData: { subView: 'chart', isFilterVisible: true },
111     receiveLevel: { subView: 'chart', isFilterVisible: true },
112     adaptiveModulation: { subView: 'chart', isFilterVisible: true },
113     transmissionPower: { subView: 'chart', isFilterVisible: true },
114     temperatur: { subView: 'chart', isFilterVisible: true },
115     SINR: { subView: 'chart', isFilterVisible: true },
116     CPD: { subView: 'chart', isFilterVisible: true },
117   }, action) => {
118
119   if (action instanceof SetSubViewAction) {
120     switch (action.currentView) {
121       case 'performanceData': state = { ...state, performanceData: { ...state.performanceData, subView: action.selectedTab } }; break;
122       case 'adaptiveModulation': state = { ...state, adaptiveModulation: { ...state.adaptiveModulation, subView: action.selectedTab } }; break;
123       case 'receiveLevel': state = { ...state, receiveLevel: { ...state.receiveLevel, subView: action.selectedTab } }; break;
124       case 'transmissionPower': state = { ...state, transmissionPower: { ...state.transmissionPower, subView: action.selectedTab } }; break;
125       case 'Temp': state = { ...state, temperatur: { ...state.temperatur, subView: action.selectedTab } }; break;
126       case 'SINR': state = { ...state, SINR: { ...state.SINR, subView: action.selectedTab } }; break;
127       case 'CPD': state = { ...state, CPD: { ...state.CPD, subView: action.selectedTab } }; break;
128     }
129   } else if (action instanceof SetFilterVisibility) {
130     switch (action.currentView) {
131       case 'performanceData': state = {
132         ...state, performanceData: { ...state.performanceData, isFilterVisible: action.isVisible },
133       }; break;
134       case 'adaptiveModulation': state = { ...state, adaptiveModulation: { ...state.performanceData, isFilterVisible: action.isVisible } }; break;
135       case 'receiveLevel': state = { ...state, receiveLevel: { ...state.receiveLevel, isFilterVisible: action.isVisible } }; break;
136       case 'transmissionPower': state = { ...state, transmissionPower: { ...state.transmissionPower, isFilterVisible: action.isVisible } }; break;
137       case 'Temp': state = { ...state, temperatur: { ...state.temperatur, isFilterVisible: action.isVisible } }; break;
138       case 'SINR': state = { ...state, SINR: { ...state.SINR, isFilterVisible: action.isVisible } }; break;
139       case 'CPD': state = { ...state, CPD: { ...state.CPD, isFilterVisible: action.isVisible } }; break;
140     }
141   } else if (action instanceof ResetAllSubViewsAction) {
142     state = {
143       ...state, performanceData: { ...state.performanceData, subView: 'chart' },
144       adaptiveModulation: { ...state.adaptiveModulation, subView: 'chart' },
145       receiveLevel: { ...state.receiveLevel, subView: 'chart' },
146       transmissionPower: { ...state.transmissionPower, subView: 'chart' },
147       temperatur: { ...state.temperatur, subView: 'chart' },
148       SINR: { ...state.SINR, subView: 'chart' },
149       CPD: { ...state.CPD, subView: 'chart' },
150     };
151   }
152   return state;
153 };
154
155 declare module '../../../../framework/src/store/applicationStore' {
156   interface IApplicationStoreState {
157     performanceHistory: IPerformanceHistoryStoreState;
158     connect: IConnectAppStoreState;
159   }
160 }
161
162 const actionHandlers = {
163   nodeId: mountIdHandler,
164   networkElements: deviceListActionHandler,
165   ltps: availableLtpsActionHandler,
166   performanceData: performanceDataActionHandler,
167   receiveLevel: receiveLevelActionHandler,
168   transmissionPower: transmissionPowerActionHandler,
169   adaptiveModulation: adaptiveModulationActionHandler,
170   temperature: temperatureActionHandler,
171   signalToInterference: signalToInterferenceActionHandler,
172   crossPolarDiscrimination: crossPolarDiscriminationActionHandler,
173   currentOpenPanel: currentOpenPanelHandler,
174   pmDataIntervalType: currentPMDataIntervalHandler,
175   subViews: toogleViewDataHandler,
176   isReloadSchedueled: reloadHandler,
177 };
178
179 const performanceHistoryRootHandler = combineActionHandler<IPerformanceHistoryStoreState>(actionHandlers);
180 export default performanceHistoryRootHandler;
181