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';
18 import i18n from 'nfvo-utils/i18n/i18n.js';
19 import Modal from 'nfvo-components/modal/Modal.jsx';
20 import ListEditorView from 'nfvo-components/listEditor/ListEditorView.jsx';
21 import ListEditorItemView from 'nfvo-components/listEditor/ListEditorItemView.jsx';
23 import FeatureGroupEditor from './FeatureGroupEditor.js';
25 class FeatureGroupListEditorView extends React.Component {
27 vendorName: React.PropTypes.string,
28 licenseModelId: React.PropTypes.string.isRequired,
29 featureGroupsModal: React.PropTypes.shape({
30 show: React.PropTypes.bool,
31 editMode: React.PropTypes.bool
33 isReadOnlyMode: React.PropTypes.bool.isRequired,
34 onAddFeatureGroupClick: React.PropTypes.func,
35 onEditFeatureGroupClick: React.PropTypes.func,
36 onDeleteFeatureGroupClick: React.PropTypes.func,
37 onCancelFeatureGroupsEditor: React.PropTypes.func,
38 featureGroupsList: React.PropTypes.array
41 static defaultProps = {
42 featureGroupsList: [],
54 let {vendorName, licenseModelId, featureGroupsModal, isReadOnlyMode, onAddFeatureGroupClick, version} = this.props;
55 const {localFilter} = this.state;
57 <div className='feature-groups-list-editor'>
59 title={i18n('Feature Groups', {vendorName})}
60 plusButtonTitle={i18n('Add Feature Group')}
61 filterValue={localFilter}
62 onFilter={value => this.setState({localFilter: value})}
63 onAdd={() => onAddFeatureGroupClick(version)}
64 isReadOnlyMode={isReadOnlyMode}>
65 {this.filterList().map(listItem => this.renderFeatureGroupListItem(listItem, isReadOnlyMode, version))}
67 {featureGroupsModal.show && <Modal show={featureGroupsModal.show} bsSize='large' animation={true}
68 className='onborading-modal feature-group-modal'>
70 <Modal.Title>{`${featureGroupsModal.editMode ? i18n('Edit Feature Group') : i18n('Create New Feature Group')}`}</Modal.Title>
75 licenseModelId={licenseModelId}
76 isReadOnlyMode={isReadOnlyMode}/>
86 renderFeatureGroupListItem(listItem, isReadOnlyMode, version) {
87 let {name, description, entitlementPoolsIds = [], licenseKeyGroupsIds = []} = listItem;
91 onDelete={() => this.deleteFeatureGroupItem(listItem, version)}
92 onSelect={() => this.editFeatureGroupItem(listItem, version)}
93 className='list-editor-item-view'
94 isReadOnlyMode={isReadOnlyMode}>
95 <div className='list-editor-item-view-field'>
96 <div className='title'>{i18n('Name')}</div>
97 <div className='text name'>{name}</div>
100 <div className='list-editor-item-view-field'>
101 <div className='feature-groups-count-field'>
102 <div className='title'>{i18n('Entitlement')}</div>
103 <div className='title'>{i18n('Pools')}</div>
104 <div className='feature-groups-count-ep'>{entitlementPoolsIds.length || 0}</div>
106 <div className='feature-groups-count-field'>
107 <div className='title'>{i18n('License key')}</div>
108 <div className='title'>{i18n('Groups')}</div>
109 <div className='feature-groups-count-lk'>{licenseKeyGroupsIds.length || 0}</div>
113 <div className='list-editor-item-view-field'>
114 <div className='title'>{i18n('Description')}</div>
115 <div className='text description'>{description}</div>
118 </ListEditorItemView>
123 let {featureGroupsList} = this.props;
124 let {localFilter} = this.state;
125 if (localFilter.trim()) {
126 const filter = new RegExp(escape(localFilter), 'i');
127 return featureGroupsList.filter(({name = '', description = ''}) => {
128 return escape(name).match(filter) || escape(description).match(filter);
132 return featureGroupsList;
136 editFeatureGroupItem(featureGroup, version) {
137 this.props.onEditFeatureGroupClick(featureGroup, version);
140 deleteFeatureGroupItem(featureGroup, version) {
141 this.props.onDeleteFeatureGroupClick(featureGroup, version);
145 export default FeatureGroupListEditorView;
147 export function generateConfirmationMsg(featureGroupToDelete) {
148 let name = featureGroupToDelete ? featureGroupToDelete.name : '';
149 let msg = i18n('Are you sure you want to delete "{name}"?', {name});
150 let subMsg = featureGroupToDelete.referencingLicenseAgreements
151 && featureGroupToDelete.referencingLicenseAgreements.length > 0 ?
152 i18n('This feature group is associated with one ore more license agreements') :