Fix name convention issue
[sdc/sdc-workflow-designer.git] / sdc-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, withRouter } from 'react-router-dom';
20 import qs from 'qs';
21 import { connect } from 'react-redux';
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 import { getVersionsAction } from 'features/workflow/overview/overviewConstansts';
28 import { setOperationModeAction } from 'features/version/versionConstants';
29 import { setPluginContext } from './pluginContext/pluginContextActions';
30 import { notificationType } from 'wfapp/pluginContext/pluginContextConstants';
31 const RouteWithSubRoutes = route => (
32     <Route
33         path={route.path}
34         exact={route.exact}
35         render={props => <route.component {...props} routes={route.routes} />}
36     />
37 );
38
39 function mapActionsToProps(dispatch) {
40     return {
41         getOverview: workflowId => {
42             dispatch(getVersionsAction(workflowId));
43             dispatch(setOperationModeAction());
44         },
45         setPluginContext: payload => dispatch(setPluginContext(payload))
46     };
47 }
48
49 class App extends Component {
50     constructor(props) {
51         super(props);
52
53         this.searchParams = qs.parse(location.search, {
54             ignoreQueryPrefix: true
55         });
56
57         if (this.searchParams && this.searchParams.userId) {
58             localStorage.setItem(USER_ID, this.searchParams.userId);
59         }
60     }
61
62     componentDidMount() {
63         if (this.searchParams) {
64             const {
65                 eventsClientId,
66                 parentUrl,
67                 workflowId,
68                 versionId
69             } = this.searchParams;
70
71             if (eventsClientId && parentUrl) {
72                 this.props.setPluginContext({
73                     eventsClientId,
74                     parentUrl
75                 });
76                 const client = new PluginPubSub(eventsClientId, parentUrl);
77                 client.notify(notificationType.READY);
78             }
79             if (workflowId && versionId) {
80                 this.props.getOverview(workflowId);
81                 this.props.history.push(
82                     `/workflow/${workflowId}/version/${versionId}/composition`
83                 );
84             }
85         }
86     }
87
88     render() {
89         return (
90             <div className="workflow-app">
91                 {routes.map((route, i) => (
92                     <RouteWithSubRoutes key={`App.route.${i}`} {...route} />
93                 ))}
94             </div>
95         );
96     }
97 }
98
99 export default hot(module)(
100     withRouter(
101         connect(
102             null,
103             mapActionsToProps
104         )(App)
105     )
106 );