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 * as React from "react";
20 import { faBook } from '@fortawesome/free-solid-svg-icons';
22 import applicationManager from '../../../framework/src/services/applicationManager';
24 import { withRouter, RouteComponentProps, Route, Switch, Redirect } from 'react-router-dom';
25 import performanceHistoryRootHandler from './handlers/performanceHistoryRootHandler';
26 import { PmDataInterval } from './models/performanceDataType';
27 import PerformanceHistoryApplication from './views/performanceHistoryApplication';
28 import { ApplicationStore } from '../../../framework/src/store/applicationStore';
30 import connect, { Connect, IDispatcher } from '../../../framework/src/flux/connect';
31 import { IApplicationStoreState } from "../../../framework/src/store/applicationStore";
32 import { updateMountIdActionCreator } from "./actions/deviceListActions";
35 readonly applicationStore: ApplicationStore | null;
36 readonly applicationStoreInitialized: Promise<ApplicationStore>;
39 const mapProps = (state: IApplicationStoreState) => ({
42 const mapDisp = (dispatcher: IDispatcher) => ({
43 updateMountId: (mountId: string) => dispatcher.dispatch(updateMountIdActionCreator(mountId))
46 let currentMountId: string | null = null;
47 let lastUrl: string = "/performanceHistory";
48 const PerformanceHistoryApplicationRouteAdapter = connect(mapProps, mapDisp)((props: RouteComponentProps<{ mountId?: string}> & Connect<typeof mapProps, typeof mapDisp>) => {
49 let mountId: string = "";
50 if (props.location.pathname !== lastUrl) {
51 // ensure the asynchronus update will only be called once per path
52 lastUrl = props.location.pathname;
53 let index = lastUrl.lastIndexOf("performanceHistory/");
55 mountId = lastUrl.substr(index+19);
60 window.setTimeout(async () => {
61 // check if the mountId has changed
62 if (currentMountId !== mountId) {
63 currentMountId = mountId;
64 await props.updateMountId(currentMountId);
69 <PerformanceHistoryApplication />
73 const PerformanceHistoryRouterApp = withRouter((props: RouteComponentProps) => {
74 props.history.action = "POP";
77 <Route path={`${props.match.path}/:mountId`} component={PerformanceHistoryApplicationRouteAdapter} />
78 <Route path={`${props.match.path}`} component={PerformanceHistoryApplicationRouteAdapter} />
79 <Redirect to={`${props.match.path}`} />
84 export function register() {
85 api = applicationManager.registerApplication({
86 name: "performanceHistory",
88 rootComponent: PerformanceHistoryRouterApp,
89 rootActionHandler: performanceHistoryRootHandler,
90 menuEntry: "Performance"
94 export function setPmDataInterval(pmDataInterval: PmDataInterval): boolean {
95 let reload: boolean = true;
96 if (api && api.applicationStore) {
97 if (api.applicationStore.state.performanceHistory.pmDataIntervalType !== pmDataInterval) {
100 api.applicationStore.state.performanceHistory.pmDataIntervalType = pmDataInterval;
106 export function getPmDataInterval(): PmDataInterval {
107 let result = api && api.applicationStore
108 ? api.applicationStore.state.performanceHistory.pmDataIntervalType
109 : PmDataInterval.pmInterval15Min;
110 return result ? result : PmDataInterval.pmInterval15Min;