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