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 React from 'react';
17 import PropTypes from 'prop-types';
18 import Tabs from 'nfvo-components/input/validation/Tabs.jsx';
19 import Tab from 'sdc-ui/lib/react/Tab.js';
20 import GridSection from 'nfvo-components/grid/GridSection.jsx';
21 import GridItem from 'nfvo-components/grid/GridItem.jsx';
22 import {TabsForm as Form} from 'nfvo-components/input/validation/Form.jsx';
23 import DualListboxView from 'nfvo-components/input/dualListbox/DualListboxView.jsx';
24 import Input from 'nfvo-components/input/validation/Input.jsx';
25 import i18n from 'nfvo-utils/i18n/i18n.js';
26 import Validator from 'nfvo-utils/Validator.js';
28 import {state as FeatureGroupStateConstants, FG_EDITOR_FORM} from './FeatureGroupsConstants.js';
30 const FeatureGroupsPropType = PropTypes.shape({
32 name: PropTypes.string,
33 description: PropTypes.string,
34 partNumber: PropTypes.string,
35 manufacturerReferenceNumber: PropTypes.string,
36 entitlementPoolsIds: PropTypes.arrayOf(PropTypes.string),
37 licenseKeyGroupsIds: PropTypes.arrayOf(PropTypes.string)
40 const GeneralTab = ({data = {}, onDataChanged, genericFieldInfo, validateName}) => {
41 let {name, description, partNumber, manufacturerReferenceNumber} = data;
43 <GridSection hasLastColSet>
44 <GridItem colSpan={2}>
46 groupClassName='field-section'
47 onChange={name => onDataChanged({name}, FG_EDITOR_FORM, {name: validateName})}
49 data-test-id='create-fg-name'
51 name='feature-group-name'
54 isValid={genericFieldInfo.name.isValid}
55 errorText={genericFieldInfo.name.errorText} />
57 <GridItem colSpan={2} lastColInRow>
59 groupClassName='field-section'
60 className='description-field'
61 onChange={description => onDataChanged({description}, FG_EDITOR_FORM)}
62 data-test-id='create-fg-description'
63 label={i18n('Description')}
65 name='feature-group-description'
67 isValid={genericFieldInfo.description.isValid}
68 errorText={genericFieldInfo.description.errorText} />
70 <GridItem colSpan={2}>
72 groupClassName='field-section'
73 onChange={partNumber => onDataChanged({partNumber}, FG_EDITOR_FORM)}
74 label={i18n('Part Number')}
75 data-test-id='create-fg-part-number'
79 isValid={genericFieldInfo.partNumber.isValid}
80 errorText={genericFieldInfo.partNumber.errorText} />
82 <GridItem colSpan={2} lastColInRow>
84 groupClassName='field-section'
85 onChange={manufacturerReferenceNumber => onDataChanged({manufacturerReferenceNumber}, FG_EDITOR_FORM)}
86 label={i18n('Manufacturer Reference Number')}
87 data-test-id='create-fg-reference-number'
88 value={manufacturerReferenceNumber}
91 isValid={genericFieldInfo.manufacturerReferenceNumber.isValid}
92 errorText={genericFieldInfo.manufacturerReferenceNumber.errorText} />
98 const EntitlementPoolsTab = ({entitlementPoolsList, data, onDataChanged, isReadOnlyMode}) => {
99 const dualBoxFilterTitle = {
100 left: i18n('Available Entitlement Pools'),
101 right: i18n('Selected Entitlement Pools')
103 if (entitlementPoolsList.length > 0) {
106 isReadOnlyMode={isReadOnlyMode}
107 filterTitle={dualBoxFilterTitle}
108 selectedValuesList={data.entitlementPoolsIds}
109 availableList={entitlementPoolsList}
110 onChange={ selectedValuesList => onDataChanged( { entitlementPoolsIds: selectedValuesList }, FG_EDITOR_FORM )}/>
114 <p>{i18n('There are no available entitlement pools')}</p>
119 const LKGTab = ({licenseKeyGroupsList, data, onDataChanged, isReadOnlyMode}) => {
120 const dualBoxFilterTitle = {
121 left: i18n('Available License Key Groups'),
122 right: i18n('Selected License Key Groups')
124 if (licenseKeyGroupsList.length > 0) {
127 isReadOnlyMode={isReadOnlyMode}
128 filterTitle={dualBoxFilterTitle}
129 selectedValuesList={data.licenseKeyGroupsIds}
130 availableList={licenseKeyGroupsList}
131 onChange={ selectedValuesList => onDataChanged( { licenseKeyGroupsIds: selectedValuesList }, FG_EDITOR_FORM )}/>
135 <p>{i18n('There are no available license key groups')}</p>
140 class FeatureGroupEditorView extends React.Component {
144 data: FeatureGroupsPropType,
145 previousData: FeatureGroupsPropType,
146 isReadOnlyMode: PropTypes.bool,
147 FGNames: PropTypes.object,
149 onSubmit: PropTypes.func,
150 onCancel: PropTypes.func,
152 selectedTab: PropTypes.number,
153 onTabSelect: PropTypes.func,
155 entitlementPoolsList: DualListboxView.propTypes.availableList,
156 licenseKeyGroupsList: DualListboxView.propTypes.availableList
160 static defaultProps = {
162 selectedTab: FeatureGroupStateConstants.SELECTED_FEATURE_GROUP_TAB.GENERAL,
166 localEntitlementPoolsListFilter: '',
167 localLicenseKeyGroupsListFilter: ''
172 let {selectedTab, onTabSelect, isReadOnlyMode, invalidTabs, data, onDataChanged, genericFieldInfo, entitlementPoolsList, licenseKeyGroupsList} = this.props;
175 { genericFieldInfo && <Form
178 onSubmit={ () => this.submit() }
179 isValid={this.props.isFormValid}
180 formReady={this.props.formReady}
181 onValidateForm={() => this.props.onValidateForm(FG_EDITOR_FORM) }
182 onReset={ () => this.props.onCancel() }
184 isReadOnlyMode={isReadOnlyMode}
185 name='feature-group-validation-form'
186 className='license-model-form feature-group-form'>
187 <Tabs activeTab={onTabSelect ? selectedTab : undefined} onTabClick={onTabSelect} invalidTabs={invalidTabs} id='vlmFGValTabs' >
188 <Tab tabId={FeatureGroupStateConstants.SELECTED_FEATURE_GROUP_TAB.GENERAL} title={i18n('General')} >
189 <fieldset disabled={isReadOnlyMode}>
190 <GeneralTab data={data} onDataChanged={onDataChanged} genericFieldInfo={genericFieldInfo} validateName={(value)=> this.validateName(value)}/>
194 tabId={FeatureGroupStateConstants.SELECTED_FEATURE_GROUP_TAB.ENTITLEMENT_POOLS}
195 title={i18n('Entitlement Pools')} >
196 <fieldset disabled={isReadOnlyMode}>
197 <EntitlementPoolsTab isReadOnlyMode={isReadOnlyMode} data={data} onDataChanged={onDataChanged} entitlementPoolsList={entitlementPoolsList} />
201 tabId={FeatureGroupStateConstants.SELECTED_FEATURE_GROUP_TAB.LICENSE_KEY_GROUPS}
202 title={i18n('License Key Groups')} >
203 <fieldset disabled={isReadOnlyMode}>
204 <LKGTab isReadOnlyMode={isReadOnlyMode} data={data} onDataChanged={onDataChanged} licenseKeyGroupsList={licenseKeyGroupsList} />
215 const {data: featureGroup, previousData: previousFeatureGroup} = this.props;
216 this.props.onSubmit(previousFeatureGroup, featureGroup);
219 validateName(value) {
220 const {data: {id}, FGNames} = this.props;
221 const isExists = Validator.isItemNameAlreadyExistsInList({itemId: id, itemName: value, list: FGNames});
223 return !isExists ? {isValid: true, errorText: ''} :
224 {isValid: false, errorText: i18n('Feature group by the name \'' + value + '\' already exists. Feature group name must be unique')};
229 export default FeatureGroupEditorView;