[SDC] Onboarding 1710 rebase.
[sdc.git] / openecomp-ui / src / sdc-app / onboarding / softwareProduct / deployment / editor / SoftwareProductDeploymentEditor.js
1 /*!
2  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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
13  * or implied. See the License for the specific language governing
14  * permissions and limitations under the License.
15  */
16 import {connect} from 'react-redux';
17 import SoftwareProductDeploymentEditorView from './SoftwareProductDeploymentEditorView.jsx';
18 import SoftwareProdcutDeploymentActionHelper from '../SoftwareProductDeploymentActionHelper.js';
19 import VersionControllerUtils from 'nfvo-components/panel/versionController/VersionControllerUtils.js';
20 import ValidationHelper from 'sdc-app/common/helpers/ValidationHelper.js';
21
22 import {DEPLOYMENT_FLAVORS_FORM_NAME} from '../SoftwareProductDeploymentConstants.js';
23
24 export function mapStateToProps({licenseModel, softwareProduct}) {
25         let {
26                 softwareProductEditor: {
27                         data: currentSoftwareProduct = {}
28                 },
29                 softwareProductComponents: {
30                         componentsList,
31                         computeFlavor: {
32                                 computesList
33                         }
34                 },
35                 softwareProductDeployment: {
36                         deploymentFlavors,
37                         deploymentFlavorEditor: {
38                                 data = {},
39                                 genericFieldInfo,
40                                 formReady
41                         }
42                 }
43         } = softwareProduct;
44
45         let {
46                         featureGroup: {
47                                 featureGroupsList
48                         }
49         } = licenseModel;
50
51         let isReadOnlyMode = VersionControllerUtils.isReadOnly(currentSoftwareProduct);
52         let isFormValid = ValidationHelper.checkFormValid(genericFieldInfo);
53         let selectedFeatureGroupsIds = currentSoftwareProduct.licensingData ? currentSoftwareProduct.licensingData.featureGroups || [] : [];
54         let selectedFeatureGroupsList = featureGroupsList
55                 .filter(featureGroup => selectedFeatureGroupsIds.includes(featureGroup.id))
56                 .map(featureGroup => ({value: featureGroup.id, label: featureGroup.name}));
57
58         let DFNames = {};
59
60         deploymentFlavors.map(deployment => {
61                 DFNames[deployment.model] = deployment.id;
62         });
63
64         return {
65                 data,
66                 selectedFeatureGroupsList,
67                 genericFieldInfo,
68                 DFNames,
69                 isFormValid,
70                 formReady,
71                 isReadOnlyMode,
72                 componentsList,
73                 computesList,
74                 isEdit: Boolean(data.id)
75         };
76 }
77
78 function mapActionsToProps(dispatch, {softwareProductId, version}) {
79         return {
80                 onDataChanged: (deltaData, customValidations) => ValidationHelper.dataChanged(dispatch, {deltaData, formName: DEPLOYMENT_FLAVORS_FORM_NAME, customValidations}),
81                 onClose: () => SoftwareProdcutDeploymentActionHelper.closeDeploymentFlavorEditor(dispatch),
82                 onCreate: data =>  SoftwareProdcutDeploymentActionHelper.createDeploymentFlavor(dispatch, {softwareProductId, data, version}),
83                 onEdit: data =>  SoftwareProdcutDeploymentActionHelper.editDeploymentFlavor(dispatch, {softwareProductId, deploymentFlavorId: data.id, data, version}),
84                 onValidateForm: () => ValidationHelper.validateForm(dispatch, DEPLOYMENT_FLAVORS_FORM_NAME)
85         };
86 }
87
88 export default connect(mapStateToProps, mapActionsToProps)(SoftwareProductDeploymentEditorView);