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 ListEditorView from 'nfvo-components/listEditor/ListEditorView.jsx';
 
  21 import ListEditorItemView from 'nfvo-components/listEditor/ListEditorItemView.jsx';
 
  23 import { extractUnits } from './EntitlementPoolsConstants';
 
  25 class EntitlementPoolsListEditorView extends React.Component {
 
  27         vendorName: PropTypes.string,
 
  28         licenseModelId: PropTypes.string.isRequired,
 
  29         entitlementPoolsList: PropTypes.array,
 
  30         isReadOnlyMode: PropTypes.bool.isRequired,
 
  31         isDisplayModal: PropTypes.bool,
 
  32         isModalInEditMode: PropTypes.bool,
 
  33         onAddEntitlementPoolClick: PropTypes.func,
 
  34         onEditEntitlementPoolClick: PropTypes.func,
 
  35         onDeleteEntitlementPool: PropTypes.func
 
  38     static defaultProps = {
 
  39         entitlementPoolsList: []
 
  47         let { isReadOnlyMode, onAddEntitlementPoolClick } = this.props;
 
  48         const { localFilter } = this.state;
 
  51             <div className="license-model-list-editor entitlement-pools-list-editor">
 
  53                     title={i18n('Entitlement Pools')}
 
  54                     plusButtonTitle={i18n('Add Entitlement Pool')}
 
  55                     onAdd={onAddEntitlementPoolClick}
 
  56                     filterValue={localFilter}
 
  57                     onFilter={value => this.setState({ localFilter: value })}
 
  58                     isReadOnlyMode={isReadOnlyMode}>
 
  59                     {this.filterList().map(entitlementPool =>
 
  60                         this.renderEntitlementPoolListItem(
 
  71         let { entitlementPoolsList } = this.props;
 
  72         let { localFilter } = this.state;
 
  73         if (localFilter.trim()) {
 
  74             const filter = new RegExp(escape(localFilter), 'i');
 
  75             return entitlementPoolsList.filter(
 
  76                 ({ name = '', description = '' }) => {
 
  78                         escape(name).match(filter) ||
 
  79                         escape(description).match(filter)
 
  84             return entitlementPoolsList;
 
  88     renderEntitlementPoolListItem(entitlementPool, isReadOnlyMode) {
 
  95             manufacturerReferenceNumber
 
  98             onEditEntitlementPoolClick,
 
  99             onDeleteEntitlementPool
 
 104                 onSelect={() => onEditEntitlementPoolClick(entitlementPool)}
 
 105                 onDelete={() => onDeleteEntitlementPool(entitlementPool)}
 
 106                 className="list-editor-item-view"
 
 107                 isReadOnlyMode={isReadOnlyMode}>
 
 108                 <div className="list-editor-item-view-field">
 
 109                     <div className="title">{i18n('Name')}</div>
 
 111                         <div className="textEllipses text name">{name}</div>
 
 115                 <div className="list-editor-item-view-field">
 
 116                     <div className="title">{i18n('Entitlement')}</div>
 
 117                     <div className="entitlement-pools-count">
 
 119                             `${thresholdValue} ${extractUnits(thresholdUnits)}`}
 
 122                 <div className="list-editor-item-view-field">
 
 123                     <div className="title">
 
 124                         {i18n('Manufacturer Reference Number')}
 
 126                     <div className="text description">
 
 127                         {manufacturerReferenceNumber}
 
 130                 <div className="list-editor-item-view-field">
 
 131                     <div className="title">{i18n('Description')}</div>
 
 132                     <div className="text description">{description}</div>
 
 134             </ListEditorItemView>
 
 139 export default EntitlementPoolsListEditorView;
 
 141 export function generateConfirmationMsg(entitlementPoolToDelete) {
 
 142     let poolName = entitlementPoolToDelete ? entitlementPoolToDelete.name : '';
 
 143     let msg = i18n('Are you sure you want to delete "{poolName}"?', {
 
 147         entitlementPoolToDelete &&
 
 148         entitlementPoolToDelete.referencingFeatureGroups &&
 
 149         entitlementPoolToDelete.referencingFeatureGroups.length > 0
 
 151                   'This entitlement pool is associated with one or more feature groups'