react 16 upgrade
[sdc.git] / openecomp-ui / src / sdc-app / onboarding / licenseModel / licenseAgreement / LicenseAgreementListEditor.js
1 /*
2 * Copyright © 2016-2018 European Support Limited
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 or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 import { connect } from 'react-redux';
17 import i18n from 'nfvo-utils/i18n/i18n.js';
18 import sortByStringProperty from 'nfvo-utils/sortByStringProperty.js';
19 import LicenseAgreementActionHelper from './LicenseAgreementActionHelper.js';
20 import LicenseAgreementListEditorView from './LicenseAgreementListEditorView.jsx';
21 import { actionTypes as globalMoadlActions } from 'nfvo-components/modal/GlobalModalConstants.js';
22 import { SORTING_PROPERTY_NAME } from 'sdc-app/onboarding/licenseModel/LicenseModelConstants.js';
23
24 const mapStateToProps = ({
25     licenseModel: { licenseAgreement, licenseModelEditor }
26 }) => {
27     let { licenseAgreementList } = licenseAgreement;
28     let { vendorName, version } = licenseModelEditor.data;
29
30     return {
31         vendorName,
32         version,
33         licenseAgreementList: sortByStringProperty(
34             licenseAgreementList,
35             SORTING_PROPERTY_NAME
36         )
37     };
38 };
39
40 const mapActionsToProps = (dispatch, { licenseModelId }) => {
41     return {
42         onAddLicenseAgreementClick: version =>
43             LicenseAgreementActionHelper.openLicenseAgreementEditor(dispatch, {
44                 licenseModelId,
45                 version,
46                 isReadOnlyMode: false
47             }),
48         onEditLicenseAgreementClick: (
49             licenseAgreement,
50             version,
51             isReadOnlyMode
52         ) =>
53             LicenseAgreementActionHelper.openLicenseAgreementEditor(dispatch, {
54                 licenseModelId,
55                 licenseAgreement,
56                 version,
57                 isReadOnlyMode
58             }),
59         onDeleteLicenseAgreement: (licenseAgreement, version) =>
60             dispatch({
61                 type: globalMoadlActions.GLOBAL_MODAL_WARNING,
62                 data: {
63                     msg: i18n('Are you sure you want to delete "{name}"?', {
64                         name: licenseAgreement.name
65                     }),
66                     confirmationButtonText: i18n('Delete'),
67                     title: i18n('Delete'),
68                     onConfirmed: () =>
69                         LicenseAgreementActionHelper.deleteLicenseAgreement(
70                             dispatch,
71                             {
72                                 licenseModelId,
73                                 licenseAgreementId: licenseAgreement.id,
74                                 version
75                             }
76                         )
77                 }
78             })
79     };
80 };
81
82 export default connect(mapStateToProps, mapActionsToProps)(
83     LicenseAgreementListEditorView
84 );