blob: ba92d26067d982f6b38f9b4c47d9a3f1331c3d2a [file] [log] [blame]
talig8e9c0652017-12-20 14:30:43 +02001/*!
2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16import React from 'react';
17import PropTypes from 'prop-types';
18import i18n from 'nfvo-utils/i18n/i18n.js';
19import Input from 'nfvo-components/input/validation/Input.jsx';
20import Form from 'nfvo-components/input/validation/Form.jsx';
21
22const VersionPropType = PropTypes.shape({
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020023 name: PropTypes.string,
24 description: PropTypes.string,
25 creationMethod: PropTypes.string
talig8e9c0652017-12-20 14:30:43 +020026});
27
28class VersionsPageCreationView extends React.Component {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020029 static propTypes = {
30 data: VersionPropType,
31 availableMethods: PropTypes.array,
32 onDataChanged: PropTypes.func.isRequired,
33 onSubmit: PropTypes.func.isRequired,
34 onCancel: PropTypes.func.isRequired
35 };
talig8e9c0652017-12-20 14:30:43 +020036
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020037 render() {
38 let {
39 data = {},
40 genericFieldInfo,
41 baseVersion,
42 onDataChanged,
43 onCancel
44 } = this.props;
45 let { additionalInfo: { OptionalCreationMethods } } = baseVersion;
46 let { description, creationMethod } = data;
talig8e9c0652017-12-20 14:30:43 +020047
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020048 return (
49 <div className="version-creation-page">
50 {genericFieldInfo && (
51 <Form
52 ref={validationForm =>
53 (this.validationForm = validationForm)
54 }
55 hasButtons={true}
56 onSubmit={() => this.submit()}
57 submitButtonText={i18n('Create')}
58 onReset={() => onCancel()}
59 labledButtons={true}
60 isValid={this.props.isFormValid}
61 formReady={this.props.formReady}
62 onValidateForm={() => this.validate()}>
63 <div className="version-form-row">
64 <Input
65 label={i18n('Version Category')}
66 value={creationMethod}
67 onChange={e => this.onSelectMethod(e)}
68 type="select"
69 overlayPos="bottom"
70 data-test-id="new-version-category"
71 isValid={
72 genericFieldInfo.creationMethod.isValid
73 }
74 errorText={
75 genericFieldInfo.creationMethod.errorText
76 }
77 isRequired>
78 <option key="" value="">
79 {i18n('Please select…')}
80 </option>
81 {OptionalCreationMethods.map(method => (
82 <option key={method} value={method}>
83 {i18n(method)}
84 </option>
85 ))}
86 </Input>
87 </div>
talig8e9c0652017-12-20 14:30:43 +020088
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020089 <div className="version-form-row">
90 <Input
91 label={i18n('Description')}
92 value={description}
93 type="text"
94 overlayPos="bottom"
95 data-test-id="new-version-description"
96 isValid={genericFieldInfo.description.isValid}
97 errorText={
98 genericFieldInfo.description.errorText
99 }
100 onChange={description =>
101 onDataChanged({ description })
102 }
103 isRequired
104 />
105 </div>
106 </Form>
107 )}
108 </div>
109 );
110 }
talig8e9c0652017-12-20 14:30:43 +0200111
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200112 onSelectMethod(e) {
113 const selectedIndex = e.target.selectedIndex;
114 const creationMethod = e.target.options[selectedIndex].value;
115 this.props.onDataChanged({ creationMethod });
116 }
talig8e9c0652017-12-20 14:30:43 +0200117
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200118 submit() {
119 let { baseVersion, data: { description, creationMethod } } = this.props;
120 this.props.onSubmit({
121 baseVersion,
122 payload: { description, creationMethod }
123 });
124 }
talig8e9c0652017-12-20 14:30:43 +0200125
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200126 validate() {
127 this.props.onValidateForm();
128 }
talig8e9c0652017-12-20 14:30:43 +0200129}
130
131export default VersionsPageCreationView;
132
talig8e9c0652017-12-20 14:30:43 +0200133/*
134 <div className='software-product-inline-section'>
135 <Input
136 value={name}
137 label={i18n('Name')}
138 isRequired={true}
139 onChange={name => onDataChanged({name},V_CREATION_FORM_NAME, {name: name => this.validateName(name)})}
140 isValid={genericFieldInfo.name.isValid}
141 errorText={genericFieldInfo.name.errorText}
142 type='text'
143 className='field-section'
144 data-test-id='new-vsp-name' />
145 <Input
146 label={i18n('Vendor')}
147 type='select'
148 value={vendorId}
149 isRequired={true}
150 disabled={disableVendor}
151 onChange={e => this.onSelectVendor(e)}
152 isValid={genericFieldInfo.vendorId.isValid}
153 errorText={genericFieldInfo.vendorId.errorText}
154 className='input-options-select'
155 groupClassName='bootstrap-input-options'
156 data-test-id='new-vsp-vendor' >
157 {vendorList.map(vendor =>
158 <option key={vendor.title} value={vendor.enum}>{vendor.title}</option>)}
159 </Input>
160 <Input
161 label={i18n('Category')}
162 type='select'
163 value={subCategory}
164 isRequired={true}
165 onChange={e => this.onSelectSubCategory(e)}
166 isValid={genericFieldInfo.subCategory.isValid}
167 errorText={genericFieldInfo.subCategory.errorText}
168 className='input-options-select'
169 groupClassName='bootstrap-input-options'
170 data-test-id='new-vsp-category' >
171 <option key='' value=''>{i18n('please select…')}</option>
172 {softwareProductCategories.map(category =>
173 category.subcategories &&
174 <optgroup
175 key={category.name}
176 label={category.name}>{category.subcategories.map(sub =>
177 <option key={sub.uniqueId} value={sub.uniqueId}>{`${sub.name} (${category.name})`}</option>)}
178 </optgroup>)
179 }
180 </Input>
181 </div>
182 <div className='software-product-inline-section'>
183 <Input
184 value={description}
185 label={i18n('Description')}
186 isRequired={true}
187 overlayPos='bottom'
188 onChange={description => onDataChanged({description},V_CREATION_FORM_NAME)}
189 isValid={genericFieldInfo.description.isValid}
190 errorText={genericFieldInfo.description.errorText}
191 type='textarea'
192 className='field-section'
193 data-test-id='new-vsp-description' />
194 </div>
195 </div>
196 </Form>}
197 </div>
198 );
199 }
200
201 getAvailableMethodsList() {
202 let {availableMethods} = this.props;
203 return [...availableMethods];
204 }
205
206 onSelectVendor(e) {
207 const selectedIndex = e.target.selectedIndex;
208 const vendorId = e.target.options[selectedIndex].value;
209 this.props.onDataChanged({vendorId},V_CREATION_FORM_NAME);
210 }
211
212 onSelectSubCategory(e) {
213 const selectedIndex = e.target.selectedIndex;
214 const subCategory = e.target.options[selectedIndex].value;
215 let {softwareProductCategories, onDataChanged} = this.props;
216 let category = SoftwareProductCategoriesHelper.getCurrentCategoryOfSubCategory(subCategory, softwareProductCategories);
217 onDataChanged({category, subCategory},V_CREATION_FORM_NAME);
218 }
219
220 submit() {
221 let {data:softwareProduct, finalizedLicenseModelList} = this.props;
222 softwareProduct.vendorName = finalizedLicenseModelList.find(vendor => vendor.id === softwareProduct.vendorId).name;
223 this.props.onSubmit(softwareProduct);
224 }
225
226 validateName(value) {
227 const {data: {id}, VSPNames} = this.props;
228 const isExists = Validator.isItemNameAlreadyExistsInList({itemId: id, itemName: value, list: VSPNames});
229
230 return !isExists ? {isValid: true, errorText: ''} :
231 {isValid: false, errorText: i18n('Software product by the name \'' + value + '\' already exists. Software product name must be unique')};
232 }
233
234 validate() {
235 this.props.onValidateForm(SP_CREATION_FORM_NAME);
236 }
237}
238
239export default SoftwareProductCreationView;
240*/