Add new code new version
[sdc.git] / openecomp-ui / src / sdc-app / onboarding / softwareProduct / details / SoftwareProductDetails.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 import {connect} from 'react-redux';
22
23 import VersionControllerUtils from 'nfvo-components/panel/versionController/VersionControllerUtils.js';
24 import SoftwareProductActionHelper from 'sdc-app/onboarding/softwareProduct/SoftwareProductActionHelper.js';
25 import SoftwareProductDetailsView from './SoftwareProductDetailsView.jsx';
26
27 export const mapStateToProps = ({finalizedLicenseModelList, softwareProduct, licenseModel: {licenseAgreement, featureGroup}}) => {
28         let {softwareProductEditor: {data: currentSoftwareProduct}, softwareProductCategories, softwareProductQuestionnaire} = softwareProduct;
29         let {licensingData = {}, licensingVersion} = currentSoftwareProduct;
30         let licenseAgreementList = [], filteredFeatureGroupsList = [];
31         if(licensingVersion && licensingVersion !== '') {
32                 licenseAgreementList = licenseAgreement.licenseAgreementList;
33                 let selectedLicenseAgreement = licenseAgreementList.find(la => la.id === licensingData.licenseAgreement);
34                 if (selectedLicenseAgreement) {
35                         let featureGroupsList = featureGroup.featureGroupsList.filter(({referencingLicenseAgreements}) => referencingLicenseAgreements.includes(selectedLicenseAgreement.id));
36                         if (featureGroupsList.length) {
37                                 filteredFeatureGroupsList = featureGroupsList.map(featureGroup => ({enum: featureGroup.id, title: featureGroup.name}));
38                         }
39                 }
40         }
41         let {qdata, qschema} = softwareProductQuestionnaire;
42         let isReadOnlyMode = VersionControllerUtils.isReadOnly(currentSoftwareProduct);
43
44         return {
45                 currentSoftwareProduct,
46                 softwareProductCategories,
47                 licenseAgreementList,
48                 featureGroupsList: filteredFeatureGroupsList,
49                 finalizedLicenseModelList,
50                 qdata,
51                 qschema,
52                 isReadOnlyMode
53         };
54 };
55
56 export const mapActionsToProps = (dispatch) => {
57         return {
58                 onDataChanged: deltaData => SoftwareProductActionHelper.softwareProductEditorDataChanged(dispatch, {deltaData}),
59                 onVendorParamChanged: deltaData => SoftwareProductActionHelper.softwareProductEditorVendorChanged(dispatch, {deltaData}),
60                 onQDataChanged: ({data}) => SoftwareProductActionHelper.softwareProductQuestionnaireUpdate(dispatch, {data}),
61                 onValidityChanged: isValidityData => SoftwareProductActionHelper.setIsValidityData(dispatch, {isValidityData}),
62                 onSubmit: (softwareProduct, qdata) =>{ return SoftwareProductActionHelper.updateSoftwareProduct(dispatch, {softwareProduct, qdata});}
63         };
64 };
65
66 export default connect(mapStateToProps, mapActionsToProps, null, {withRef: true})(SoftwareProductDetailsView);