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 GridSection from 'nfvo-components/grid/GridSection.jsx';
20 import GridItem from 'nfvo-components/grid/GridItem.jsx';
21 import Input from 'nfvo-components/input/validation/Input.jsx';
24 SP_ENTITLEMENT_POOL_FORM
25 } from 'sdc-app/onboarding/licenseModel/entitlementPools/EntitlementPoolsConstants.js';
26 import { DATE_FORMAT } from 'sdc-app/onboarding/OnboardingConstants.js';
27 import { optionsInputValues as LicenseModelOptionsInputValues } from '../../LicenseModelConstants.js';
28 import UuId from 'sdc-app/onboarding/licenseModel/components/UuId.jsx';
30 export const EntitlementPoolsFormContent = ({
35 thresholdValueValidation,
47 manufacturerReferenceNumber,
52 <GridSection hasLostColSet>
53 <GridItem colSpan={2}>
56 onDataChanged({ name }, SP_ENTITLEMENT_POOL_FORM, {
60 isValid={genericFieldInfo.name.isValid}
62 errorText={genericFieldInfo.name.errorText}
65 data-test-id="create-ep-name"
69 <GridItem colSpan={2}>
73 const selectedIndex = e.target.selectedIndex;
74 const val = e.target.options[selectedIndex].value;
75 onDataChanged({ type: val }, SP_ENTITLEMENT_POOL_FORM);
79 data-test-id="create-ep-type"
80 isValid={genericFieldInfo.type.isValid}
81 errorText={genericFieldInfo.type.errorText}
82 groupClassName="bootstrap-input-options"
83 className="input-options-select"
86 {optionsInputValues.TYPE.map(type => (
87 <option key={type.enum} value={type.enum}>
93 <GridItem colSpan={2} stretch>
95 onChange={description =>
96 onDataChanged({ description }, SP_ENTITLEMENT_POOL_FORM)
98 isValid={genericFieldInfo.description.isValid}
99 errorText={genericFieldInfo.description.errorText}
100 label={i18n('Description')}
102 data-test-id="create-ep-description"
109 // setting the unit to the correct value
110 const selectedIndex = e.target.selectedIndex;
111 const val = e.target.options[selectedIndex].value;
113 { thresholdUnits: val },
114 SP_ENTITLEMENT_POOL_FORM
116 // TODO make sure that the value is valid too
117 if (thresholdValue && thresholdValue !== '') {
119 { thresholdValue: thresholdValue },
120 SP_ENTITLEMENT_POOL_FORM,
121 { thresholdValue: thresholdValueValidation }
125 value={thresholdUnits}
126 label={i18n('Threshold Units')}
127 data-test-id="create-ep-threshold-units"
128 isValid={genericFieldInfo.thresholdUnits.isValid}
129 errorText={genericFieldInfo.thresholdUnits.errorText}
130 groupClassName="bootstrap-input-options"
131 className="input-options-select"
133 {LicenseModelOptionsInputValues.THRESHOLD_UNITS.map(
135 <option key={mtype.enum} value={mtype.enum}>{`${
143 label={i18n('Start Date')}
145 dateFormat={DATE_FORMAT}
146 startDate={startDate}
148 onChange={startDate =>
152 ? startDate.format(DATE_FORMAT)
155 SP_ENTITLEMENT_POOL_FORM,
156 { startDate: validateStartDate }
159 isValid={genericFieldInfo.startDate.isValid}
160 errorText={genericFieldInfo.startDate.errorText}
166 className="entitlement-pools-form-row-threshold-value"
167 onChange={thresholdValue =>
170 SP_ENTITLEMENT_POOL_FORM,
172 thresholdValue: thresholdValueValidation
176 label={i18n('Threshold Value')}
177 isValid={genericFieldInfo.thresholdValue.isValid}
178 errorText={genericFieldInfo.thresholdValue.errorText}
179 data-test-id="create-ep-threshold-value"
180 value={thresholdValue}
185 label={i18n('Expiry Date')}
187 dateFormat={DATE_FORMAT}
188 startDate={startDate}
190 onChange={expiryDate => {
193 expiryDate: expiryDate
194 ? expiryDate.format(DATE_FORMAT)
197 SP_ENTITLEMENT_POOL_FORM
199 onDataChanged({ startDate }, SP_ENTITLEMENT_POOL_FORM, {
200 startDate: validateStartDate
203 isValid={genericFieldInfo.expiryDate.isValid}
204 errorText={genericFieldInfo.expiryDate.errorText}
208 <GridItem colSpan={2}>
210 className="entitlement-pools-form-row-threshold-value"
211 onChange={manufacturerReferenceNumber =>
213 { manufacturerReferenceNumber },
214 SP_ENTITLEMENT_POOL_FORM
218 genericFieldInfo.manufacturerReferenceNumber.isValid
222 genericFieldInfo.manufacturerReferenceNumber.errorText
224 label={i18n('Manufacturer Reference Number')}
225 data-test-id="create-ep-manufacturerReferenceNumber-value"
226 value={manufacturerReferenceNumber}
230 <GridItem colSpan={2}>
232 onChange={increments =>
233 onDataChanged({ increments }, SP_ENTITLEMENT_POOL_FORM)
235 label={i18n('Increments')}
237 data-test-id="create-ep-increments"
238 groupClassName="no-bottom-margin"
242 {id && versionUUID && <UuId id={id} versionUUID={versionUUID} />}
247 EntitlementPoolsFormContent.propTypes = {
248 data: PropTypes.object,
249 genericFieldInfo: PropTypes.object,
250 onDataChanged: PropTypes.func,
251 validateName: PropTypes.func,
252 thresholdValueValidation: PropTypes.func,
253 validateStartDate: PropTypes.func
256 export default EntitlementPoolsFormContent;