react 16 upgrade
[sdc.git] / openecomp-ui / src / sdc-app / onboarding / licenseModel / entitlementPools / EntitlementPoolsListEditor.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 EntitlementPoolsActionHelper from './EntitlementPoolsActionHelper.js';
20 import EntitlementPoolsListEditorView, {
21     generateConfirmationMsg
22 } from './EntitlementPoolsListEditorView.jsx';
23 import { actionTypes as globalMoadlActions } from 'nfvo-components/modal/GlobalModalConstants.js';
24 import { SORTING_PROPERTY_NAME } from 'sdc-app/onboarding/licenseModel/LicenseModelConstants.js';
25
26 const mapStateToProps = ({
27     licenseModel: { entitlementPool, licenseModelEditor }
28 }) => {
29     const { entitlementPoolsList } = entitlementPool;
30     const { vendorName } = licenseModelEditor.data;
31
32     return {
33         vendorName,
34         entitlementPoolsList: sortByStringProperty(
35             entitlementPoolsList,
36             SORTING_PROPERTY_NAME
37         )
38     };
39 };
40
41 const mapActionsToProps = (
42     dispatch,
43     { licenseModelId, version, isReadOnlyMode }
44 ) => {
45     return {
46         onAddEntitlementPoolClick: () =>
47             EntitlementPoolsActionHelper.openEntitlementPoolsEditor(dispatch, {
48                 licenseModelId,
49                 version,
50                 isReadOnlyMode
51             }),
52         onEditEntitlementPoolClick: entitlementPool =>
53             EntitlementPoolsActionHelper.openEntitlementPoolsEditor(dispatch, {
54                 entitlementPool,
55                 licenseModelId,
56                 version,
57                 isReadOnlyMode
58             }),
59         onDeleteEntitlementPool: entitlementPool =>
60             dispatch({
61                 type: globalMoadlActions.GLOBAL_MODAL_WARNING,
62                 data: {
63                     msg: generateConfirmationMsg(entitlementPool),
64                     confirmationButtonText: i18n('Delete'),
65                     title: i18n('Delete'),
66                     onConfirmed: () =>
67                         EntitlementPoolsActionHelper.deleteEntitlementPool(
68                             dispatch,
69                             {
70                                 licenseModelId,
71                                 entitlementPoolId: entitlementPool.id,
72                                 version
73                             }
74                         )
75                 }
76             })
77     };
78 };
79
80 export default connect(mapStateToProps, mapActionsToProps)(
81     EntitlementPoolsListEditorView
82 );