f711c440c697862c32ce2bf091b3188ecba8ea3b
[ccsdk/features.git] / sdnr / wt / odlux / apps / connectApp / src / pluginConnect.tsx
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
19 import { faPlug } from '@fortawesome/free-solid-svg-icons';
20
21 import applicationManager from '../../../framework/src/services/applicationManager';
22 import { subscribe, IFormatedMessage } from '../../../framework/src/services/notificationService';
23
24 import connectAppRootHandler from './handlers/connectAppRootHandler';
25 import ConnectApplication from './views/connectView';
26
27 import { AddSnackbarNotification } from '../../../framework/src/actions/snackbarActions';
28 import { updateCurrentViewAsyncAction } from './actions/commonNetworkElementsActions';
29
30 type ObjectNotification = {
31   counter: string;
32   nodeName: string;
33   objectId: string;
34   timeStamp: string;
35 }
36
37 export function register() {
38   const applicationApi = applicationManager.registerApplication({
39     name: "connect",
40     icon: faPlug,
41     rootComponent: ConnectApplication,
42     rootActionHandler: connectAppRootHandler,
43     menuEntry: "Connect"
44   });
45
46   // subscribe to the websocket notifications
47   subscribe<ObjectNotification & IFormatedMessage>(["ObjectCreationNotification", "ObjectDeletionNotification", "AttributeValueChangedNotification"], (msg => {
48     const store = applicationApi.applicationStore;
49     if (msg && msg.notifType === "ObjectCreationNotification" && store) {
50       store.dispatch(new AddSnackbarNotification({ message: `Adding network element [${msg.objectId}]`, options: { variant: 'info' } }));
51     } else if (msg && (msg.notifType === "ObjectDeletionNotification" || msg.notifType === "AttributeValueChangedNotification") && store) {
52       store.dispatch(new AddSnackbarNotification({ message: `Updating network element [${msg.objectId}]`, options: { variant: 'info' } }));
53     }
54     store && store.dispatch(updateCurrentViewAsyncAction());
55   }));
56 }