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 Validator from 'nfvo-utils/Validator.js';
21 import Tabs from 'sdc-ui/lib/react/Tabs.js';
22 import Tab from 'sdc-ui/lib/react/Tab.js';
24 import Button from 'sdc-ui/lib/react/Button.js';
25 import Form from 'nfvo-components/input/validation/Form.jsx';
26 //import GridSection from 'nfvo-components/grid/GridSection.jsx';
27 import { LKG_FORM_NAME, tabIds } from './LicenseKeyGroupsConstants.js';
31 thresholdValueValidation
32 } from '../LicenseModelValidations.js';
34 import LicenseKeyGroupsLimits from './LicenseKeyGroupsLimits.js';
38 } from '../limits/LimitEditorConstants.js';
39 import LicenseKeyGroupFormContent from './components/FormContent.jsx';
40 import ModalButtons from 'sdc-app/onboarding/licenseModel/components/ModalButtons.jsx';
42 const TabButton = props => {
43 const { onClick, disabled, className } = props;
44 const dataTestId = props['data-test-id'];
48 onClick={disabled ? undefined : onClick}
49 data-test-id={dataTestId}
57 const LicenseKeyGroupPropType = PropTypes.shape({
59 name: PropTypes.string,
60 description: PropTypes.string,
61 increments: PropTypes.string,
62 type: PropTypes.string,
63 thresholdUnits: PropTypes.string,
64 thresholdValue: PropTypes.number,
65 startDate: PropTypes.string,
66 expiryDate: PropTypes.string
69 class LicenseKeyGroupsEditorView extends React.Component {
71 data: LicenseKeyGroupPropType,
72 previousData: LicenseKeyGroupPropType,
73 LKGNames: PropTypes.object,
74 isReadOnlyMode: PropTypes.bool,
75 onDataChanged: PropTypes.func.isRequired,
76 onSubmit: PropTypes.func.isRequired,
77 onCancel: PropTypes.func.isRequired
80 static defaultProps = {
84 componentDidUpdate(prevProps) {
86 this.props.formReady &&
87 this.props.formReady !== prevProps.formReady
89 // if form validation succeeded -> continue with submit
95 localFeatureGroupsListFilter: '',
96 selectedTab: tabIds.GENERAL,
109 let { selectedTab } = this.state;
110 const isTabsDisabled = !data.id || !this.props.isFormValid;
112 <div className="license-keygroup-editor license-model-modal license-key-groups-modal">
115 activeTab={selectedTab}
116 onTabClick={tabIndex => {
117 if (tabIndex === tabIds.ADD_LIMIT_BUTTON) {
120 this.setState({ selectedTab: tabIndex });
121 onCloseLimitEditor();
122 this.setState({ selectedLimit: '' });
127 tabId={tabIds.GENERAL}
128 data-test-id="general-tab"
129 title={i18n('General')}>
130 {genericFieldInfo && (
134 isValid={this.props.isFormValid}
135 formReady={this.props.formReady}
136 onValidateForm={() =>
137 this.props.onValidateForm(LKG_FORM_NAME)
140 isReadOnlyMode={isReadOnlyMode}
141 className="license-model-form license-key-groups-form">
142 <LicenseKeyGroupFormContent
144 onDataChanged={onDataChanged}
145 genericFieldInfo={genericFieldInfo}
146 validateName={value =>
147 this.validateName(value)
149 validateStartDate={(value, state) =>
150 validateStartDate(value, state)
152 thresholdValueValidation={(value, state) =>
153 thresholdValueValidation(value, state)
160 tabId={tabIds.SP_LIMITS}
161 disabled={isTabsDisabled}
162 data-test-id="general-tab"
163 title={i18n('SP Limits')}>
164 {selectedTab === tabIds.SP_LIMITS && (
165 <LicenseKeyGroupsLimits
166 limitType={limitType.SERVICE_PROVIDER}
167 limitsList={limitsList.filter(
169 item.type === limitType.SERVICE_PROVIDER
171 selectedLimit={this.state.selectedLimit}
172 onCloseLimitEditor={() =>
173 this.onCloseLimitEditor()
175 onSelectLimit={limit =>
176 this.onSelectLimit(limit)
178 isReadOnlyMode={isReadOnlyMode}
183 tabId={tabIds.VENDOR_LIMITS}
184 disabled={isTabsDisabled}
185 data-test-id="general-tab"
186 title={i18n('Vendor Limits')}>
187 {selectedTab === tabIds.VENDOR_LIMITS && (
188 <LicenseKeyGroupsLimits
189 limitType={limitType.VENDOR}
190 limitsList={limitsList.filter(
191 item => item.type === limitType.VENDOR
193 selectedLimit={this.state.selectedLimit}
194 onCloseLimitEditor={() =>
195 this.onCloseLimitEditor()
197 onSelectLimit={limit =>
198 this.onSelectLimit(limit)
200 isReadOnlyMode={isReadOnlyMode}
204 {selectedTab !== tabIds.GENERAL ? (
206 tabId={tabIds.ADD_LIMIT_BUTTON}
208 !!this.state.selectedLimit || isReadOnlyMode
210 data-test-id="add-limits-tab"
211 className="add-limit-button">
216 !!this.state.selectedLimit || isReadOnlyMode
222 <TabButton key="empty_lm_tab_key" />
223 ) // Render empty div to not break tabs
227 className="sdc-modal__footer"
228 selectedLimit={this.state.selectedLimit}
229 isFormValid={this.props.isFormValid}
230 isReadOnlyMode={isReadOnlyMode}
231 onSubmit={this.submit}
232 onCancel={this.props.onCancel}
240 data: licenseKeyGroup,
241 previousData: previousLicenseKeyGroup,
247 onValidateForm(LKG_FORM_NAME);
249 onSubmit({ licenseKeyGroup, previousLicenseKeyGroup });
253 validateName(value) {
254 const { data: { id }, LKGNames } = this.props;
255 const isExists = Validator.isItemNameAlreadyExistsInList({
262 ? { isValid: true, errorText: '' }
266 "License key group by the name '" +
268 "' already exists. License key group name must be unique"
273 onSelectLimit(limit) {
274 if (limit.id === this.state.selectedLimit) {
275 this.setState({ selectedLimit: '' });
278 this.setState({ selectedLimit: limit.id });
279 this.props.onOpenLimitEditor(limit);
282 onCloseLimitEditor() {
283 this.setState({ selectedLimit: '' });
284 this.props.onCloseLimitEditor();
288 this.setState({ selectedLimit: NEW_LIMIT_TEMP_ID });
289 this.props.onOpenLimitEditor();
293 export default LicenseKeyGroupsEditorView;