react 16 upgrade
[sdc.git] / openecomp-ui / src / sdc-app / onboarding / softwareProduct / attachments / setup / HeatSetupActionHelper.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 { actionTypes } from './HeatSetupConstants.js';
17 import isEqual from 'lodash/isEqual.js';
18 import cloneDeep from 'lodash/cloneDeep.js';
19 import SoftwareProductActionHelper from 'sdc-app/onboarding/softwareProduct/SoftwareProductActionHelper.js';
20
21 export default {
22     toggleVolFilesDisplay(dispatch, data) {
23         dispatch({ type: actionTypes.TOGGLE_VOL_DISPLAY, data });
24     },
25
26     addModule(dispatch, isBase) {
27         dispatch({ type: actionTypes.ADD_MODULE, data: { isBase } });
28     },
29
30     deleteModule(dispatch, moduleName) {
31         dispatch({ type: actionTypes.REMOVE_MODULE, data: { moduleName } });
32     },
33
34     renameModule(dispatch, { oldName, newName }) {
35         dispatch({
36             type: actionTypes.RENAME_MODULE,
37             data: { oldName, newName }
38         });
39     },
40
41     changeModuleFileType(dispatch, { module, value, type }) {
42         if (!value) {
43             value = { value: '' };
44         }
45         dispatch({
46             type: actionTypes.FILE_ASSIGN_CHANGED,
47             data: { module, value, type }
48         });
49     },
50
51     changeArtifactList(dispatch, artifacts) {
52         dispatch({
53             type: actionTypes.ARTIFACT_LIST_CHANGE,
54             data: { artifacts: artifacts.map(artifact => artifact.value) }
55         });
56     },
57
58     processAndValidateHeat(
59         dispatch,
60         { softwareProductId, heatData, heatDataCache, isReadOnlyMode, version }
61     ) {
62         return isEqual({ ...heatData, softwareProductId }, heatDataCache) ||
63             isReadOnlyMode
64             ? Promise.resolve()
65             : SoftwareProductActionHelper.updateSoftwareProductHeatCandidate(
66                   dispatch,
67                   { softwareProductId, heatCandidate: heatData, version }
68               )
69                   .then(() =>
70                       SoftwareProductActionHelper.processAndValidateHeatCandidate(
71                           dispatch,
72                           { softwareProductId, version }
73                       )
74                   )
75                   .then(() =>
76                       dispatch({
77                           type: actionTypes.FILL_HEAT_SETUP_CACHE,
78                           payload: { ...cloneDeep(heatData), softwareProductId }
79                       })
80                   );
81     },
82
83     addAllUnassignedFilesToArtifacts(dispatch) {
84         dispatch({ type: actionTypes.ADD_ALL_UNASSIGNED_TO_ARTIFACTS });
85     },
86
87     heatSetupLeaveConfirmation() {
88         return Promise.resolve();
89     }
90
91     /*heatSetupLeaveConfirmation(dispatch, {softwareProductId, heatSetup, heatSetupCache}) {
92                 return new Promise((resolve, reject) => {
93                         if (isEqual({...heatSetup, softwareProductId}, heatSetupCache)) {
94                                 resolve();
95                         } else {
96                                 dispatch({
97                                         type: modalActionTypes.GLOBAL_MODAL_WARNING,
98                                         data:{
99                                                 msg: i18n(`You have uploaded a new HEAT. If you navigate away or Check-in without proceeding to validation,
100                                                         Old HEAT zip file will be in use. new HEAT will be ignored. Do you want to continue?`),
101                                                 confirmationButtonText: i18n('Continue'),
102                                                 onConfirmed: () => resolve(),
103                                                 onDeclined: () => reject()
104                                         }
105                                 });
106                         }
107                 });
108         }*/
109 };