1 import React from 'react';
4 import i18n from 'nfvo-utils/i18n/i18n.js';
6 import ValidationForm from 'nfvo-components/input/validation/ValidationForm.jsx';
7 import ValidationInput from 'nfvo-components/input/validation/ValidationInput.jsx';
8 import {optionsInputValues as EntitlementPoolsOptionsInputValues, thresholdUnitType} from './EntitlementPoolsConstants.js';
9 import {other as optionInputOther} from 'nfvo-components/input/inputOptions/InputOptions.jsx';
12 const EntitlementPoolPropType = React.PropTypes.shape({
13 id: React.PropTypes.string,
14 name: React.PropTypes.string,
15 description: React.PropTypes.string,
16 manufacturerReferenceNumber: React.PropTypes.string,
17 operationalScope: React.PropTypes.shape({
18 choices: React.PropTypes.array,
19 other: React.PropTypes.string
21 aggregationFunction: React.PropTypes.shape({
22 choice: React.PropTypes.string,
23 other: React.PropTypes.string
25 increments: React.PropTypes.string,
26 time: React.PropTypes.shape({
27 choice: React.PropTypes.string,
28 other: React.PropTypes.string
30 entitlementMetric: React.PropTypes.shape({
31 choice: React.PropTypes.string,
32 other: React.PropTypes.string
36 class EntitlementPoolsEditorView extends React.Component {
39 data: EntitlementPoolPropType,
40 previousData: EntitlementPoolPropType,
41 isReadOnlyMode: React.PropTypes.bool,
42 onDataChanged: React.PropTypes.func.isRequired,
43 onSubmit: React.PropTypes.func.isRequired,
44 onCancel: React.PropTypes.func.isRequired
47 static defaultProps = {
52 let {data = {}, onDataChanged, isReadOnlyMode} = this.props;
54 name, description, manufacturerReferenceNumber, operationalScope, aggregationFunction, thresholdUnits, thresholdValue,
55 increments, time, entitlementMetric} = data;
56 let thresholdValueValidation = thresholdUnits === thresholdUnitType.PERCENTAGE ? {numeric: true, required: true, maxValue: 100} : {numeric: true, required: true};
57 let timeValidation = time && time.choice === optionInputOther.OTHER ? {numeric: true, required: true} : {required: true};
63 onSubmit={ () => this.submit() }
64 onReset={ () => this.props.onCancel() }
66 isReadOnlyMode={isReadOnlyMode}
67 className='entitlement-pools-form'>
68 <div className='entitlement-pools-form-row'>
70 onChange={name => onDataChanged({name})}
73 validations={{maxLength: 120, required: true}}
78 onEnumChange={operationalScope => onDataChanged({operationalScope:{choices: operationalScope, other: ''}})}
79 onOtherChange={operationalScope => onDataChanged({operationalScope:{choices: [optionInputOther.OTHER], other: operationalScope}})}
80 multiSelectedEnum={operationalScope && operationalScope.choices}
81 label={i18n('Operational Scope')}
82 otherValue={operationalScope && operationalScope.other}
83 validations={{required: true}}
84 values={EntitlementPoolsOptionsInputValues.OPERATIONAL_SCOPE}/>
87 <div className='entitlement-pools-form-row'>
89 onChange={description => onDataChanged({description})}
90 label={i18n('Description')}
92 validations={{maxLength: 1000, required: true}}
94 <div className='entitlement-pools-form-row-group'>
95 <div className='entitlement-pools-form-row'>
97 onEnumChange={thresholdUnits => onDataChanged({thresholdUnits})}
98 selectedEnum={thresholdUnits}
99 label={i18n('Threshold Value')}
101 values={EntitlementPoolsOptionsInputValues.THRESHOLD_UNITS}
102 validations={{required: true}}/>
104 className='entitlement-pools-form-row-threshold-value'
105 onChange={thresholdValue => onDataChanged({thresholdValue})}
106 value={thresholdValue}
107 validations={thresholdValueValidation}
112 onEnumChange={entitlementMetric => onDataChanged({entitlementMetric:{choice: entitlementMetric, other: ''}})}
113 onOtherChange={entitlementMetric => onDataChanged({entitlementMetric:{choice: optionInputOther.OTHER, other: entitlementMetric}})}
114 selectedEnum={entitlementMetric && entitlementMetric.choice}
115 otherValue={entitlementMetric && entitlementMetric.other}
116 label={i18n('Entitlement Metric')}
117 validations={{required: true}}
118 values={EntitlementPoolsOptionsInputValues.ENTITLEMENT_METRIC}/>
120 onEnumChange={aggregationFunction => onDataChanged({aggregationFunction:{choice: aggregationFunction, other: ''}})}
121 onOtherChange={aggregationFunction => onDataChanged({aggregationFunction:{choice: optionInputOther.OTHER, other: aggregationFunction}})}
122 selectedEnum={aggregationFunction && aggregationFunction.choice}
123 otherValue={aggregationFunction && aggregationFunction.other}
124 validations={{required: true}}
125 label={i18n('Aggregate Function')}
126 values={EntitlementPoolsOptionsInputValues.AGGREGATE_FUNCTION}/>
130 <div className='entitlement-pools-form-row'>
133 onChange={manufacturerReferenceNumber => onDataChanged({manufacturerReferenceNumber})}
134 label={i18n('Manufacturer Reference Number')}
135 value={manufacturerReferenceNumber}
136 validations={{maxLength: 100, required: true}}
140 onEnumChange={time => onDataChanged({time:{choice: time, other: ''}})}
141 onOtherChange={time => onDataChanged({time:{choice: optionInputOther.OTHER, other: time}})}
142 selectedEnum={time && time.choice}
143 otherValue={time && time.other}
144 validations={timeValidation}
146 values={EntitlementPoolsOptionsInputValues.TIME}/>
148 <div className='entitlement-pools-form-row'>
150 onChange={increments => onDataChanged({increments})}
151 label={i18n('Increments')}
153 validations={{maxLength: 120}}
162 const {data: entitlementPool, previousData: previousEntitlementPool} = this.props;
163 this.props.onSubmit({entitlementPool, previousEntitlementPool});
167 export default EntitlementPoolsEditorView;