react 16 upgrade
[sdc.git] / openecomp-ui / src / sdc-app / onboarding / licenseModel / featureGroups / FeatureGroupListEditor.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 sortByStringProperty from 'nfvo-utils/sortByStringProperty.js';
18 import FeatureGroupsActionHelper from './FeatureGroupsActionHelper.js';
19 import FeatureGroupListEditorView, {
20     generateConfirmationMsg
21 } from './FeatureGroupListEditorView.jsx';
22 import i18n from 'nfvo-utils/i18n/i18n.js';
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 export const mapStateToProps = ({
27     licenseModel: { featureGroup, licenseModelEditor }
28 }) => {
29     const { featureGroupsList } = featureGroup;
30     const { vendorName, version } = licenseModelEditor.data;
31
32     return {
33         vendorName,
34         version,
35         featureGroupsList: sortByStringProperty(
36             featureGroupsList,
37             SORTING_PROPERTY_NAME
38         )
39     };
40 };
41
42 const mapActionsToProps = (dispatch, { licenseModelId }) => {
43     return {
44         onDeleteFeatureGroupClick: (featureGroup, version) =>
45             dispatch({
46                 type: globalMoadlActions.GLOBAL_MODAL_WARNING,
47                 data: {
48                     msg: generateConfirmationMsg(featureGroup),
49                     confirmationButtonText: i18n('Delete'),
50                     title: i18n('Delete'),
51                     onConfirmed: () =>
52                         FeatureGroupsActionHelper.deleteFeatureGroup(dispatch, {
53                             featureGroupId: featureGroup.id,
54                             licenseModelId,
55                             version
56                         })
57                 }
58             }),
59         onAddFeatureGroupClick: actualVersion =>
60             FeatureGroupsActionHelper.openFeatureGroupsEditor(dispatch, {
61                 licenseModelId,
62                 version: actualVersion,
63                 isReadOnlyMode: false
64             }),
65         onEditFeatureGroupClick: (
66             featureGroup,
67             actualVersion,
68             isReadOnlyMode
69         ) =>
70             FeatureGroupsActionHelper.openFeatureGroupsEditor(dispatch, {
71                 featureGroup,
72                 licenseModelId,
73                 version: actualVersion,
74                 isReadOnlyMode
75             })
76     };
77 };
78
79 export default connect(mapStateToProps, mapActionsToProps)(
80     FeatureGroupListEditorView
81 );