react 16 upgrade
[sdc.git] / openecomp-ui / src / sdc-app / onboarding / softwareProduct / attachments / setup / HeatSetup.js
1 /*
2  * Copyright © 2016-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 import { connect } from 'react-redux';
17 import HeatSetupView from './HeatSetupView.jsx';
18 import HeatSetupActionHelper from './HeatSetupActionHelper.js';
19
20 const BASE = true;
21
22 function baseExists(modules) {
23     for (let i in modules) {
24         if (modules[i].isBase) {
25             return true;
26         }
27     }
28     return false;
29 }
30
31 export const mapStateToProps = ({
32     softwareProduct: {
33         softwareProductAttachments: { heatSetup, heatSetupCache }
34     }
35 }) => {
36     let {
37         modules = [],
38         unassigned = [],
39         artifacts = [],
40         nested = []
41     } = heatSetup;
42     let isBaseExist = baseExists(modules);
43
44     return {
45         heatSetupCache,
46         modules,
47         unassigned,
48         artifacts,
49         nested,
50         isBaseExist
51     };
52 };
53
54 export const mapActionsToProps = (dispatch, {}) => {
55     return {
56         onModuleRename: (oldName, newName) =>
57             HeatSetupActionHelper.renameModule(dispatch, { oldName, newName }),
58         onModuleAdd: () => HeatSetupActionHelper.addModule(dispatch, !BASE),
59         onBaseAdd: () => HeatSetupActionHelper.addModule(dispatch, BASE),
60         onModuleDelete: moduleName =>
61             HeatSetupActionHelper.deleteModule(dispatch, moduleName),
62         onModuleFileTypeChange: ({ module, value, type }) =>
63             HeatSetupActionHelper.changeModuleFileType(dispatch, {
64                 module,
65                 value,
66                 type
67             }),
68         onToggleVolFilesDisplay: ({ module, value }) => {
69             HeatSetupActionHelper.toggleVolFilesDisplay(dispatch, {
70                 module,
71                 value
72             });
73         },
74         onArtifactListChange: artifacts =>
75             HeatSetupActionHelper.changeArtifactList(dispatch, artifacts),
76         onAddAllUnassigned: () =>
77             HeatSetupActionHelper.addAllUnassignedFilesToArtifacts(dispatch)
78     };
79 };
80
81 export default connect(mapStateToProps, mapActionsToProps, null, {
82     withRef: true
83 })(HeatSetupView);