1 import React from 'react';
2 import i18n from 'nfvo-utils/i18n/i18n.js';
3 import Input from 'nfvo-components/input/validation/Input.jsx';
4 import Form from 'nfvo-components/input/validation/Form.jsx';
5 import GridSection from 'nfvo-components/grid/GridSection.jsx';
6 import GridItem from 'nfvo-components/grid/GridItem.jsx';
7 import SelectInput from 'nfvo-components/input/SelectInput.jsx';
8 import SelectActionTable from 'nfvo-components/table/SelectActionTable.jsx';
9 import SelectActionTableRow from 'nfvo-components/table/SelectActionTableRow.jsx';
10 import SelectActionTableCell from 'nfvo-components/table/SelectActionTableCell.jsx';
11 import Validator from 'nfvo-utils/Validator.js';
13 export default class SoftwareProductDeploymentEditorView extends React.Component {
15 let {data, isEdit, onClose, onDataChanged, isReadOnlyMode, selectedFeatureGroupsList, componentsList, computesList, genericFieldInfo} = this.props;
16 let {model, description, featureGroupId, componentComputeAssociations = []} = data;
17 let featureGroupsExist = selectedFeatureGroupsList.length > 0;
20 {genericFieldInfo && <Form
24 isReadOnlyMode={isReadOnlyMode}
25 onSubmit={ () => this.submit() }
26 submitButtonText={isEdit ? i18n('Save') : i18n('Create')}
27 onReset={ () => onClose() }
28 onValidateForm={() => this.validate() }
29 isValid={this.props.isFormValid}
30 formReady={this.props.formReady}
31 className='vsp-deployment-editor'>
32 <GridSection hasLastColSet>
33 <GridItem colSpan={1}>
35 onChange={model => onDataChanged({model}, {model: model => this.validateName(model)})}
38 data-test-id='deployment-model'
39 isValid={genericFieldInfo.model.isValid}
40 errorText={genericFieldInfo.model.errorText}
44 <GridItem colSpan={3} lastColInRow>
46 onChange={description => onDataChanged({description})}
47 label={i18n('Description')}
49 data-test-id='deployment-description'
50 isValid={genericFieldInfo.description.isValid}
51 errorText={genericFieldInfo.description.errorText}
55 <GridSection className={`deployment-feature-groups-section${!featureGroupsExist ? ' no-feature-groups' : ''}`} title={i18n('License Details')} hasLastColSet>
56 <GridItem colSpan={1}>
58 data-test-id='deployment-feature-groups'
59 label={i18n('Feature Group')}
60 value={featureGroupId}
61 onChange={featureGroup => onDataChanged({featureGroupId: featureGroup ? featureGroup.value : null})}
64 disabled={isReadOnlyMode || !featureGroupsExist}
65 className='field-section'
66 options={selectedFeatureGroupsList}/>
69 {!featureGroupsExist && <GridSection className='deployment-feature-group-warning-section'>
70 <GridItem colSpan={3}>
71 <span>{i18n('Please assign Feature Groups in VSP General')}</span>
74 <GridSection title={i18n('Assign VFCs and Compute Flavors')} className='vfc-table' hasLastColSet>
75 <GridItem colSpan={4} lastColInRow>
77 columns={['Virtual Function Components', 'Compute Flavors']}
79 {componentComputeAssociations.map( (association, index) =>
80 <SelectActionTableRow key={association.componentId}>
81 <SelectActionTableCell
84 .map(component => ({value: component.id, label: component.displayName}) )
86 selected={association.componentId}
87 onChange={componentId => {
88 let newAssociations = [...componentComputeAssociations];
89 newAssociations[index] = {...newAssociations[index], componentId};
90 onDataChanged({componentComputeAssociations: newAssociations});
93 <SelectActionTableCell
96 .filter(compute => compute.componentId === association.componentId)
97 .map(compute => ({value: compute.computeFlavorId, label: compute.name}) )
99 selected={association.computeFlavorId}
100 onChange={computeFlavorId => {
101 let newAssociations = [...componentComputeAssociations];
102 newAssociations[index] = {...newAssociations[index], computeFlavorId};
103 onDataChanged({componentComputeAssociations: newAssociations});
105 disabled={isReadOnlyMode}/>
106 </SelectActionTableRow>
116 validateName(value) {
117 const {data: {id = ''}, DFNames} = this.props;
118 const isExists = Validator.isItemNameAlreadyExistsInList({itemId: id, itemName: value, list: DFNames});
120 return !isExists ? {isValid: true, errorText: ''} :
121 {isValid: false, errorText: i18n('Deployment flavor by the name \'' + value + '\' already exists. Deployment flavor name must be unique')};
125 let {isEdit, onCreate, onEdit, onClose, data} = this.props;
135 this.props.onValidateForm();