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 or implied.
13 * See the License for the specific language governing permissions and
14 * 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 licenseTerm: PropTypes.object,
46 featureGroupsIds: PropTypes.arrayOf(PropTypes.string),
47 version: PropTypes.object
50 const GeneralTabContent = ({
56 let { name, description, licenseTerm } = data;
58 <GridSection hasLastColSet>
59 <GridItem colSpan={2}>
61 isValid={genericFieldInfo.name.isValid}
62 errorText={genericFieldInfo.name.errorText}
64 onDataChanged({ name }, LA_EDITOR_FORM, {
70 data-test-id="create-la-name"
71 name="license-agreement-name"
76 onInputChange={() => {}}
78 onEnumChange={licenseTerm =>
89 onOtherChange={licenseTerm =>
93 choice: optionInputOther.OTHER,
100 label={i18n('License Term')}
101 data-test-id="create-la-license-term"
104 selectedEnum={licenseTerm && licenseTerm.choice}
105 otherValue={licenseTerm && licenseTerm.other}
107 LicenseAgreementOptionsInputValues.LICENSE_MODEL_TYPE
109 isValid={genericFieldInfo.licenseTerm.isValid}
110 errorText={genericFieldInfo.licenseTerm.errorText}
113 <GridItem colSpan={2} stretch lastColInRow>
115 isValid={genericFieldInfo.description.isValid}
116 errorText={genericFieldInfo.description.errorText}
117 onChange={description =>
118 onDataChanged({ description }, LA_EDITOR_FORM)
120 label={i18n('Description')}
123 data-test-id="create-la-description"
124 name="license-agreement-description"
132 class LicenseAgreementEditorView extends React.Component {
134 data: LicenseAgreementPropType,
135 previousData: LicenseAgreementPropType,
136 LANames: PropTypes.object,
137 isReadOnlyMode: PropTypes.bool,
138 onDataChanged: PropTypes.func.isRequired,
139 onSubmit: PropTypes.func.isRequired,
140 onCancel: PropTypes.func.isRequired,
142 selectedTab: PropTypes.number,
143 onTabSelect: PropTypes.func,
145 selectedFeatureGroupsButtonTab: PropTypes.number,
146 onFeatureGroupsButtonTabSelect: PropTypes.func,
147 featureGroupsList: DualListboxView.propTypes.availableList
150 static defaultProps = {
152 LicenseAgreementEnums.SELECTED_LICENSE_AGREEMENT_TAB.GENERAL,
157 localFeatureGroupsListFilter: ''
171 <div className="license-model-modal license-agreement-modal">
172 {genericFieldInfo && (
176 onSubmit={() => this.submit()}
177 onReset={() => this.props.onCancel()}
179 isReadOnlyMode={isReadOnlyMode}
180 isValid={this.props.isFormValid}
181 formReady={this.props.formReady}
182 onValidateForm={() =>
183 this.props.onValidateForm(LA_EDITOR_FORM)
185 className="license-model-form license-agreement-form"
186 btnClassName="sdc-modal__footer">
188 activeTab={onTabSelect ? selectedTab : undefined}
189 onTabClick={onTabSelect}
190 invalidTabs={this.props.invalidTabs}>
193 LicenseAgreementEnums
194 .SELECTED_LICENSE_AGREEMENT_TAB.GENERAL
196 data-test-id="general-tab"
197 title={i18n('General')}>
198 <fieldset disabled={isReadOnlyMode}>
201 genericFieldInfo={genericFieldInfo}
202 onDataChanged={onDataChanged}
203 validateLTChoice={value =>
204 this.validateLTChoice(value)
206 validateName={value =>
207 this.validateName(value)
214 LicenseAgreementEnums
215 .SELECTED_LICENSE_AGREEMENT_TAB
218 data-test-id="feature-group-tab"
219 title={i18n('Feature Groups')}>
220 <fieldset disabled={isReadOnlyMode}>
221 {featureGroupsList.length > 0 ? (
223 isReadOnlyMode={isReadOnlyMode}
224 filterTitle={dualBoxFilterTitle}
226 data.featureGroupsIds
228 availableList={featureGroupsList}
229 onChange={selectedValuesList =>
232 featureGroupsIds: selectedValuesList
241 'There are no available feature groups'
256 data: licenseAgreement,
257 previousData: previousLicenseAgreement
259 this.props.onSubmit({ licenseAgreement, previousLicenseAgreement });
262 validateLTChoice(value) {
264 return { isValid: false, errorText: i18n('Field is required') };
266 return { isValid: true, errorText: '' };
269 validateName(value) {
270 const { data: { id }, LANames } = this.props;
271 const isExists = Validator.isItemNameAlreadyExistsInList({
278 ? { isValid: true, errorText: '' }
282 "License Agreement by the name '" +
284 "' already exists. License agreement name must be unique"
290 export default LicenseAgreementEditorView;