2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 import {connect} from 'react-redux';
18 import FeatureGroupsActionHelper from './FeatureGroupsActionHelper.js';
19 import FeatureGroupEditorView from './FeatureGroupEditorView.jsx';
20 import ValidationHelper from 'sdc-app/common/helpers/ValidationHelper.js';
22 export const mapStateToProps = ({licenseModel: {featureGroup, entitlementPool, licenseKeyGroup}}) => {
23 let {entitlementPoolsList = []} = entitlementPool;
24 let {licenseKeyGroupsList = []} = licenseKeyGroup;
25 const {featureGroupEditor} = featureGroup;
26 let {data, selectedTab, genericFieldInfo, formReady} = featureGroupEditor;
27 const featureGroupId = data ? data.id : null;
28 const list = featureGroup.featureGroupsList;
30 let previousData, FGNames = {}, isFormValid = true, invalidTabs = [];
33 previousData = list.find(featureGroup => featureGroup.id === featureGroupId);
36 for (let i = 0; i < list.length; i++) {
37 FGNames[list[i].name.toLowerCase()] = list[i].id;
40 for (let field in genericFieldInfo) {
41 if (!genericFieldInfo[field].isValid) {
43 let tabId = genericFieldInfo[field].tabId;
44 if (invalidTabs.indexOf(tabId) === -1) {
45 invalidTabs[invalidTabs.length] = genericFieldInfo[field].tabId;
65 const mapActionsToProps = (dispatch, {licenseModelId, version}) => {
67 onDataChanged: (deltaData, formName, customValidations) => ValidationHelper.dataChanged(dispatch, {deltaData, formName, customValidations}),
68 onTabSelect: tab => FeatureGroupsActionHelper.selectEntitlementPoolsEditorTab(dispatch, {tab}),
69 onSubmit: (previousFeatureGroup, featureGroup) => {
70 FeatureGroupsActionHelper.closeFeatureGroupsEditor(dispatch);
71 FeatureGroupsActionHelper.saveFeatureGroup(dispatch, {licenseModelId, previousFeatureGroup, featureGroup, version});
73 onCancel: () => FeatureGroupsActionHelper.closeFeatureGroupsEditor(dispatch),
74 onValidateForm: (formName) => ValidationHelper.validateForm(dispatch, formName)
78 export default connect(mapStateToProps, mapActionsToProps)(FeatureGroupEditorView);