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';
19 import i18n from 'nfvo-utils/i18n/i18n.js';
20 import Modal from 'nfvo-components/modal/Modal.jsx';
21 import ListEditorView from 'nfvo-components/listEditor/ListEditorView.jsx';
22 import ListEditorItemView from 'nfvo-components/listEditor/ListEditorItemView.jsx';
24 import EntitlementPoolsEditor from './EntitlementPoolsEditor.js';
25 import { extractUnits } from './EntitlementPoolsConstants';
27 class EntitlementPoolsListEditorView extends React.Component {
29 vendorName: PropTypes.string,
30 licenseModelId: PropTypes.string.isRequired,
31 entitlementPoolsList: PropTypes.array,
32 isReadOnlyMode: PropTypes.bool.isRequired,
33 isDisplayModal: PropTypes.bool,
34 isModalInEditMode: PropTypes.bool,
35 onAddEntitlementPoolClick: PropTypes.func,
36 onEditEntitlementPoolClick: PropTypes.func,
37 onDeleteEntitlementPool: PropTypes.func
40 static defaultProps = {
41 entitlementPoolsList: []
56 let { onAddEntitlementPoolClick } = this.props;
57 const { localFilter } = this.state;
60 <div className="license-model-list-editor entitlement-pools-list-editor">
62 title={i18n('Entitlement Pools')}
63 plusButtonTitle={i18n('Add Entitlement Pool')}
64 onAdd={onAddEntitlementPoolClick}
65 filterValue={localFilter}
66 onFilter={value => this.setState({ localFilter: value })}
67 isReadOnlyMode={isReadOnlyMode}>
68 {this.filterList().map(entitlementPool =>
69 this.renderEntitlementPoolListItem(
79 className="onborading-modal license-model-modal entitlement-pools-modal">
83 ? i18n('Edit Entitlement Pool')
84 : i18n('Create New Entitlement Pool')
89 <EntitlementPoolsEditor
91 licenseModelId={licenseModelId}
92 isReadOnlyMode={isReadOnlyMode}
102 let { entitlementPoolsList } = this.props;
103 let { localFilter } = this.state;
104 if (localFilter.trim()) {
105 const filter = new RegExp(escape(localFilter), 'i');
106 return entitlementPoolsList.filter(
107 ({ name = '', description = '' }) => {
109 escape(name).match(filter) ||
110 escape(description).match(filter)
115 return entitlementPoolsList;
119 renderEntitlementPoolListItem(entitlementPool, isReadOnlyMode) {
126 manufacturerReferenceNumber
129 onEditEntitlementPoolClick,
130 onDeleteEntitlementPool
135 onSelect={() => onEditEntitlementPoolClick(entitlementPool)}
136 onDelete={() => onDeleteEntitlementPool(entitlementPool)}
137 className="list-editor-item-view"
138 isReadOnlyMode={isReadOnlyMode}>
139 <div className="list-editor-item-view-field">
140 <div className="title">{i18n('Name')}</div>
142 <div className="textEllipses text name">{name}</div>
146 <div className="list-editor-item-view-field">
147 <div className="title">{i18n('Entitlement')}</div>
148 <div className="entitlement-pools-count">
150 `${thresholdValue} ${extractUnits(thresholdUnits)}`}
153 <div className="list-editor-item-view-field">
154 <div className="title">
155 {i18n('Manufacturer Reference Number')}
157 <div className="text description">
158 {manufacturerReferenceNumber}
161 <div className="list-editor-item-view-field">
162 <div className="title">{i18n('Description')}</div>
163 <div className="text description">{description}</div>
165 </ListEditorItemView>
170 export default EntitlementPoolsListEditorView;
172 export function generateConfirmationMsg(entitlementPoolToDelete) {
173 let poolName = entitlementPoolToDelete ? entitlementPoolToDelete.name : '';
174 let msg = i18n('Are you sure you want to delete "{poolName}"?', {
178 entitlementPoolToDelete &&
179 entitlementPoolToDelete.referencingFeatureGroups &&
180 entitlementPoolToDelete.referencingFeatureGroups.length > 0
182 'This entitlement pool is associated with one or more feature groups'