2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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) {
128 onEditEntitlementPoolClick,
129 onDeleteEntitlementPool
134 onSelect={() => onEditEntitlementPoolClick(entitlementPool)}
135 onDelete={() => onDeleteEntitlementPool(entitlementPool)}
136 className="list-editor-item-view"
137 isReadOnlyMode={isReadOnlyMode}>
138 <div className="list-editor-item-view-field">
139 <div className="title">{i18n('Name')}</div>
141 <div className="textEllipses text name">{name}</div>
145 <div className="list-editor-item-view-field">
146 <div className="title">{i18n('Entitlement')}</div>
147 <div className="entitlement-pools-count">
149 `${thresholdValue} ${extractUnits(thresholdUnits)}`}
153 <div className="list-editor-item-view-field">
154 <div className="title">{i18n('Description')}</div>
155 <div className="text description">{description}</div>
157 </ListEditorItemView>
162 export default EntitlementPoolsListEditorView;
164 export function generateConfirmationMsg(entitlementPoolToDelete) {
165 let poolName = entitlementPoolToDelete ? entitlementPoolToDelete.name : '';
166 let msg = i18n('Are you sure you want to delete "{poolName}"?', {
170 entitlementPoolToDelete &&
171 entitlementPoolToDelete.referencingFeatureGroups &&
172 entitlementPoolToDelete.referencingFeatureGroups.length > 0
174 'This entitlement pool is associated with one or more feature groups'