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';
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 LicenseKeyGroupsEditor from './LicenseKeyGroupsEditor.js';
24 import InputOptions, {
25 other as optionInputOther
26 } from 'nfvo-components/input/validation/InputOptions.jsx';
27 import { optionsInputValues } from './LicenseKeyGroupsConstants';
29 class LicenseKeyGroupsListEditorView extends React.Component {
31 vendorName: PropTypes.string,
32 licenseModelId: PropTypes.string.isRequired,
33 licenseKeyGroupsList: PropTypes.array,
34 isReadOnlyMode: PropTypes.bool.isRequired,
35 isDisplayModal: PropTypes.bool,
36 isModalInEditMode: PropTypes.bool,
37 onAddLicenseKeyGroupClick: PropTypes.func,
38 onEditLicenseKeyGroupClick: PropTypes.func,
39 onDeleteLicenseKeyGroupClick: PropTypes.func
42 static defaultProps = {
43 licenseKeyGroupsList: []
58 let { onAddLicenseKeyGroupClick } = this.props;
59 const { localFilter } = this.state;
62 <div className="license-model-list-editor license-key-groups-list-editor">
64 title={i18n('License Key Groups')}
65 plusButtonTitle={i18n('Add License Key Group')}
66 onAdd={onAddLicenseKeyGroupClick}
67 filterValue={localFilter}
68 onFilter={value => this.setState({ localFilter: value })}
69 isReadOnlyMode={isReadOnlyMode}>
70 {this.filterList().map(licenseKeyGroup =>
71 this.renderLicenseKeyGroupListItem(
81 className="onborading-modal license-model-modal license-key-groups-modal">
85 ? i18n('Edit License Key Group')
86 : i18n('Create New License Key Group')
91 <LicenseKeyGroupsEditor
93 licenseModelId={licenseModelId}
94 isReadOnlyMode={isReadOnlyMode}
104 let { licenseKeyGroupsList } = this.props;
105 let { localFilter } = this.state;
106 if (localFilter.trim()) {
107 const filter = new RegExp(escape(localFilter), 'i');
108 return licenseKeyGroupsList.filter(
109 ({ name = '', description = '', type = '' }) => {
111 escape(name).match(filter) ||
112 escape(description).match(filter) ||
113 escape(type).match(filter)
118 return licenseKeyGroupsList;
122 renderLicenseKeyGroupListItem(licenseKeyGroup, isReadOnlyMode) {
128 manufacturerReferenceNumber
131 onEditLicenseKeyGroupClick,
132 onDeleteLicenseKeyGroupClick
137 onSelect={() => onEditLicenseKeyGroupClick(licenseKeyGroup)}
138 onDelete={() => onDeleteLicenseKeyGroupClick(licenseKeyGroup)}
139 className="list-editor-item-view"
140 isReadOnlyMode={isReadOnlyMode}>
141 <div className="list-editor-item-view-field">
142 <div className="title">{i18n('Name')}</div>
143 <div className="text name">{name}</div>
146 <div className="list-editor-item-view-field">
147 <div className="title">{i18n('Type')}</div>
148 <div className="text type">
149 {InputOptions.getTitleByName(optionsInputValues, type)}
152 <div className="list-editor-item-view-field">
153 <div className="title">
154 {i18n('Manufacturer Reference Number')}
156 <div className="text description">
157 {manufacturerReferenceNumber}
160 <div className="list-editor-item-view-field">
161 <div className="title">{i18n('Description')}</div>
162 <div className="text description">{description}</div>
164 </ListEditorItemView>
169 if (item === undefined) {
171 } //TODO fix it sooner rather than later
174 ? item.choice === optionInputOther.OTHER
176 : InputOptions.getTitleByName(optionsInputValues, item.choice)
181 export default LicenseKeyGroupsListEditorView;
183 export function generateConfirmationMsg(licenseKeyGroupToDelete) {
184 let name = licenseKeyGroupToDelete ? licenseKeyGroupToDelete.name : '';
185 let msg = i18n('Are you sure you want to delete "{name}"?', { name: name });
187 licenseKeyGroupToDelete.referencingFeatureGroups &&
188 licenseKeyGroupToDelete.referencingFeatureGroups.length > 0
190 'This license key group is associated with one or more feature groups'