Fix errors and warnings
[sdc/sdc-workflow-designer.git] / workflow-designer-ui / src / main / frontend / src / App.js
1 /*
2 * Copyright © 2018 European Support Limited
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 import { hot } from 'react-hot-loader';
18 import React, { Component } from 'react';
19 import { Route } from 'react-router-dom';
20 import qs from 'qs';
21
22 import { PluginPubSub } from 'shared/pubsub/plugin-pubsub';
23 import 'resources/scss/style.scss';
24 import 'bpmn-js-properties-panel/styles/properties.less';
25 import { routes } from 'wfapp/routes';
26 import { USER_ID } from 'wfapp/appConstants';
27
28 const RouteWithSubRoutes = route => (
29     <Route
30         path={route.path}
31         exact={route.exact}
32         render={props => <route.component {...props} routes={route.routes} />}
33     />
34 );
35
36 class App extends Component {
37     constructor(props) {
38         super(props);
39
40         this.searchParams = qs.parse(location.search, {
41             ignoreQueryPrefix: true
42         });
43
44         if (this.searchParams && this.searchParams.userId) {
45             localStorage.setItem(USER_ID, this.searchParams.userId);
46         }
47     }
48
49     componentDidMount() {
50         if (this.searchParams) {
51             const { eventsClientId, parentUrl } = this.searchParams;
52
53             if (eventsClientId && parentUrl) {
54                 const client = new PluginPubSub(eventsClientId, parentUrl);
55
56                 client.notify('READY');
57             }
58         }
59     }
60
61     render() {
62         return (
63             <div className="workflow-app">
64                 {routes.map((route, i) => (
65                     <RouteWithSubRoutes key={`App.route.${i}`} {...route} />
66                 ))}
67             </div>
68         );
69     }
70 }
71
72 export default hot(module)(App);