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==========================================================================
19 import React from 'react';
20 import { Redirect, Route, RouteComponentProps, Switch, withRouter } from 'react-router-dom';
22 import { connect, Connect, IDispatcher } from '../../../framework/src/flux/connect';
23 import applicationManager from '../../../framework/src/services/applicationManager';
24 // eslint-disable-next-line @typescript-eslint/no-unused-vars
25 import { IApplicationStoreState } from '../../../framework/src/store/applicationStore';
26 import { ApplicationStore } from '../../../framework/src/store/applicationStore';
28 import { updateMountIdActionCreator } from './actions/deviceListActions';
29 import { ResetLtpsAction } from './actions/ltpAction';
30 import { ReloadAction } from './actions/reloadAction';
31 import { ResetAllSubViewsAction } from './actions/toggleActions';
32 import performanceHistoryRootHandler from './handlers/performanceHistoryRootHandler';
33 import { PmDataInterval } from './models/performanceDataType';
34 import PerformanceHistoryApplication from './views/performanceHistoryApplication';
36 const appIcon = require('./assets/icons/performanceHistoryAppIcon.svg'); // select app icon
39 readonly applicationStore: ApplicationStore | null;
40 readonly applicationStoreInitialized: Promise<ApplicationStore>;
43 const mapProps = () => ({
46 const mapDisp = (dispatcher: IDispatcher) => ({
47 updateMountId: (mountId: string) => dispatcher.dispatch(updateMountIdActionCreator(mountId)),
48 resetLtps: () => dispatcher.dispatch(new ResetLtpsAction()),
49 resetSubViews: () => dispatcher.dispatch(new ResetAllSubViewsAction()),
50 setScheduleReload: (show: boolean) => dispatcher.dispatch(new ReloadAction(show)),
53 let currentMountId: string | null = null;
54 let lastUrl: string = '/performanceHistory';
55 const PerformanceHistoryApplicationRouteAdapter = connect(mapProps, mapDisp)((props: RouteComponentProps<{ mountId?: string }> & Connect<typeof mapProps, typeof mapDisp>) => {
56 let mountId: string = '';
58 const getMountId = (last_url: string) => {
59 let index = last_url.lastIndexOf('performanceHistory/');
61 mountId = last_url.substring(index + 19);
69 const scheduleReload = (current_mount_id: string) => {
70 props.updateMountId(current_mount_id);
72 props.resetSubViews();
73 props.setScheduleReload(true);
76 // called when component finished mounting
77 React.useEffect(() => {
79 lastUrl = props.location.pathname;
80 mountId = getMountId(lastUrl);
82 if (currentMountId !== mountId) { // new element is loaded
83 currentMountId = mountId;
84 scheduleReload(currentMountId);
86 if (currentMountId !== '') { // same element is loaded again
87 scheduleReload(currentMountId);
91 // called when component gets updated
92 React.useEffect(() => {
94 lastUrl = props.location.pathname;
95 mountId = getMountId(lastUrl);
97 if (currentMountId !== mountId) {
98 currentMountId = mountId;
99 scheduleReload(currentMountId);
105 <PerformanceHistoryApplication />
109 const PerformanceHistoryRouterApp = withRouter((props: RouteComponentProps) => {
110 props.history.action = 'POP';
113 <Route path={`${props.match.path}/:mountId`} component={PerformanceHistoryApplicationRouteAdapter} />
114 <Route path={`${props.match.path}`} component={PerformanceHistoryApplicationRouteAdapter} />
115 <Redirect to={`${props.match.path}`} />
120 export function register() {
121 api = applicationManager.registerApplication({
122 name: 'performanceHistory',
124 rootComponent: PerformanceHistoryRouterApp,
125 rootActionHandler: performanceHistoryRootHandler,
126 menuEntry: 'Performance',
130 export function setPmDataInterval(pmDataInterval: PmDataInterval): boolean {
131 let reload: boolean = true;
132 if (api && api.applicationStore) {
133 if (api.applicationStore.state.performanceHistory.pmDataIntervalType !== pmDataInterval) {
136 api.applicationStore.state.performanceHistory.pmDataIntervalType = pmDataInterval;
142 export function getPmDataInterval(): PmDataInterval {
143 let result = api && api.applicationStore
144 ? api.applicationStore.state.performanceHistory.pmDataIntervalType
145 : PmDataInterval.pmInterval15Min;
146 return result ? result : PmDataInterval.pmInterval15Min;