Create wt-odlux directory
[ccsdk/features.git] / sdnr / wt-odlux / odlux / framework / src / app.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 * as React from 'react';
20 import * as ReactDOM from 'react-dom';
21
22 import { ThemeProvider, Theme, StyledEngineProvider } from '@mui/material/styles';
23
24 import { Frame } from './views/frame';
25
26 import { User } from './models/authentication';
27
28 import { AddErrorInfoAction } from './actions/errorActions';
29 import { loginUserAction } from './actions/authentication';
30
31 import { applicationStoreCreator } from './store/applicationStore';
32 import { ApplicationStoreProvider } from './flux/connect';
33
34 import { startHistoryListener } from './middleware/navigation';
35 import { startSoreService } from './services/storeService';
36
37 import { startUserSessionService } from './services/userSessionService';
38 import { startNotificationService } from './services/notificationService';
39
40 import { startBroadcastChannel } from './services/broadcastService';
41
42 import theme from './design/default';
43 import '!style-loader!css-loader!./app.css';
44
45 declare module '@mui/material/styles' {
46
47   interface IDesign {
48     id: string,
49     name: string,
50     url: string,        // image url of a company logo, which will be presented in the ui header
51     height: number,     // image height [px] as delivered by the url
52     width: number,      // image width [px] as delivered by the url
53     logoHeight: number  // height in [px] of the logo (see url) within the ui header
54   }
55
56   interface Theme {
57     design?: IDesign
58   }
59   interface DeprecatedThemeOptions {
60     design?: IDesign
61   }
62 }
63
64
65 declare module '@mui/styles/defaultTheme' {
66   // eslint-disable-next-line @typescript-eslint/no-empty-interface (remove this line if you don't have the rule enabled)
67   interface DefaultTheme extends Theme {}
68 }
69
70 export { configureApplication } from "./handlers/applicationStateHandler";
71
72 export const transportPCEUrl = "transportPCEUrl";
73
74 export const runApplication = () => {
75   
76   const initialToken = localStorage.getItem("userToken");
77   const applicationStore = applicationStoreCreator();
78
79   startBroadcastChannel(applicationStore);
80   startUserSessionService(applicationStore);
81   
82   if (initialToken) {
83     applicationStore.dispatch(loginUserAction(User.fromString(initialToken) || undefined));
84   }
85
86   window.onerror = function (msg: string, url: string, line: number, col: number, error: Error) {
87     // Note that col & error are new to the HTML 5 spec and may not be
88     // supported in every browser.  It worked for me in Chrome.
89     var extra = !col ? '' : '\ncolumn: ' + col;
90     extra += !error ? '' : '\nerror: ' + error;
91
92     // You can view the information in an alert to see things working like this:
93     applicationStore.dispatch(new AddErrorInfoAction({ error, message: msg, url, line, col, info: { extra } }));
94
95     var suppressErrorAlert = true;
96     // If you return true, then error alerts (like in older versions of
97     // Internet Explorer) will be suppressed.
98     return suppressErrorAlert;
99   };
100   
101
102   startSoreService(applicationStore);
103   startHistoryListener(applicationStore);
104   startNotificationService(applicationStore);
105
106   const App = (): JSX.Element => (
107     <ApplicationStoreProvider applicationStore={applicationStore} >
108       <StyledEngineProvider injectFirst>
109         <ThemeProvider theme={theme}>
110           <Frame />
111         </ThemeProvider>
112       </StyledEngineProvider>
113     </ApplicationStoreProvider>
114   );
115
116   ReactDOM.render(<App />, document.getElementById('app'));
117
118   
119
120 };