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 class FeatureGroupListEditorView extends React.Component {
25 vendorName: PropTypes.string,
26 licenseModelId: PropTypes.string.isRequired,
27 isReadOnlyMode: PropTypes.bool.isRequired,
28 onAddFeatureGroupClick: PropTypes.func,
29 onEditFeatureGroupClick: PropTypes.func,
30 onDeleteFeatureGroupClick: PropTypes.func,
31 onCancelFeatureGroupsEditor: PropTypes.func,
32 featureGroupsList: PropTypes.array
35 static defaultProps = {
44 let { isReadOnlyMode, onAddFeatureGroupClick, version } = this.props;
45 const { localFilter } = this.state;
47 <div className="license-model-list-editor feature-groups-list-editor">
49 title={i18n('Feature Groups')}
50 plusButtonTitle={i18n('Add Feature Group')}
51 filterValue={localFilter}
52 onFilter={value => this.setState({ localFilter: value })}
53 onAdd={() => onAddFeatureGroupClick(version)}
54 isReadOnlyMode={isReadOnlyMode}>
55 {this.filterList().map(listItem =>
56 this.renderFeatureGroupListItem(
67 renderFeatureGroupListItem(listItem, isReadOnlyMode, version) {
71 entitlementPoolsIds = [],
72 licenseKeyGroupsIds = []
77 onDelete={() => this.deleteFeatureGroupItem(listItem, version)}
79 this.editFeatureGroupItem(listItem, version, isReadOnlyMode)
81 className="list-editor-item-view"
82 isReadOnlyMode={isReadOnlyMode}>
83 <div className="list-editor-item-view-field">
84 <div className="title">{i18n('Name')}</div>
85 <div className="text name">{name}</div>
88 <div className="list-editor-item-view-field smaller-field">
89 <div className="feature-groups-count-field">
90 <div className="title">{i18n('EP')}</div>
91 <div className="feature-groups-count-ep">
92 {entitlementPoolsIds.length || 0}
96 <div className="list-editor-item-view-field smaller-field">
97 <div className="feature-groups-count-field">
98 <div className="title">{i18n('LKG')}</div>
99 <div className="feature-groups-count-lk">
100 {licenseKeyGroupsIds.length || 0}
104 <div className="list-editor-item-view-field">
105 <div className="title">{i18n('Description')}</div>
106 <div className="text description">{description}</div>
108 </ListEditorItemView>
113 let { featureGroupsList } = this.props;
114 let { localFilter } = this.state;
115 if (localFilter.trim()) {
116 const filter = new RegExp(escape(localFilter), 'i');
117 return featureGroupsList.filter(
118 ({ name = '', description = '' }) => {
120 escape(name).match(filter) ||
121 escape(description).match(filter)
126 return featureGroupsList;
130 editFeatureGroupItem(featureGroup, version) {
131 this.props.onEditFeatureGroupClick(featureGroup, version);
134 deleteFeatureGroupItem(featureGroup, version) {
135 this.props.onDeleteFeatureGroupClick(featureGroup, version);
139 export default FeatureGroupListEditorView;
141 export function generateConfirmationMsg(featureGroupToDelete) {
142 let name = featureGroupToDelete ? featureGroupToDelete.name : '';
143 let msg = i18n('Are you sure you want to delete "{name}"?', { name: name });
145 featureGroupToDelete.referencingLicenseAgreements &&
146 featureGroupToDelete.referencingLicenseAgreements.length > 0
148 'This feature group is associated with one ore more license agreements'