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 GridSection from 'nfvo-components/grid/GridSection.jsx';
22 import GridItem from 'nfvo-components/grid/GridItem.jsx';
24 import {SP_CREATION_FORM_NAME} from './SoftwareProductCreationConstants.js';
25 import sortByStringProperty from 'nfvo-utils/sortByStringProperty.js';
27 import SoftwareProductCategoriesHelper from 'sdc-app/onboarding/softwareProduct/SoftwareProductCategoriesHelper.js';
28 import {onboardingMethod as onboardingMethodConst} from '../SoftwareProductConstants.js';
30 const SoftwareProductPropType = React.PropTypes.shape({
31 id: React.PropTypes.string,
32 name: React.PropTypes.string,
33 description: React.PropTypes.string,
34 category: React.PropTypes.string,
35 subCategory: React.PropTypes.string,
36 vendorId: React.PropTypes.string
39 class SoftwareProductCreationView extends React.Component {
42 data: SoftwareProductPropType,
43 finalizedLicenseModelList: React.PropTypes.array,
44 softwareProductCategories: React.PropTypes.array,
45 VSPNames: React.PropTypes.object,
46 onDataChanged: React.PropTypes.func.isRequired,
47 onSubmit: React.PropTypes.func.isRequired,
48 onCancel: React.PropTypes.func.isRequired
52 let {softwareProductCategories, data = {}, onDataChanged, onCancel, genericFieldInfo, disableVendor} = this.props;
53 let {name, description, vendorId, subCategory, onboardingMethod} = data;
55 const vendorList = this.getVendorList();
57 <div className='software-product-creation-page'>
58 { genericFieldInfo && <Form
59 ref={(validationForm) => this.validationForm = validationForm}
61 onSubmit={() => this.submit() }
62 onReset={() => onCancel() }
64 isValid={this.props.isFormValid}
65 submitButtonText={i18n('Create')}
66 formReady={this.props.formReady}
67 onValidateForm={() => this.validate() }>
69 <GridItem colSpan='2'>
74 onChange={name => onDataChanged({name},SP_CREATION_FORM_NAME, {name: name => this.validateName(name)})}
75 isValid={genericFieldInfo.name.isValid}
76 errorText={genericFieldInfo.name.errorText}
78 className='field-section'
79 data-test-id='new-vsp-name' />
81 label={i18n('Vendor')}
86 disabled={disableVendor}
87 onChange={e => this.onSelectVendor(e)}
88 isValid={genericFieldInfo.vendorId.isValid}
89 errorText={genericFieldInfo.vendorId.errorText}
90 className='input-options-select'
91 groupClassName='bootstrap-input-options'
92 data-test-id='new-vsp-vendor' >
93 {vendorList.map(vendor =>
94 <option key={vendor.title} value={vendor.enum}>{vendor.title}</option>)}
97 label={i18n('Category')}
101 onChange={e => this.onSelectSubCategory(e)}
102 isValid={genericFieldInfo.subCategory.isValid}
103 errorText={genericFieldInfo.subCategory.errorText}
104 className='input-options-select'
105 groupClassName='bootstrap-input-options'
106 data-test-id='new-vsp-category' >
107 <option key='' value=''>{i18n('please select…')}</option>
108 {softwareProductCategories.map(category =>
109 category.subcategories &&
112 label={category.name}>{category.subcategories.map(sub =>
113 <option key={sub.uniqueId} value={sub.uniqueId}>{`${sub.name} (${category.name})`}</option>)}
118 <GridItem colSpan='2' stretch>
121 label={i18n('Description')}
124 onChange={description => onDataChanged({description},SP_CREATION_FORM_NAME)}
125 isValid={genericFieldInfo.description.isValid}
126 errorText={genericFieldInfo.description.errorText}
128 className='field-section'
129 data-test-id='new-vsp-description'/>
132 <OnboardingProcedure genericFieldInfo={genericFieldInfo} onboardingMethod={onboardingMethod} onDataChanged={onDataChanged} />
139 let {finalizedLicenseModelList} = this.props;
141 return [{enum: '', title: i18n('please select...')}].concat(
142 sortByStringProperty(finalizedLicenseModelList, 'vendorName').map(vendor => {
145 title: vendor.vendorName
152 const selectedIndex = e.target.selectedIndex;
153 const vendorId = e.target.options[selectedIndex].value;
154 this.props.onDataChanged({vendorId},SP_CREATION_FORM_NAME);
157 onSelectSubCategory(e) {
158 const selectedIndex = e.target.selectedIndex;
159 const subCategory = e.target.options[selectedIndex].value;
160 let {softwareProductCategories, onDataChanged} = this.props;
161 let category = SoftwareProductCategoriesHelper.getCurrentCategoryOfSubCategory(subCategory, softwareProductCategories);
162 onDataChanged({category, subCategory},SP_CREATION_FORM_NAME);
166 let {data:softwareProduct, finalizedLicenseModelList} = this.props;
167 softwareProduct.vendorName = finalizedLicenseModelList.find(vendor => vendor.id === softwareProduct.vendorId).vendorName;
168 this.props.onSubmit(softwareProduct);
171 validateName(value) {
172 const {data: {id}, VSPNames} = this.props;
173 const isExists = Validator.isItemNameAlreadyExistsInList({itemId: id, itemName: value, list: VSPNames});
175 return !isExists ? {isValid: true, errorText: ''} :
176 {isValid: false, errorText: i18n('Software product by the name \'' + value + '\' already exists. Software product name must be unique')};
180 this.props.onValidateForm(SP_CREATION_FORM_NAME);
184 const OnboardingProcedure = ({onboardingMethod, onDataChanged, genericFieldInfo}) => {
186 <GridSection title={i18n('Onboarding procedure')}>
187 <GridItem colSpan={4}>
189 label={i18n('Network Package')}
191 isValid={genericFieldInfo.onboardingMethod.isValid}
192 checked={onboardingMethod === onboardingMethodConst.NETWORK_PACKAGE}
193 errorText={genericFieldInfo.onboardingMethod.errorText}
194 onChange={() => onDataChanged({onboardingMethod: onboardingMethodConst.NETWORK_PACKAGE},SP_CREATION_FORM_NAME)}
196 data-test-id='new-vsp-creation-procedure-heat' />
198 <GridItem colSpan={4}>
200 label={i18n('Manual')}
202 checked={onboardingMethod === onboardingMethodConst.MANUAL}
203 isValid={genericFieldInfo.onboardingMethod.isValid}
204 errorText={genericFieldInfo.onboardingMethod.errorText}
205 onChange={() => onDataChanged({onboardingMethod: onboardingMethodConst.MANUAL},SP_CREATION_FORM_NAME)}
207 data-test-id='new-vsp-creation-procedure-manual' />
213 export default SoftwareProductCreationView;