2 * Copyright © 2016-2018 European Support Limited
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';
29 state as FeatureGroupStateConstants,
31 } from './FeatureGroupsConstants.js';
33 const FeatureGroupsPropType = PropTypes.shape({
35 name: PropTypes.string,
36 description: PropTypes.string,
37 partNumber: PropTypes.string,
38 manufacturerReferenceNumber: PropTypes.string,
39 entitlementPoolsIds: PropTypes.arrayOf(PropTypes.string),
40 licenseKeyGroupsIds: PropTypes.arrayOf(PropTypes.string)
49 let { name, description, partNumber } = data;
51 <GridSection hasLastColSet>
52 <GridItem colSpan={4}>
54 groupClassName="field-section"
56 onDataChanged({ name }, FG_EDITOR_FORM, {
61 data-test-id="create-fg-name"
63 name="feature-group-name"
66 isValid={genericFieldInfo.name.isValid}
67 errorText={genericFieldInfo.name.errorText}
70 <GridItem colSpan={4} lastColInRow strech>
72 groupClassName="field-section"
73 className="description-field"
74 onChange={description =>
75 onDataChanged({ description }, FG_EDITOR_FORM)
77 data-test-id="create-fg-description"
78 label={i18n('Description')}
80 name="feature-group-description"
82 isValid={genericFieldInfo.description.isValid}
83 errorText={genericFieldInfo.description.errorText}
86 <GridItem colSpan={4}>
88 groupClassName="field-section no-bottom-margin"
89 onChange={partNumber =>
90 onDataChanged({ partNumber }, FG_EDITOR_FORM)
92 label={i18n('Part Number')}
93 data-test-id="create-fg-part-number"
97 isValid={genericFieldInfo.partNumber.isValid}
98 errorText={genericFieldInfo.partNumber.errorText}
105 const EntitlementPoolsTab = ({
106 entitlementPoolsList,
111 const dualBoxFilterTitle = {
112 left: i18n('Available Entitlement Pools'),
113 right: i18n('Selected Entitlement Pools')
115 if (entitlementPoolsList.length > 0) {
118 isReadOnlyMode={isReadOnlyMode}
119 filterTitle={dualBoxFilterTitle}
120 selectedValuesList={data.entitlementPoolsIds}
121 availableList={entitlementPoolsList}
122 onChange={selectedValuesList =>
124 { entitlementPoolsIds: selectedValuesList },
131 return <p>{i18n('There are no available entitlement pools')}</p>;
136 licenseKeyGroupsList,
141 const dualBoxFilterTitle = {
142 left: i18n('Available License Key Groups'),
143 right: i18n('Selected License Key Groups')
145 if (licenseKeyGroupsList.length > 0) {
148 isReadOnlyMode={isReadOnlyMode}
149 filterTitle={dualBoxFilterTitle}
150 selectedValuesList={data.licenseKeyGroupsIds}
151 availableList={licenseKeyGroupsList}
152 onChange={selectedValuesList =>
154 { licenseKeyGroupsIds: selectedValuesList },
161 return <p>{i18n('There are no available license key groups')}</p>;
165 class FeatureGroupEditorView extends React.Component {
167 data: FeatureGroupsPropType,
168 previousData: FeatureGroupsPropType,
169 isReadOnlyMode: PropTypes.bool,
170 FGNames: PropTypes.object,
172 onSubmit: PropTypes.func,
173 onCancel: PropTypes.func,
175 selectedTab: PropTypes.number,
176 onTabSelect: PropTypes.func,
178 entitlementPoolsList: DualListboxView.propTypes.availableList,
179 licenseKeyGroupsList: DualListboxView.propTypes.availableList
182 static defaultProps = {
185 FeatureGroupStateConstants.SELECTED_FEATURE_GROUP_TAB.GENERAL
189 localEntitlementPoolsListFilter: '',
190 localLicenseKeyGroupsListFilter: ''
202 entitlementPoolsList,
206 <div className="license-model-modal feature-group-modal">
207 {genericFieldInfo && (
211 onSubmit={() => this.submit()}
212 isValid={this.props.isFormValid}
213 formReady={this.props.formReady}
214 onValidateForm={() =>
215 this.props.onValidateForm(FG_EDITOR_FORM)
217 onReset={() => this.props.onCancel()}
219 isReadOnlyMode={isReadOnlyMode}
220 name="feature-group-validation-form"
221 btnClassName="sdc-modal__footer"
222 className="license-model-form feature-group-form">
224 activeTab={onTabSelect ? selectedTab : undefined}
225 onTabClick={onTabSelect}
226 invalidTabs={invalidTabs}
230 FeatureGroupStateConstants
231 .SELECTED_FEATURE_GROUP_TAB.GENERAL
233 title={i18n('General')}>
234 <fieldset disabled={isReadOnlyMode}>
237 onDataChanged={onDataChanged}
238 genericFieldInfo={genericFieldInfo}
239 validateName={value =>
240 this.validateName(value)
247 FeatureGroupStateConstants
248 .SELECTED_FEATURE_GROUP_TAB
251 title={i18n('Entitlement Pools')}>
252 <fieldset disabled={isReadOnlyMode}>
254 isReadOnlyMode={isReadOnlyMode}
256 onDataChanged={onDataChanged}
257 entitlementPoolsList={
265 FeatureGroupStateConstants
266 .SELECTED_FEATURE_GROUP_TAB
269 title={i18n('License Key Groups')}>
270 <fieldset disabled={isReadOnlyMode}>
272 isReadOnlyMode={isReadOnlyMode}
274 onDataChanged={onDataChanged}
275 licenseKeyGroupsList={
291 previousData: previousFeatureGroup
293 this.props.onSubmit(previousFeatureGroup, featureGroup);
296 validateName(value) {
297 const { data: { id }, FGNames } = this.props;
298 const isExists = Validator.isItemNameAlreadyExistsInList({
305 ? { isValid: true, errorText: '' }
309 "Feature group by the name '" +
311 "' already exists. Feature group name must be unique"
317 export default FeatureGroupEditorView;