Add collaboration feature
[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 {onboardingMethod as onboardingMethodTypes} from '../../SoftwareProductConstants.js';
21 import {forms} from 'sdc-app/onboarding/softwareProduct/components/SoftwareProductComponentsConstants.js';
22 import {IMAGE_QUESTIONNAIRE} from './SoftwareProductComponentsImageConstants.js';
23
24 export const mapStateToProps = ({
25         softwareProduct,
26         currentScreen: {props: {isReadOnlyMode}}
27 }) => {
28
29         let {softwareProductEditor: {data:currentSoftwareProduct = {},  isValidityData = true}, softwareProductComponents} = softwareProduct;
30
31         let {images: {imageEditor = {}}} = softwareProductComponents;
32         let {data, qdata, genericFieldInfo, qgenericFieldInfo, dataMap, formReady} = imageEditor;
33         let {version, onboardingMethod} = currentSoftwareProduct;
34         let isManual =  onboardingMethod === onboardingMethodTypes.MANUAL;
35         let isFormValid = ValidationHelper.checkFormValid(genericFieldInfo) &&  ValidationHelper.checkFormValid(qgenericFieldInfo);
36
37         return {
38                 version,
39                 currentSoftwareProduct,
40                 isValidityData,
41                 data,
42                 qdata,
43                 dataMap,
44                 isFormValid,
45                 formReady,
46                 genericFieldInfo,
47                 qgenericFieldInfo,
48                 isReadOnlyMode,
49                 isManual: isManual
50         };
51
52 };
53
54 const mapActionsToProps = (dispatch, {softwareProductId, componentId, version}) => {
55         return {
56                 onDataChanged: (deltaData) => ValidationHelper.dataChanged(dispatch, {deltaData, formName: forms.IMAGE_EDIT_FORM}),
57                 onSubmit: ({data, qdata}) => SoftwareProductComponentsImageActionHelper.saveImageDataAndQuestionnaire(dispatch, {softwareProductId, componentId, version, data, qdata}),
58                 onCancel: () => SoftwareProductComponentsImageActionHelper.closeImageEditor(dispatch),
59                 onValidateForm: customValidations => {
60                         ValidationHelper.validateForm(dispatch, forms.IMAGE_EDIT_FORM);
61                         ValidationHelper.qValidateForm(dispatch, IMAGE_QUESTIONNAIRE, customValidations);
62                 },
63                 onQDataChanged: (deltaData, customValidations) => ValidationHelper.qDataChanged(dispatch, {deltaData,
64                         qName: IMAGE_QUESTIONNAIRE, customValidations}),
65         };
66 };
67
68 export default connect(mapStateToProps, mapActionsToProps)(SoftwareProductComponentsImageEditorView);