Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 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 | */ |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 16 | import { connect } from 'react-redux'; |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 17 | import i18n from 'nfvo-utils/i18n/i18n.js'; |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 18 | import { actionTypes as globalModalActionTypes } from 'nfvo-components/modal/GlobalModalConstants.js'; |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 19 | import ValidationHelper from 'sdc-app/common/helpers/ValidationHelper.js'; |
| 20 | import Limits from 'sdc-app/onboarding/licenseModel/limits/Limits.jsx'; |
| 21 | |
| 22 | import LicenseKeyGroupsActionHelper from './LicenseKeyGroupsActionHelper.js'; |
| 23 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 24 | const mapStateToProps = ({ |
| 25 | licenseModel: { |
| 26 | licenseKeyGroup: { licenseKeyGroupsEditor: { data } }, |
| 27 | limitEditor |
| 28 | }, |
| 29 | currentScreen |
| 30 | }) => { |
| 31 | let { props: { licenseModelId, version } } = currentScreen; |
| 32 | return { |
| 33 | parent: data, |
| 34 | limitEditor, |
| 35 | licenseModelId, |
| 36 | version |
| 37 | }; |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 38 | }; |
| 39 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 40 | const mapActionsToProps = dispatch => { |
| 41 | return { |
| 42 | onDataChanged: (deltaData, formName, customValidations) => |
| 43 | ValidationHelper.dataChanged(dispatch, { |
| 44 | deltaData, |
| 45 | formName, |
| 46 | customValidations |
| 47 | }), |
| 48 | onSubmit: (limit, licenseKeyGroup, licenseModelId, version) => |
| 49 | LicenseKeyGroupsActionHelper.submitLimit(dispatch, { |
| 50 | limit, |
| 51 | licenseKeyGroup, |
| 52 | licenseModelId, |
| 53 | version |
| 54 | }), |
| 55 | onDelete: ({ |
| 56 | limit, |
| 57 | parent, |
| 58 | licenseModelId, |
| 59 | version, |
| 60 | onCloseLimitEditor, |
| 61 | selectedLimit |
| 62 | }) => |
| 63 | dispatch({ |
| 64 | type: globalModalActionTypes.GLOBAL_MODAL_WARNING, |
| 65 | data: { |
| 66 | msg: i18n('Are you sure you want to delete {name}?', { |
| 67 | name: limit.name |
| 68 | }), |
| 69 | confirmationButtonText: i18n('Delete'), |
| 70 | title: i18n('Delete'), |
| 71 | onConfirmed: () => |
| 72 | LicenseKeyGroupsActionHelper.deleteLimit(dispatch, { |
| 73 | limit, |
| 74 | licenseKeyGroup: parent, |
| 75 | licenseModelId, |
| 76 | version |
| 77 | }).then( |
| 78 | () => |
| 79 | selectedLimit === limit.id && |
| 80 | onCloseLimitEditor() |
| 81 | ) |
| 82 | } |
| 83 | }) |
| 84 | }; |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 85 | }; |
| 86 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 87 | export default connect(mapStateToProps, mapActionsToProps)(Limits); |