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';
22 import { SP_ENTITLEMENT_POOL_FORM } from '../EntitlementPoolsConstants.js';
23 import { DATE_FORMAT } from 'sdc-app/onboarding/OnboardingConstants.js';
24 import { optionsInputValues as LicenseModelOptionsInputValues } from '../../LicenseModelConstants.js';
25 import UuId from 'sdc-app/onboarding/licenseModel/components/UuId.jsx';
27 export const EntitlementPoolsFormContent = ({
32 thresholdValueValidation,
43 manufacturerReferenceNumber,
48 <GridSection hasLastColSet>
49 <GridItem colSpan={2}>
52 onDataChanged({ name }, SP_ENTITLEMENT_POOL_FORM, {
56 isValid={genericFieldInfo.name.isValid}
58 errorText={genericFieldInfo.name.errorText}
61 data-test-id="create-ep-name"
65 <GridItem colSpan={2} lastColInRow>
68 // setting the unit to the correct value
69 const selectedIndex = e.target.selectedIndex;
70 const val = e.target.options[selectedIndex].value;
72 { thresholdUnits: val },
73 SP_ENTITLEMENT_POOL_FORM
75 // TODO make sure that the value is valid too
76 if (thresholdValue && thresholdValue !== '') {
78 { thresholdValue: thresholdValue },
79 SP_ENTITLEMENT_POOL_FORM,
80 { thresholdValue: thresholdValueValidation }
84 value={thresholdUnits}
85 label={i18n('Threshold Units')}
86 data-test-id="create-ep-threshold-units"
87 isValid={genericFieldInfo.thresholdUnits.isValid}
88 errorText={genericFieldInfo.thresholdUnits.errorText}
89 groupClassName="bootstrap-input-options"
90 className="input-options-select"
92 {LicenseModelOptionsInputValues.THRESHOLD_UNITS.map(
94 <option key={mtype.enum} value={mtype.enum}>{`${
101 <GridItem colSpan={2} stretch>
103 onChange={description =>
104 onDataChanged({ description }, SP_ENTITLEMENT_POOL_FORM)
106 isValid={genericFieldInfo.description.isValid}
107 errorText={genericFieldInfo.description.errorText}
108 label={i18n('Description')}
110 data-test-id="create-ep-description"
114 <GridItem colSpan={2} lastColInRow>
116 className="entitlement-pools-form-row-threshold-value"
117 onChange={thresholdValue =>
120 SP_ENTITLEMENT_POOL_FORM,
122 thresholdValue: thresholdValueValidation
126 label={i18n('Threshold Value')}
127 isValid={genericFieldInfo.thresholdValue.isValid}
128 errorText={genericFieldInfo.thresholdValue.errorText}
129 data-test-id="create-ep-threshold-value"
130 value={thresholdValue}
134 onChange={increments =>
135 onDataChanged({ increments }, SP_ENTITLEMENT_POOL_FORM)
137 label={i18n('Increments')}
139 data-test-id="create-ep-increments"
144 <GridItem colSpan={2}>
146 className="entitlement-pools-form-row-threshold-value"
147 onChange={manufacturerReferenceNumber =>
149 { manufacturerReferenceNumber },
150 SP_ENTITLEMENT_POOL_FORM
154 genericFieldInfo.manufacturerReferenceNumber.isValid
158 genericFieldInfo.manufacturerReferenceNumber.errorText
160 label={i18n('Manufacturer Reference Number')}
161 data-test-id="create-ep-manufacturerReferenceNumber-value"
162 value={manufacturerReferenceNumber}
164 groupClassName="no-bottom-margin"
167 <GridItem colSpan={2} lastColInRow>
168 <div className="date-section">
170 groupClassName="no-bottom-margin"
172 label={i18n('Start Date')}
174 dateFormat={DATE_FORMAT}
175 startDate={startDate}
177 onChange={startDate =>
181 ? startDate.format(DATE_FORMAT)
184 SP_ENTITLEMENT_POOL_FORM,
185 { startDate: validateStartDate }
188 isValid={genericFieldInfo.startDate.isValid}
189 errorText={genericFieldInfo.startDate.errorText}
193 groupClassName="no-bottom-margin"
195 label={i18n('Expiry Date')}
197 dateFormat={DATE_FORMAT}
198 startDate={startDate}
200 onChange={expiryDate => {
203 expiryDate: expiryDate
204 ? expiryDate.format(DATE_FORMAT)
207 SP_ENTITLEMENT_POOL_FORM
211 SP_ENTITLEMENT_POOL_FORM,
213 startDate: validateStartDate
217 isValid={genericFieldInfo.expiryDate.isValid}
218 errorText={genericFieldInfo.expiryDate.errorText}
223 {id && versionUUID && <UuId id={id} versionUUID={versionUUID} />}
228 EntitlementPoolsFormContent.propTypes = {
229 data: PropTypes.object,
230 genericFieldInfo: PropTypes.object,
231 onDataChanged: PropTypes.func,
232 validateName: PropTypes.func,
233 thresholdValueValidation: PropTypes.func,
234 validateStartDate: PropTypes.func
237 export default EntitlementPoolsFormContent;