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 i18n from 'nfvo-utils/i18n/i18n.js';
18 import Validator from 'nfvo-utils/Validator.js';
19 import Input from 'nfvo-components/input/validation/Input.jsx';
20 import Form from 'nfvo-components/input/validation/Form.jsx';
21 import {LICENSE_MODEL_CREATION_FORM_NAME} from './LicenseModelCreationConstants.js';
23 const LicenseModelPropType = React.PropTypes.shape({
24 id: React.PropTypes.string,
25 vendorName: React.PropTypes.string,
26 description: React.PropTypes.string
29 class LicenseModelCreationView extends React.Component {
32 data: LicenseModelPropType,
33 VLMNames: React.PropTypes.object,
34 onDataChanged: React.PropTypes.func.isRequired,
35 onSubmit: React.PropTypes.func.isRequired,
36 onValidateForm: React.PropTypes.func.isRequired,
37 onCancel: React.PropTypes.func.isRequired
41 let {data = {}, onDataChanged, genericFieldInfo} = this.props;
42 let {vendorName, description} = data;
45 {genericFieldInfo && <Form
48 onSubmit={ () => this.submit() }
49 onReset={ () => this.props.onCancel() }
51 isValid={this.props.isFormValid}
52 formReady={this.props.formReady}
53 onValidateForm={() => this.validate() }>
56 label={i18n('Vendor Name')}
57 data-test-id='vendor-name'
58 onChange={vendorName => onDataChanged({vendorName}, LICENSE_MODEL_CREATION_FORM_NAME, {vendorName: name => this.validateName(name)})}
59 isValid={genericFieldInfo.vendorName.isValid}
60 errorText={genericFieldInfo.vendorName.errorText}
63 className='field-section'/>
67 label={i18n('Description')}
68 data-test-id='vendor-description'
70 onChange={description => onDataChanged({description}, LICENSE_MODEL_CREATION_FORM_NAME)}
71 isValid={genericFieldInfo.description.isValid}
72 errorText={genericFieldInfo.description.errorText}
74 className='field-section'/>
82 const {data:licenseModel} = this.props;
83 this.props.onSubmit(licenseModel);
87 const {data: {id}, VLMNames} = this.props;
88 const isExists = Validator.isItemNameAlreadyExistsInList({itemId: id, itemName: value, list: VLMNames});
90 return !isExists ? {isValid: true, errorText: ''} :
91 {isValid: false, errorText: i18n('License model by the name \'' + value + '\' already exists. License model name must be unique')};
95 this.props.onValidateForm(LICENSE_MODEL_CREATION_FORM_NAME);
99 export default LicenseModelCreationView;