svishnev | 8ae8f7e | 2018-07-02 14:05:17 +0300 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright © 2016-2018 European Support Limited |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 3 | * |
| 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 |
svishnev | 8ae8f7e | 2018-07-02 14:05:17 +0300 | [diff] [blame^] | 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
svishnev | 8ae8f7e | 2018-07-02 14:05:17 +0300 | [diff] [blame^] | 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. |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 15 | */ |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 16 | import React from 'react'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 17 | import PropTypes from 'prop-types'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 18 | import i18n from 'nfvo-utils/i18n/i18n.js'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 19 | import Input from 'nfvo-components/input/validation/Input.jsx'; |
| 20 | import Form from 'nfvo-components/input/validation/Form.jsx'; |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 21 | import { LICENSE_MODEL_CREATION_FORM_NAME } from './LicenseModelCreationConstants.js'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 22 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 23 | const LicenseModelPropType = PropTypes.shape({ |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 24 | id: PropTypes.string, |
| 25 | vendorName: PropTypes.string, |
| 26 | description: PropTypes.string |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 27 | }); |
| 28 | |
| 29 | class LicenseModelCreationView extends React.Component { |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 30 | static propTypes = { |
| 31 | data: LicenseModelPropType, |
| 32 | VLMNames: PropTypes.object, |
| 33 | usersList: PropTypes.array, |
| 34 | onDataChanged: PropTypes.func.isRequired, |
| 35 | onSubmit: PropTypes.func.isRequired, |
| 36 | onValidateForm: PropTypes.func.isRequired, |
| 37 | onCancel: PropTypes.func.isRequired |
| 38 | }; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 39 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 40 | render() { |
| 41 | let { data = {}, onDataChanged, genericFieldInfo } = this.props; |
| 42 | let { vendorName, description } = data; |
| 43 | return ( |
| 44 | <div> |
| 45 | {genericFieldInfo && ( |
| 46 | <Form |
| 47 | ref="validationForm" |
| 48 | hasButtons={true} |
| 49 | onSubmit={() => this.submit()} |
| 50 | submitButtonText={i18n('Create')} |
| 51 | onReset={() => this.props.onCancel()} |
| 52 | labledButtons={true} |
| 53 | isValid={this.props.isFormValid} |
| 54 | formReady={this.props.formReady} |
| 55 | onValidateForm={() => this.validate()}> |
| 56 | <Input |
| 57 | value={vendorName} |
| 58 | label={i18n('Vendor Name')} |
| 59 | data-test-id="vendor-name" |
| 60 | onChange={vendorName => |
| 61 | onDataChanged( |
| 62 | { vendorName }, |
svishnev | 8ae8f7e | 2018-07-02 14:05:17 +0300 | [diff] [blame^] | 63 | LICENSE_MODEL_CREATION_FORM_NAME |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 64 | ) |
| 65 | } |
svishnev | 8ae8f7e | 2018-07-02 14:05:17 +0300 | [diff] [blame^] | 66 | onBlur={e => |
| 67 | this.validateIsNameUnique(e.target.value) |
| 68 | } |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 69 | isValid={genericFieldInfo.vendorName.isValid} |
| 70 | errorText={genericFieldInfo.vendorName.errorText} |
| 71 | type="text" |
| 72 | isRequired={true} |
| 73 | className="field-section" |
| 74 | /> |
| 75 | <Input |
| 76 | isRequired={true} |
| 77 | value={description} |
| 78 | label={i18n('Description')} |
| 79 | data-test-id="vendor-description" |
| 80 | overlayPos="bottom" |
| 81 | onChange={description => |
| 82 | onDataChanged( |
| 83 | { description }, |
| 84 | LICENSE_MODEL_CREATION_FORM_NAME |
| 85 | ) |
| 86 | } |
| 87 | isValid={genericFieldInfo.description.isValid} |
| 88 | errorText={genericFieldInfo.description.errorText} |
| 89 | type="textarea" |
| 90 | className="field-section" |
| 91 | /> |
| 92 | </Form> |
| 93 | )} |
| 94 | </div> |
| 95 | ); |
| 96 | } |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 97 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 98 | submit() { |
| 99 | const { data: licenseModel, usersList } = this.props; |
| 100 | this.props.onSubmit(licenseModel, usersList); |
| 101 | } |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 102 | |
svishnev | 8ae8f7e | 2018-07-02 14:05:17 +0300 | [diff] [blame^] | 103 | validateIsNameUnique(value) { |
| 104 | this.props.isNameUnique( |
| 105 | value, |
| 106 | 'vendorName', |
| 107 | LICENSE_MODEL_CREATION_FORM_NAME |
| 108 | ); |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 109 | } |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 110 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 111 | validate() { |
| 112 | this.props.onValidateForm(LICENSE_MODEL_CREATION_FORM_NAME); |
| 113 | } |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | export default LicenseModelCreationView; |