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
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 Validator from 'nfvo-utils/Validator.js';
20 import Input from 'nfvo-components/input/validation/Input.jsx';
21 import Form from 'nfvo-components/input/validation/Form.jsx';
22 import GridSection from 'nfvo-components/grid/GridSection.jsx';
23 import GridItem from 'nfvo-components/grid/GridItem.jsx';
25 import { SP_CREATION_FORM_NAME } from './SoftwareProductCreationConstants.js';
26 import sortByStringProperty from 'nfvo-utils/sortByStringProperty.js';
28 import SoftwareProductCategoriesHelper from 'sdc-app/onboarding/softwareProduct/SoftwareProductCategoriesHelper.js';
29 import { onboardingMethod as onboardingMethodConst } from '../SoftwareProductConstants.js';
31 const SoftwareProductPropType = PropTypes.shape({
33 name: PropTypes.string,
34 description: PropTypes.string,
35 category: PropTypes.string,
36 subCategory: PropTypes.string,
37 vendorId: PropTypes.string
40 class SoftwareProductCreationView extends React.Component {
42 data: SoftwareProductPropType,
43 finalizedLicenseModelList: PropTypes.array,
44 softwareProductCategories: PropTypes.array,
45 VSPNames: PropTypes.object,
46 usersList: PropTypes.array,
47 onDataChanged: PropTypes.func.isRequired,
48 onSubmit: PropTypes.func.isRequired,
49 onCancel: PropTypes.func.isRequired
54 softwareProductCategories,
69 const vendorList = this.getVendorList();
71 <div className="software-product-creation-page">
72 {genericFieldInfo && (
74 ref={validationForm =>
75 (this.validationForm = validationForm)
78 onSubmit={() => this.submit()}
79 onReset={() => onCancel()}
81 isValid={this.props.isFormValid}
82 submitButtonText={i18n('Create')}
83 formReady={this.props.formReady}
84 onValidateForm={() => this.validate()}>
85 <GridSection hasLastColSet>
86 <GridItem colSpan="2">
97 onBlur={this.validateIsNameUnique}
98 isValid={genericFieldInfo.name.isValid}
99 errorText={genericFieldInfo.name.errorText}
101 className="field-section"
102 data-test-id="new-vsp-name"
105 label={i18n('Vendor')}
110 disabled={disableVendor}
111 onChange={e => this.onSelectVendor(e)}
112 isValid={genericFieldInfo.vendorId.isValid}
114 genericFieldInfo.vendorId.errorText
116 className="input-options-select"
117 groupClassName="bootstrap-input-options"
118 data-test-id="new-vsp-vendor">
119 {vendorList.map(vendor => (
128 label={i18n('Category')}
132 onChange={e => this.onSelectSubCategory(e)}
134 genericFieldInfo.subCategory.isValid
137 genericFieldInfo.subCategory.errorText
139 className="input-options-select"
140 groupClassName="bootstrap-input-options"
141 data-test-id="new-vsp-category">
142 <option key="" value="">
143 {i18n('please select…')}
145 {softwareProductCategories.map(
147 category.subcategories && (
150 label={category.name}>
151 {category.subcategories.map(
171 <GridItem colSpan="2" stretch lastColInRow>
174 label={i18n('Description')}
177 onChange={description =>
180 SP_CREATION_FORM_NAME
184 genericFieldInfo.description.isValid
187 genericFieldInfo.description.errorText
190 className="field-section"
191 data-test-id="new-vsp-description"
196 genericFieldInfo={genericFieldInfo}
197 onboardingMethod={onboardingMethod}
198 onDataChanged={onDataChanged}
207 let { vendorList } = this.props;
209 return [{ enum: '', title: i18n('please select...') }].concat(
210 sortByStringProperty(vendorList, 'name').map(vendor => {
220 const selectedIndex = e.target.selectedIndex;
221 const vendorId = e.target.options[selectedIndex].value;
222 this.props.onDataChanged({ vendorId }, SP_CREATION_FORM_NAME);
225 onSelectSubCategory(e) {
226 const selectedIndex = e.target.selectedIndex;
227 const subCategory = e.target.options[selectedIndex].value;
228 let { softwareProductCategories, onDataChanged } = this.props;
229 let category = SoftwareProductCategoriesHelper.getCurrentCategoryOfSubCategory(
231 softwareProductCategories
233 onDataChanged({ category, subCategory }, SP_CREATION_FORM_NAME);
238 data: softwareProduct,
239 finalizedLicenseModelList,
242 softwareProduct.vendorName = finalizedLicenseModelList.find(
243 vendor => vendor.id === softwareProduct.vendorId
245 this.props.onSubmit(softwareProduct, usersList);
248 validateName(value) {
249 const { data: { id }, VSPNames } = this.props;
250 const isExists = Validator.isItemNameAlreadyExistsInList({
257 ? { isValid: true, errorText: '' }
261 "Software product by the name '" +
263 "' already exists. Software product name must be unique"
268 validateIsNameUnique = e => {
269 const value = e.target.value;
271 this.props.isNameUnique(value, 'name', SP_CREATION_FORM_NAME);
276 this.props.onValidateForm(SP_CREATION_FORM_NAME);
280 const OnboardingProcedure = ({
286 <GridSection title={i18n('Onboarding procedure')}>
287 <GridItem colSpan={4}>
289 label={i18n('Network Package')}
293 onboardingMethodConst.NETWORK_PACKAGE
295 errorText={genericFieldInfo.onboardingMethod.errorText}
300 onboardingMethodConst.NETWORK_PACKAGE
302 SP_CREATION_FORM_NAME
306 data-test-id="new-vsp-creation-procedure-heat"
309 <GridItem colSpan={4}>
311 label={i18n('Manual')}
313 checked={onboardingMethod === onboardingMethodConst.MANUAL}
314 isValid={genericFieldInfo.onboardingMethod.isValid}
315 errorText={genericFieldInfo.onboardingMethod.errorText}
318 { onboardingMethod: onboardingMethodConst.MANUAL },
319 SP_CREATION_FORM_NAME
323 data-test-id="new-vsp-creation-procedure-manual"
330 export default SoftwareProductCreationView;