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 GridSection from 'nfvo-components/grid/GridSection.jsx';
19 import GridItem from 'nfvo-components/grid/GridItem.jsx';
20 import { TabsForm as Form } from 'nfvo-components/input/validation/Form.jsx';
21 import Tabs from 'nfvo-components/input/validation/Tabs.jsx';
22 import Tab from 'sdc-ui/lib/react/Tab.js';
23 import Input from 'nfvo-components/input/validation/Input.jsx';
24 import InputOptions from 'nfvo-components/input/validation/InputOptions.jsx';
25 import DualListboxView from 'nfvo-components/input/dualListbox/DualListboxView.jsx';
26 import i18n from 'nfvo-utils/i18n/i18n.js';
27 import Validator from 'nfvo-utils/Validator.js';
28 import { other as optionInputOther } from 'nfvo-components/input/validation/InputOptions.jsx';
31 enums as LicenseAgreementEnums,
32 optionsInputValues as LicenseAgreementOptionsInputValues,
34 } from './LicenseAgreementConstants.js';
36 const dualBoxFilterTitle = {
37 left: i18n('Available Feature Groups'),
38 right: i18n('Selected Feature Groups')
41 const LicenseAgreementPropType = PropTypes.shape({
43 name: PropTypes.string,
44 description: PropTypes.string,
45 requirementsAndConstrains: PropTypes.string,
46 licenseTerm: PropTypes.object,
47 featureGroupsIds: PropTypes.arrayOf(PropTypes.string),
48 version: PropTypes.object
51 const GeneralTabContent = ({
57 let { name, description, requirementsAndConstrains, licenseTerm } = data;
59 <GridSection hasLastColSet>
60 <GridItem colSpan={2}>
62 isValid={genericFieldInfo.name.isValid}
63 errorText={genericFieldInfo.name.errorText}
65 onDataChanged({ name }, LA_EDITOR_FORM, {
71 data-test-id="create-la-name"
72 name="license-agreement-name"
77 isValid={genericFieldInfo.requirementsAndConstrains.isValid}
79 genericFieldInfo.requirementsAndConstrains.errorText
81 onChange={requirementsAndConstrains =>
83 { requirementsAndConstrains },
87 label={i18n('Requirements and Constraints')}
88 value={requirementsAndConstrains}
89 data-test-id="create-la-requirements-constants"
90 name="license-agreement-requirements-and-constraints"
94 onInputChange={() => {}}
96 onEnumChange={licenseTerm =>
98 { licenseTerm: { choice: licenseTerm, other: '' } },
102 onOtherChange={licenseTerm =>
106 choice: optionInputOther.OTHER,
113 label={i18n('License Term')}
114 data-test-id="create-la-license-term"
117 selectedEnum={licenseTerm && licenseTerm.choice}
118 otherValue={licenseTerm && licenseTerm.other}
120 LicenseAgreementOptionsInputValues.LICENSE_MODEL_TYPE
122 isValid={genericFieldInfo.licenseTerm.isValid}
123 errorText={genericFieldInfo.licenseTerm.errorText}
126 <GridItem colSpan={2} stretch lastColInRow>
128 isValid={genericFieldInfo.description.isValid}
129 errorText={genericFieldInfo.description.errorText}
130 onChange={description =>
131 onDataChanged({ description }, LA_EDITOR_FORM)
133 label={i18n('Description')}
136 data-test-id="create-la-description"
137 name="license-agreement-description"
145 class LicenseAgreementEditorView extends React.Component {
147 data: LicenseAgreementPropType,
148 previousData: LicenseAgreementPropType,
149 LANames: PropTypes.object,
150 isReadOnlyMode: PropTypes.bool,
151 onDataChanged: PropTypes.func.isRequired,
152 onSubmit: PropTypes.func.isRequired,
153 onCancel: PropTypes.func.isRequired,
155 selectedTab: PropTypes.number,
156 onTabSelect: PropTypes.func,
158 selectedFeatureGroupsButtonTab: PropTypes.number,
159 onFeatureGroupsButtonTabSelect: PropTypes.func,
160 featureGroupsList: DualListboxView.propTypes.availableList
163 static defaultProps = {
165 LicenseAgreementEnums.SELECTED_LICENSE_AGREEMENT_TAB.GENERAL,
170 localFeatureGroupsListFilter: ''
185 {genericFieldInfo && (
189 onSubmit={() => this.submit()}
190 onReset={() => this.props.onCancel()}
192 isReadOnlyMode={isReadOnlyMode}
193 isValid={this.props.isFormValid}
194 formReady={this.props.formReady}
195 onValidateForm={() =>
196 this.props.onValidateForm(LA_EDITOR_FORM)
198 className="license-model-form license-agreement-form">
200 activeTab={onTabSelect ? selectedTab : undefined}
201 onTabClick={onTabSelect}
202 invalidTabs={this.props.invalidTabs}>
205 LicenseAgreementEnums
206 .SELECTED_LICENSE_AGREEMENT_TAB.GENERAL
208 data-test-id="general-tab"
209 title={i18n('General')}>
210 <fieldset disabled={isReadOnlyMode}>
213 genericFieldInfo={genericFieldInfo}
214 onDataChanged={onDataChanged}
215 validateLTChoice={value =>
216 this.validateLTChoice(value)
218 validateName={value =>
219 this.validateName(value)
226 LicenseAgreementEnums
227 .SELECTED_LICENSE_AGREEMENT_TAB
230 data-test-id="feature-group-tab"
231 title={i18n('Feature Groups')}>
232 <fieldset disabled={isReadOnlyMode}>
233 {featureGroupsList.length > 0 ? (
235 isReadOnlyMode={isReadOnlyMode}
236 filterTitle={dualBoxFilterTitle}
238 data.featureGroupsIds
240 availableList={featureGroupsList}
241 onChange={selectedValuesList =>
244 featureGroupsIds: selectedValuesList
253 'There are no available feature groups'
268 data: licenseAgreement,
269 previousData: previousLicenseAgreement
271 this.props.onSubmit({ licenseAgreement, previousLicenseAgreement });
274 validateLTChoice(value) {
276 return { isValid: false, errorText: i18n('Field is required') };
278 return { isValid: true, errorText: '' };
281 validateName(value) {
282 const { data: { id }, LANames } = this.props;
283 const isExists = Validator.isItemNameAlreadyExistsInList({
290 ? { isValid: true, errorText: '' }
294 "License Agreement by the name '" +
296 "' already exists. License agreement name must be unique"
302 export default LicenseAgreementEditorView;