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';
30 import {enums as LicenseAgreementEnums, optionsInputValues as LicenseAgreementOptionsInputValues, LA_EDITOR_FORM} from './LicenseAgreementConstants.js';
32 const dualBoxFilterTitle = {
33 left: i18n('Available Feature Groups'),
34 right: i18n('Selected Feature Groups')
37 const LicenseAgreementPropType = PropTypes.shape({
39 name: PropTypes.string,
40 description: PropTypes.string,
41 requirementsAndConstrains: PropTypes.string,
42 licenseTerm: PropTypes.object,
43 featureGroupsIds: PropTypes.arrayOf(PropTypes.string),
44 version: PropTypes.object
48 const GeneralTabContent = ({data, genericFieldInfo, onDataChanged, validateName}) => {
49 let {name, description, requirementsAndConstrains, licenseTerm} = data;
51 <GridSection hasLastColSet>
52 <GridItem colSpan={2}>
54 isValid={genericFieldInfo.name.isValid}
55 errorText={genericFieldInfo.name.errorText}
56 onChange={name => onDataChanged({name}, LA_EDITOR_FORM, { name: validateName })}
59 data-test-id='create-la-name'
60 name='license-agreement-name'
64 isValid={genericFieldInfo.requirementsAndConstrains.isValid}
65 errorText={genericFieldInfo.requirementsAndConstrains.errorText}
66 onChange={requirementsAndConstrains => onDataChanged({requirementsAndConstrains}, LA_EDITOR_FORM)}
67 label={i18n('Requirements and Constraints')}
68 value={requirementsAndConstrains}
69 data-test-id='create-la-requirements-constants'
70 name='license-agreement-requirements-and-constraints'
73 onInputChange={()=>{}}
75 onEnumChange={licenseTerm => onDataChanged({licenseTerm:{choice: licenseTerm, other: ''}},
77 onOtherChange={licenseTerm => onDataChanged({licenseTerm:{choice: optionInputOther.OTHER,
78 other: licenseTerm}}, LA_EDITOR_FORM)}
79 label={i18n('License Term')}
80 data-test-id='create-la-license-term'
83 selectedEnum={licenseTerm && licenseTerm.choice}
84 otherValue={licenseTerm && licenseTerm.other}
85 values={LicenseAgreementOptionsInputValues.LICENSE_MODEL_TYPE}
86 isValid={genericFieldInfo.licenseTerm.isValid}
87 errorText={genericFieldInfo.licenseTerm.errorText} />
89 <GridItem colSpan={2} stretch lastColInRow>
91 isValid={genericFieldInfo.description.isValid}
92 errorText={genericFieldInfo.description.errorText}
93 onChange={description => onDataChanged({description}, LA_EDITOR_FORM)}
94 label={i18n('Description')}
97 data-test-id='create-la-description'
98 name='license-agreement-description'
105 class LicenseAgreementEditorView extends React.Component {
108 data: LicenseAgreementPropType,
109 previousData: LicenseAgreementPropType,
110 LANames: PropTypes.object,
111 isReadOnlyMode: PropTypes.bool,
112 onDataChanged: PropTypes.func.isRequired,
113 onSubmit: PropTypes.func.isRequired,
114 onCancel: PropTypes.func.isRequired,
116 selectedTab: PropTypes.number,
117 onTabSelect: PropTypes.func,
119 selectedFeatureGroupsButtonTab: PropTypes.number,
120 onFeatureGroupsButtonTabSelect: PropTypes.func,
121 featureGroupsList: DualListboxView.propTypes.availableList
124 static defaultProps = {
125 selectedTab: LicenseAgreementEnums.SELECTED_LICENSE_AGREEMENT_TAB.GENERAL,
130 localFeatureGroupsListFilter: ''
134 let {selectedTab, onTabSelect, isReadOnlyMode, featureGroupsList, data, onDataChanged, genericFieldInfo} = this.props;
137 {genericFieldInfo && <Form
140 onSubmit={ () => this.submit() }
141 onReset={ () => this.props.onCancel() }
143 isReadOnlyMode={isReadOnlyMode}
144 isValid={this.props.isFormValid}
145 formReady={this.props.formReady}
146 onValidateForm={() => this.props.onValidateForm(LA_EDITOR_FORM) }
147 className='license-model-form license-agreement-form'>
148 <Tabs activeTab={onTabSelect ? selectedTab : undefined} onTabClick={onTabSelect} invalidTabs={this.props.invalidTabs} >
150 tabId={LicenseAgreementEnums.SELECTED_LICENSE_AGREEMENT_TAB.GENERAL}
151 data-test-id='general-tab'
152 title={i18n('General')}>
153 <fieldset disabled={isReadOnlyMode}>
154 <GeneralTabContent data={data} genericFieldInfo={genericFieldInfo} onDataChanged={onDataChanged} validateLTChoice={(value)=>this.validateLTChoice(value)}
155 validateName={(value)=>this.validateName(value)}/>
159 tabId={LicenseAgreementEnums.SELECTED_LICENSE_AGREEMENT_TAB.FEATURE_GROUPS}
160 data-test-id='feature-group-tab'
161 title={i18n('Feature Groups')}>
162 <fieldset disabled={isReadOnlyMode}>
163 {featureGroupsList.length > 0 ?
165 isReadOnlyMode={isReadOnlyMode}
166 filterTitle={dualBoxFilterTitle}
167 selectedValuesList={data.featureGroupsIds}
168 availableList={featureGroupsList}
169 onChange={ selectedValuesList => onDataChanged( { featureGroupsIds: selectedValuesList }, LA_EDITOR_FORM )}/> :
170 <p>{i18n('There are no available feature groups')}</p>}
180 const {data: licenseAgreement, previousData: previousLicenseAgreement} = this.props;
181 this.props.onSubmit({licenseAgreement, previousLicenseAgreement});
184 validateLTChoice(value) {
186 return {isValid: false, errorText: i18n('Field is required')};
188 return {isValid: true, errorText: ''};
191 validateName(value) {
192 const {data: {id}, LANames} = this.props;
193 const isExists = Validator.isItemNameAlreadyExistsInList({itemId: id, itemName: value, list: LANames});
195 return !isExists ? {isValid: true, errorText: ''} :
196 {isValid: false, errorText: i18n('License Agreement by the name \'' + value + '\' already exists. License agreement name must be unique')};
200 export default LicenseAgreementEditorView;