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 i18n from 'nfvo-utils/i18n/i18n.js';
19 import Input from 'nfvo-components/input/validation/Input.jsx';
20 import Form from 'nfvo-components/input/validation/Form.jsx';
22 const VersionPropType = PropTypes.shape({
23 name: PropTypes.string,
24 description: PropTypes.string,
25 creationMethod: PropTypes.string
28 class VersionsPageCreationView extends React.Component {
31 data: VersionPropType,
32 availableMethods: PropTypes.array,
33 onDataChanged: PropTypes.func.isRequired,
34 onSubmit: PropTypes.func.isRequired,
35 onCancel: PropTypes.func.isRequired
39 let {data = {}, genericFieldInfo, baseVersion, onDataChanged, onCancel} = this.props;
40 let {additionalInfo: {OptionalCreationMethods}} = baseVersion;
41 let {description, creationMethod} = data;
44 <div className='version-creation-page'>
45 { genericFieldInfo && <Form
46 ref={(validationForm) => this.validationForm = validationForm}
48 onSubmit={() => this.submit()}
49 submitButtonText={i18n('Create')}
50 onReset={() => onCancel()}
52 isValid={this.props.isFormValid}
53 formReady={this.props.formReady}
54 onValidateForm={() => this.validate()}>
56 <div className='version-form-row'>
58 label={i18n('Version Category')}
59 value={creationMethod}
60 onChange={e => this.onSelectMethod(e)}
63 data-test-id='new-version-category'
64 isValid={genericFieldInfo.creationMethod.isValid}
65 errorText={genericFieldInfo.creationMethod.errorText}
67 <option key='' value=''>{i18n('Please select…')}</option>
68 {OptionalCreationMethods.map(method => <option key={method} value={method}>{i18n(method)}</option>)}
72 <div className='version-form-row'>
74 label={i18n('Description')}
78 data-test-id='new-version-description'
79 isValid={genericFieldInfo.description.isValid}
80 errorText={genericFieldInfo.description.errorText}
81 onChange={description => onDataChanged({description})}
91 const selectedIndex = e.target.selectedIndex;
92 const creationMethod = e.target.options[selectedIndex].value;
93 this.props.onDataChanged({creationMethod});
97 let {baseVersion, data: {description, creationMethod}} = this.props;
98 this.props.onSubmit({baseVersion, payload: {description, creationMethod}});
102 this.props.onValidateForm();
107 export default VersionsPageCreationView;
143 <div className='software-product-inline-section'>
148 onChange={name => onDataChanged({name},V_CREATION_FORM_NAME, {name: name => this.validateName(name)})}
149 isValid={genericFieldInfo.name.isValid}
150 errorText={genericFieldInfo.name.errorText}
152 className='field-section'
153 data-test-id='new-vsp-name' />
155 label={i18n('Vendor')}
159 disabled={disableVendor}
160 onChange={e => this.onSelectVendor(e)}
161 isValid={genericFieldInfo.vendorId.isValid}
162 errorText={genericFieldInfo.vendorId.errorText}
163 className='input-options-select'
164 groupClassName='bootstrap-input-options'
165 data-test-id='new-vsp-vendor' >
166 {vendorList.map(vendor =>
167 <option key={vendor.title} value={vendor.enum}>{vendor.title}</option>)}
170 label={i18n('Category')}
174 onChange={e => this.onSelectSubCategory(e)}
175 isValid={genericFieldInfo.subCategory.isValid}
176 errorText={genericFieldInfo.subCategory.errorText}
177 className='input-options-select'
178 groupClassName='bootstrap-input-options'
179 data-test-id='new-vsp-category' >
180 <option key='' value=''>{i18n('please select…')}</option>
181 {softwareProductCategories.map(category =>
182 category.subcategories &&
185 label={category.name}>{category.subcategories.map(sub =>
186 <option key={sub.uniqueId} value={sub.uniqueId}>{`${sub.name} (${category.name})`}</option>)}
191 <div className='software-product-inline-section'>
194 label={i18n('Description')}
197 onChange={description => onDataChanged({description},V_CREATION_FORM_NAME)}
198 isValid={genericFieldInfo.description.isValid}
199 errorText={genericFieldInfo.description.errorText}
201 className='field-section'
202 data-test-id='new-vsp-description' />
210 getAvailableMethodsList() {
211 let {availableMethods} = this.props;
212 return [...availableMethods];
216 const selectedIndex = e.target.selectedIndex;
217 const vendorId = e.target.options[selectedIndex].value;
218 this.props.onDataChanged({vendorId},V_CREATION_FORM_NAME);
221 onSelectSubCategory(e) {
222 const selectedIndex = e.target.selectedIndex;
223 const subCategory = e.target.options[selectedIndex].value;
224 let {softwareProductCategories, onDataChanged} = this.props;
225 let category = SoftwareProductCategoriesHelper.getCurrentCategoryOfSubCategory(subCategory, softwareProductCategories);
226 onDataChanged({category, subCategory},V_CREATION_FORM_NAME);
230 let {data:softwareProduct, finalizedLicenseModelList} = this.props;
231 softwareProduct.vendorName = finalizedLicenseModelList.find(vendor => vendor.id === softwareProduct.vendorId).name;
232 this.props.onSubmit(softwareProduct);
235 validateName(value) {
236 const {data: {id}, VSPNames} = this.props;
237 const isExists = Validator.isItemNameAlreadyExistsInList({itemId: id, itemName: value, list: VSPNames});
239 return !isExists ? {isValid: true, errorText: ''} :
240 {isValid: false, errorText: i18n('Software product by the name \'' + value + '\' already exists. Software product name must be unique')};
244 this.props.onValidateForm(SP_CREATION_FORM_NAME);
248 export default SoftwareProductCreationView;