86c4e072d44886810ad3b16a54de3e0d36b29373
[sdc.git] /
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 i18n from 'nfvo-utils/i18n/i18n.js';
18
19 import VersionControllerUtils from 'nfvo-components/panel/versionController/VersionControllerUtils.js';
20 import {actionTypes as modalActionTypes} from 'nfvo-components/modal/GlobalModalConstants.js';
21 import SoftwareProductComponentsImageListView from './SoftwareProductComponentsImageListView.jsx';
22 import ImageHelper from './SoftwareProductComponentsImageActionHelper.js';
23 import SoftwareProductComponentsImagesActionHelper from './SoftwareProductComponentsImageActionHelper.js';
24 import SoftwareProductComponentsActionHelper from '../SoftwareProductComponentsActionHelper.js';
25 import {COMPONENTS_QUESTIONNAIRE} from 'sdc-app/onboarding/softwareProduct/components/SoftwareProductComponentsConstants.js';
26 import ValidationHelper from 'sdc-app/common/helpers/ValidationHelper.js';
27
28 import {onboardingMethod as onboardingMethodTypes} from '../../SoftwareProductConstants.js';
29
30 export const mapStateToProps = ({softwareProduct}) => {
31
32         let {softwareProductEditor: {data: currentSoftwareProduct = {}, isValidityData = true}, softwareProductComponents} = softwareProduct;
33         let {images: {imagesList = []}, componentEditor: {data: componentData, qdata, dataMap, qgenericFieldInfo}} = softwareProductComponents;
34         let isReadOnlyMode = VersionControllerUtils.isReadOnly(currentSoftwareProduct);
35         let {version, onboardingMethod} = currentSoftwareProduct;
36         let isManual =  onboardingMethod === onboardingMethodTypes.MANUAL;
37
38         return {
39                 version,
40                 componentData,
41                 qdata,
42                 dataMap,
43                 qgenericFieldInfo,
44                 isValidityData,
45                 imagesList,
46                 isReadOnlyMode,
47                 isManual : isManual
48         };
49 };
50
51 const mapActionsToProps = (dispatch, {softwareProductId, componentId}) => {
52         return {
53                 onQDataChanged: (deltaData) => ValidationHelper.qDataChanged(dispatch, {deltaData,
54                         qName: COMPONENTS_QUESTIONNAIRE}),
55                 onAddImage: (version, isReadOnlyMode) => {
56                         SoftwareProductComponentsImagesActionHelper.openImageEditor(dispatch,
57                                 {isReadOnlyMode, softwareProductId,
58                                         componentId, version}
59                         );},
60                 onDeleteImage: ((image, version) => {
61                         let shortenedFileName = (image.fileName.length > 40) ? image.fileName.substr(0,40) + '...' : image.fileName;
62                         dispatch({
63                                 type: modalActionTypes.GLOBAL_MODAL_WARNING,
64                                 data: {
65                                         msg: i18n(`Are you sure you want to delete "${shortenedFileName}"?`),
66                                         onConfirmed: () => ImageHelper.deleteImage(dispatch, {
67                                                 softwareProductId,
68                                                 componentId,
69                                                 version,
70                                                 imageId: image.id
71                                         })
72                                 }
73                         });
74                 }),
75                 onEditImageClick: (image, version, isReadOnlyMode) => {
76                         SoftwareProductComponentsImagesActionHelper.openEditImageEditor(dispatch, {
77                                 image, isReadOnlyMode, softwareProductId, componentId, version, modalClassName: 'image-modal-edit'}
78                         );
79                 },
80                 onSubmit: ({qdata}) => { return SoftwareProductComponentsActionHelper.updateSoftwareProductComponentQuestionnaire(dispatch,
81                         {softwareProductId,
82                                 vspComponentId: componentId,
83                                 qdata});
84                 }
85         };
86 };
87
88 export default connect(mapStateToProps, mapActionsToProps, null, {withRef: true})(SoftwareProductComponentsImageListView);