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 ListEditorView from 'nfvo-components/listEditor/ListEditorView.jsx';
20 import ListEditorItemView from 'nfvo-components/listEditor/ListEditorItemView.jsx';
22 import InputOptions, {
23 other as optionInputOther
24 } from 'nfvo-components/input/validation/InputOptions.jsx';
25 import { optionsInputValues } from './LicenseKeyGroupsConstants';
27 class LicenseKeyGroupsListEditorView extends React.Component {
29 vendorName: PropTypes.string,
30 licenseModelId: PropTypes.string.isRequired,
31 licenseKeyGroupsList: PropTypes.array,
32 isReadOnlyMode: PropTypes.bool.isRequired,
33 onAddLicenseKeyGroupClick: PropTypes.func,
34 onEditLicenseKeyGroupClick: PropTypes.func,
35 onDeleteLicenseKeyGroupClick: PropTypes.func
38 static defaultProps = {
39 licenseKeyGroupsList: []
47 let { isReadOnlyMode } = this.props;
48 let { onAddLicenseKeyGroupClick } = this.props;
49 const { localFilter } = this.state;
52 <div className="license-model-list-editor license-key-groups-list-editor">
54 title={i18n('License Key Groups')}
55 plusButtonTitle={i18n('Add License Key Group')}
56 onAdd={onAddLicenseKeyGroupClick}
57 filterValue={localFilter}
58 onFilter={value => this.setState({ localFilter: value })}
59 isReadOnlyMode={isReadOnlyMode}>
60 {this.filterList().map(licenseKeyGroup =>
61 this.renderLicenseKeyGroupListItem(
72 let { licenseKeyGroupsList } = this.props;
73 let { localFilter } = this.state;
74 if (localFilter.trim()) {
75 const filter = new RegExp(escape(localFilter), 'i');
76 return licenseKeyGroupsList.filter(
77 ({ name = '', description = '', type = '' }) => {
79 escape(name).match(filter) ||
80 escape(description).match(filter) ||
81 escape(type).match(filter)
86 return licenseKeyGroupsList;
90 renderLicenseKeyGroupListItem(licenseKeyGroup, isReadOnlyMode) {
96 manufacturerReferenceNumber
99 onEditLicenseKeyGroupClick,
100 onDeleteLicenseKeyGroupClick
106 onEditLicenseKeyGroupClick(licenseKeyGroup, isReadOnlyMode)
108 onDelete={() => onDeleteLicenseKeyGroupClick(licenseKeyGroup)}
109 className="list-editor-item-view"
110 isReadOnlyMode={isReadOnlyMode}>
111 <div className="list-editor-item-view-field">
112 <div className="title">{i18n('Name')}</div>
113 <div className="text name">{name}</div>
116 <div className="list-editor-item-view-field">
117 <div className="title">{i18n('Type')}</div>
118 <div className="text type">
119 {InputOptions.getTitleByName(optionsInputValues, type)}
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 if (item === undefined) {
141 } //TODO fix it sooner rather than later
144 ? item.choice === optionInputOther.OTHER
146 : InputOptions.getTitleByName(optionsInputValues, item.choice)
151 export default LicenseKeyGroupsListEditorView;
153 export function generateConfirmationMsg(licenseKeyGroupToDelete) {
154 let name = licenseKeyGroupToDelete ? licenseKeyGroupToDelete.name : '';
155 let msg = i18n('Are you sure you want to delete "{name}"?', { name: name });
157 licenseKeyGroupToDelete.referencingFeatureGroups &&
158 licenseKeyGroupToDelete.referencingFeatureGroups.length > 0
160 'This license key group is associated with one or more feature groups'