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 Tabs from 'nfvo-components/input/validation/Tabs.jsx';
18 import Tab from 'sdc-ui/lib/react/Tab.js';
19 import GridSection from 'nfvo-components/grid/GridSection.jsx';
20 import GridItem from 'nfvo-components/grid/GridItem.jsx';
21 import {TabsForm as Form} from 'nfvo-components/input/validation/Form.jsx';
22 import DualListboxView from 'nfvo-components/input/dualListbox/DualListboxView.jsx';
23 import Input from 'nfvo-components/input/validation/Input.jsx';
24 import i18n from 'nfvo-utils/i18n/i18n.js';
25 import Validator from 'nfvo-utils/Validator.js';
27 import {state as FeatureGroupStateConstants, FG_EDITOR_FORM} from './FeatureGroupsConstants.js';
29 const FeatureGroupsPropType = React.PropTypes.shape({
30 id: React.PropTypes.string,
31 name: React.PropTypes.string,
32 description: React.PropTypes.string,
33 partNumber: React.PropTypes.string,
34 manufacturerReferenceNumber: React.PropTypes.string,
35 entitlementPoolsIds: React.PropTypes.arrayOf(React.PropTypes.string),
36 licenseKeyGroupsIds: React.PropTypes.arrayOf(React.PropTypes.string)
39 const GeneralTab = ({data = {}, onDataChanged, genericFieldInfo, validateName}) => {
40 let {name, description, partNumber, manufacturerReferenceNumber} = data;
43 <GridItem colSpan={2}>
45 groupClassName='field-section'
46 onChange={name => onDataChanged({name}, FG_EDITOR_FORM, {name: validateName})}
48 data-test-id='create-fg-name'
50 name='feature-group-name'
53 isValid={genericFieldInfo.name.isValid}
54 errorText={genericFieldInfo.name.errorText} />
56 <GridItem colSpan={2}>
58 groupClassName='field-section'
59 className='description-field'
60 onChange={description => onDataChanged({description}, FG_EDITOR_FORM)}
61 data-test-id='create-fg-description'
62 label={i18n('Description')}
64 name='feature-group-description'
66 isValid={genericFieldInfo.description.isValid}
67 errorText={genericFieldInfo.description.errorText} />
69 <GridItem colSpan={2}>
71 groupClassName='field-section'
72 onChange={partNumber => onDataChanged({partNumber}, FG_EDITOR_FORM)}
73 label={i18n('Part Number')}
74 data-test-id='create-fg-part-number'
78 isValid={genericFieldInfo.partNumber.isValid}
79 errorText={genericFieldInfo.partNumber.errorText} />
81 <GridItem colSpan={2}>
83 groupClassName='field-section'
84 onChange={manufacturerReferenceNumber => onDataChanged({manufacturerReferenceNumber}, FG_EDITOR_FORM)}
85 label={i18n('Manufacturer Reference Number')}
86 data-test-id='create-fg-reference-number'
87 value={manufacturerReferenceNumber}
90 isValid={genericFieldInfo.manufacturerReferenceNumber.isValid}
91 errorText={genericFieldInfo.manufacturerReferenceNumber.errorText} />
97 const EntitlementPoolsTab = ({entitlementPoolsList, data, onDataChanged, isReadOnlyMode}) => {
98 const dualBoxFilterTitle = {
99 left: i18n('Available Entitlement Pools'),
100 right: i18n('Selected Entitlement Pools')
102 if (entitlementPoolsList.length > 0) {
105 isReadOnlyMode={isReadOnlyMode}
106 filterTitle={dualBoxFilterTitle}
107 selectedValuesList={data.entitlementPoolsIds}
108 availableList={entitlementPoolsList}
109 onChange={ selectedValuesList => onDataChanged( { entitlementPoolsIds: selectedValuesList }, FG_EDITOR_FORM )}/>
113 <p>{i18n('There are no available entitlement pools')}</p>
118 const LKGTab = ({licenseKeyGroupsList, data, onDataChanged, isReadOnlyMode}) => {
119 const dualBoxFilterTitle = {
120 left: i18n('Available License Key Groups'),
121 right: i18n('Selected License Key Groups')
123 if (licenseKeyGroupsList.length > 0) {
126 isReadOnlyMode={isReadOnlyMode}
127 filterTitle={dualBoxFilterTitle}
128 selectedValuesList={data.licenseKeyGroupsIds}
129 availableList={licenseKeyGroupsList}
130 onChange={ selectedValuesList => onDataChanged( { licenseKeyGroupsIds: selectedValuesList }, FG_EDITOR_FORM )}/>
134 <p>{i18n('There are no available license key groups')}</p>
139 class FeatureGroupEditorView extends React.Component {
143 data: FeatureGroupsPropType,
144 previousData: FeatureGroupsPropType,
145 isReadOnlyMode: React.PropTypes.bool,
146 FGNames: React.PropTypes.object,
148 onSubmit: React.PropTypes.func,
149 onCancel: React.PropTypes.func,
151 selectedTab: React.PropTypes.number,
152 onTabSelect: React.PropTypes.func,
154 entitlementPoolsList: DualListboxView.propTypes.availableList,
155 licenseKeyGroupsList: DualListboxView.propTypes.availableList
159 static defaultProps = {
161 selectedTab: FeatureGroupStateConstants.SELECTED_FEATURE_GROUP_TAB.GENERAL,
165 localEntitlementPoolsListFilter: '',
166 localLicenseKeyGroupsListFilter: ''
171 let {selectedTab, onTabSelect, isReadOnlyMode, invalidTabs, data, onDataChanged, genericFieldInfo, entitlementPoolsList, licenseKeyGroupsList} = this.props;
174 { genericFieldInfo && <Form
177 onSubmit={ () => this.submit() }
178 isValid={this.props.isFormValid}
179 formReady={this.props.formReady}
180 onValidateForm={() => this.props.onValidateForm(FG_EDITOR_FORM) }
181 onReset={ () => this.props.onCancel() }
183 isReadOnlyMode={isReadOnlyMode}
184 name='feature-group-validation-form'
185 className='license-model-form feature-group-form'>
186 <Tabs activeTab={onTabSelect ? selectedTab : undefined} onTabClick={onTabSelect} invalidTabs={invalidTabs} id='vlmFGValTabs' >
187 <Tab tabId={FeatureGroupStateConstants.SELECTED_FEATURE_GROUP_TAB.GENERAL} title={i18n('General')} >
188 <fieldset disabled={isReadOnlyMode}>
189 <GeneralTab data={data} onDataChanged={onDataChanged} genericFieldInfo={genericFieldInfo} validateName={(value)=> this.validateName(value)}/>
193 tabId={FeatureGroupStateConstants.SELECTED_FEATURE_GROUP_TAB.ENTITLEMENT_POOLS}
194 title={i18n('Entitlement Pools')} >
195 <fieldset disabled={isReadOnlyMode}>
196 <EntitlementPoolsTab isReadOnlyMode={isReadOnlyMode} data={data} onDataChanged={onDataChanged} entitlementPoolsList={entitlementPoolsList} />
200 tabId={FeatureGroupStateConstants.SELECTED_FEATURE_GROUP_TAB.LICENSE_KEY_GROUPS}
201 title={i18n('License Key Groups')} >
202 <fieldset disabled={isReadOnlyMode}>
203 <LKGTab isReadOnlyMode={isReadOnlyMode} data={data} onDataChanged={onDataChanged} licenseKeyGroupsList={licenseKeyGroupsList} />
214 const {data: featureGroup, previousData: previousFeatureGroup} = this.props;
215 this.props.onSubmit(previousFeatureGroup, featureGroup);
218 validateName(value) {
219 const {data: {id}, FGNames} = this.props;
220 const isExists = Validator.isItemNameAlreadyExistsInList({itemId: id, itemName: value, list: FGNames});
222 return !isExists ? {isValid: true, errorText: ''} :
223 {isValid: false, errorText: i18n('Feature group by the name \'' + value + '\' already exists. Feature group name must be unique')};
228 export default FeatureGroupEditorView;