Add sdnr wt odlux
[ccsdk/features.git] / sdnr / wt / odlux / apps / connectApp / src / plugin.tsx
1
2 import { faPlug } from '@fortawesome/free-solid-svg-icons';
3
4 import applicationManager from '../../../framework/src/services/applicationManager';
5 import { subscribe, IFormatedMessage } from '../../../framework/src/services/notificationService';
6
7 import connectAppRootHandler from './handlers/connectAppRootHandler';
8 import ConnectApplication  from './views/connectView';
9 import { RemoveMountedNetworkElement, addMountedNetworkElementAsyncActionCreator } from './actions/mountedNetworkElementsActions' ;
10 import { AddSnackbarNotification } from '../../../framework/src/actions/snackbarActions';
11
12 type ObjectNotification = {
13   counter: string;
14   nodeName: string;
15   objectId: string;
16   timeStamp: string;
17 }
18
19 export function register() {
20   const applicationApi = applicationManager.registerApplication({
21     name: "connectApp",
22     icon: faPlug,
23     rootComponent: ConnectApplication,
24     rootActionHandler: connectAppRootHandler,
25     menuEntry: "Connect App"
26   });
27
28   // subscribe to the websocket notifications
29   subscribe<ObjectNotification & IFormatedMessage>(["ObjectCreationNotification", "ObjectDeletionNotification"], (msg => {
30     const store = applicationApi && applicationApi.applicationStore;
31     if (msg && msg.notifType === "ObjectCreationNotification" && store) {
32       store.dispatch(addMountedNetworkElementAsyncActionCreator(msg.objectId));
33       store.dispatch(new AddSnackbarNotification({ message: `Adding network element [${ msg.objectId }]`, options: { variant: 'info' } }));
34     } else if (msg && msg.notifType === "ObjectDeletionNotification" && store) {
35       store.dispatch(new AddSnackbarNotification({ message: `Removing network element [${ msg.objectId }]`, options: { variant: 'info' } }));
36       store.dispatch(new RemoveMountedNetworkElement(msg.objectId));
37     }
38   }));
39 }