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 btnClassName="sdc-modal__footer"
85 onValidateForm={() => this.validate()}>
86 <GridSection hasLastColSet>
87 <GridItem colSpan="2">
98 onBlur={this.validateIsNameUnique}
99 isValid={genericFieldInfo.name.isValid}
100 errorText={genericFieldInfo.name.errorText}
102 className="field-section"
103 data-test-id="new-vsp-name"
106 label={i18n('Vendor')}
111 disabled={disableVendor}
112 onChange={e => this.onSelectVendor(e)}
113 isValid={genericFieldInfo.vendorId.isValid}
115 genericFieldInfo.vendorId.errorText
117 className="input-options-select"
118 groupClassName="bootstrap-input-options"
119 data-test-id="new-vsp-vendor">
120 {vendorList.map(vendor => (
129 label={i18n('Category')}
133 onChange={e => this.onSelectSubCategory(e)}
135 genericFieldInfo.subCategory.isValid
138 genericFieldInfo.subCategory.errorText
140 className="input-options-select"
141 groupClassName="bootstrap-input-options"
142 data-test-id="new-vsp-category">
143 <option key="" value="">
144 {i18n('please select…')}
146 {softwareProductCategories.map(
148 category.subcategories && (
151 label={category.name}>
152 {category.subcategories.map(
172 <GridItem colSpan="2" stretch lastColInRow>
175 label={i18n('Description')}
178 onChange={description =>
181 SP_CREATION_FORM_NAME
185 genericFieldInfo.description.isValid
188 genericFieldInfo.description.errorText
191 className="field-section"
192 data-test-id="new-vsp-description"
197 genericFieldInfo={genericFieldInfo}
198 onboardingMethod={onboardingMethod}
199 onDataChanged={onDataChanged}
208 let { vendorList } = this.props;
210 return [{ enum: '', title: i18n('please select...') }].concat(
211 sortByStringProperty(vendorList, 'name').map(vendor => {
221 const selectedIndex = e.target.selectedIndex;
222 const vendorId = e.target.options[selectedIndex].value;
223 this.props.onDataChanged({ vendorId }, SP_CREATION_FORM_NAME);
226 onSelectSubCategory(e) {
227 const selectedIndex = e.target.selectedIndex;
228 const subCategory = e.target.options[selectedIndex].value;
229 let { softwareProductCategories, onDataChanged } = this.props;
230 let category = SoftwareProductCategoriesHelper.getCurrentCategoryOfSubCategory(
232 softwareProductCategories
234 onDataChanged({ category, subCategory }, SP_CREATION_FORM_NAME);
239 data: softwareProduct,
240 finalizedLicenseModelList,
243 softwareProduct.vendorName = finalizedLicenseModelList.find(
244 vendor => vendor.id === softwareProduct.vendorId
246 this.props.onSubmit(softwareProduct, usersList);
249 validateName(value) {
250 const { data: { id }, VSPNames } = this.props;
251 const isExists = Validator.isItemNameAlreadyExistsInList({
258 ? { isValid: true, errorText: '' }
262 "Software product by the name '" +
264 "' already exists. Software product name must be unique"
269 validateIsNameUnique = e => {
270 const value = e.target.value;
272 this.props.isNameUnique(value, 'name', SP_CREATION_FORM_NAME);
277 this.props.onValidateForm(SP_CREATION_FORM_NAME);
281 const OnboardingProcedure = ({
287 <GridSection title={i18n('Onboarding procedure')}>
288 <GridItem colSpan={4}>
290 label={i18n('Network Package')}
294 onboardingMethodConst.NETWORK_PACKAGE
296 errorText={genericFieldInfo.onboardingMethod.errorText}
301 onboardingMethodConst.NETWORK_PACKAGE
303 SP_CREATION_FORM_NAME
307 data-test-id="new-vsp-creation-procedure-heat"
310 <GridItem colSpan={4}>
312 label={i18n('Manual')}
314 checked={onboardingMethod === onboardingMethodConst.MANUAL}
315 isValid={genericFieldInfo.onboardingMethod.isValid}
316 errorText={genericFieldInfo.onboardingMethod.errorText}
319 { onboardingMethod: onboardingMethodConst.MANUAL },
320 SP_CREATION_FORM_NAME
324 data-test-id="new-vsp-creation-procedure-manual"
325 groupClassName="no-bottom-margin"
332 export default SoftwareProductCreationView;