[SDC] Onboarding 1710 rebase.
[sdc.git] / openecomp-ui / src / sdc-app / onboarding / softwareProduct / components / images / SoftwareProductComponentsImageEditor.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 ValidationHelper from 'sdc-app/common/helpers/ValidationHelper.js';
18 import SoftwareProductComponentsImageActionHelper from './SoftwareProductComponentsImageActionHelper.js';
19 import SoftwareProductComponentsImageEditorView from './SoftwareProductComponentsImageEditorView.jsx';
20 import VersionControllerUtils from 'nfvo-components/panel/versionController/VersionControllerUtils.js';
21 import {onboardingMethod as onboardingMethodTypes} from '../../SoftwareProductConstants.js';
22 import {forms} from 'sdc-app/onboarding/softwareProduct/components/SoftwareProductComponentsConstants.js';
23 import {IMAGE_QUESTIONNAIRE} from './SoftwareProductComponentsImageConstants.js';
24
25 export const mapStateToProps = ({softwareProduct}) => {
26
27         let {softwareProductEditor: {data:currentSoftwareProduct = {},  isValidityData = true}, softwareProductComponents} = softwareProduct;
28
29         let {images: {imageEditor = {}}} = softwareProductComponents;
30         let {data, qdata, genericFieldInfo, qgenericFieldInfo, dataMap, formReady} = imageEditor;
31         let isReadOnlyMode = VersionControllerUtils.isReadOnly(currentSoftwareProduct);
32         let {version, onboardingMethod} = currentSoftwareProduct;
33         let isManual =  onboardingMethod === onboardingMethodTypes.MANUAL;
34         let isFormValid = ValidationHelper.checkFormValid(genericFieldInfo) &&  ValidationHelper.checkFormValid(qgenericFieldInfo);
35
36         return {
37                 version,
38                 currentSoftwareProduct,
39                 isValidityData,
40                 data,
41                 qdata,
42                 dataMap,
43                 isFormValid,
44                 formReady,
45                 genericFieldInfo,
46                 qgenericFieldInfo,
47                 isReadOnlyMode,
48                 isManual: isManual
49         };
50 };
51
52 const mapActionsToProps = (dispatch, {softwareProductId, componentId, version}) => {
53         return {
54                 onDataChanged: (deltaData) => ValidationHelper.dataChanged(dispatch, {deltaData, formName: forms.IMAGE_EDIT_FORM}),
55                 onSubmit: ({data, qdata}) => SoftwareProductComponentsImageActionHelper.saveImageDataAndQuestionnaire(dispatch, {softwareProductId, componentId, version, data, qdata}),
56                 onCancel: () => SoftwareProductComponentsImageActionHelper.closeImageEditor(dispatch),
57                 onValidateForm: () => ValidationHelper.validateForm(dispatch, forms.IMAGE_EDIT_FORM),
58                 onQDataChanged: (deltaData) => ValidationHelper.qDataChanged(dispatch, {deltaData,
59                         qName: IMAGE_QUESTIONNAIRE}),
60         };
61 };
62
63 export default connect(mapStateToProps, mapActionsToProps)(SoftwareProductComponentsImageEditorView);