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 // app configuration and main entry point for the app
20 import React from "react";
21 import { withRouter, RouteComponentProps, Route, Switch, Redirect } from 'react-router-dom';
23 import applicationManager from '../../../framework/src/services/applicationManager';
25 import { connect, Connect, IDispatcher } from '../../../framework/src/flux/connect';
27 import { mediatorAppRootHandler } from './handlers/mediatorAppRootHandler';
28 import { avaliableMediatorServersReloadAction } from "./handlers/avaliableMediatorServersHandler";
30 import { MediatorApplication } from "./views/mediatorApplication";
31 import { MediatorServerSelection } from "./views/mediatorServerSelection";
32 import { initializeMediatorServerAsyncActionCreator } from "./actions/mediatorServerActions";
34 const appIcon = require('./assets/icons/mediatorAppIcon.svg'); // select app icon
36 let currentMediatorServerId: string | undefined = undefined;
38 const mapDisp = (dispatcher: IDispatcher) => ({
39 loadMediatorServer : (mediatorServerId: string) => dispatcher.dispatch(initializeMediatorServerAsyncActionCreator(mediatorServerId)),
42 const MediatorServerRouteAdapter = connect(undefined, mapDisp)((props: RouteComponentProps<{ mediatorServerId: string }> & Connect<undefined, typeof mapDisp>) => {
43 if (currentMediatorServerId !== props.match.params.mediatorServerId) {
44 // route parameter has changed
45 currentMediatorServerId = props.match.params.mediatorServerId || undefined;
46 // Hint: This timeout is need, since it is not recommended to change the state while rendering is in progress !
47 window.setTimeout(() => {
48 if (currentMediatorServerId) {
49 props.loadMediatorServer(currentMediatorServerId);
54 <MediatorApplication />
58 type AppProps = RouteComponentProps & Connect;
60 const App = (props: AppProps) => (
62 <Route exact path={ `${ props.match.path }` } component={ MediatorServerSelection } />
63 <Route path={ `${ props.match.path }/:mediatorServerId` } component={ MediatorServerRouteAdapter } />
64 <Redirect to={ `${ props.match.path }` } />
68 const FinalApp = withRouter(connect()(App));
70 export function register() {
71 const applicationApi = applicationManager.registerApplication({
74 rootComponent: FinalApp,
75 rootActionHandler: mediatorAppRootHandler,
79 // prefetch all available mediator servers
80 applicationApi.applicationStoreInitialized.then(applicationStore => {
81 applicationStore.dispatch(avaliableMediatorServersReloadAction)