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';
17 import PropTypes from 'prop-types';
18 import i18n from 'nfvo-utils/i18n/i18n.js';
19 import Modal from 'nfvo-components/modal/Modal.jsx';
21 import ListEditorView from 'nfvo-components/listEditor/ListEditorView.jsx';
22 import ListEditorItemView from 'nfvo-components/listEditor/ListEditorItemView.jsx';
23 import LicenseAgreementEditor from './LicenseAgreementEditor.js';
24 import {extractValue} from './LicenseAgreementConstants';
26 class LicenseAgreementListEditorView extends React.Component {
28 vendorName: PropTypes.string,
29 licenseModelId: PropTypes.string.isRequired,
30 licenseAgreementList: PropTypes.array,
31 isReadOnlyMode: PropTypes.bool.isRequired,
32 isDisplayModal: PropTypes.bool,
33 isModalInEditMode: PropTypes.bool,
34 onAddLicenseAgreementClick: PropTypes.func,
35 onEditLicenseAgreementClick: PropTypes.func,
36 onDeleteLicenseAgreement: PropTypes.func,
39 static defaultProps = {
40 licenseAgreementList: []
48 const {licenseModelId, isReadOnlyMode, isDisplayModal, isModalInEditMode, version} = this.props;
49 const {onAddLicenseAgreementClick} = this.props;
50 const {localFilter} = this.state;
53 <div className='license-model-list-editor license-agreement-list-editor'>
55 title={i18n('License Agreements')}
56 plusButtonTitle={i18n('Add License Agreement')}
57 onAdd={() => onAddLicenseAgreementClick(version)}
58 filterValue={localFilter}
59 onFilter={value => this.setState({localFilter: value})}
60 isReadOnlyMode={isReadOnlyMode}>
61 {this.filterList().map(licenseAgreement => this.renderLicenseAgreementListItem(licenseAgreement, isReadOnlyMode, version))}
63 <Modal show={isDisplayModal} bsSize='large' animation={true} className='onborading-modal license-model-modal license-agreement-modal'>
65 <Modal.Title>{`${isModalInEditMode ? i18n('Edit License Agreement') : i18n('Create New License Agreement')}`}</Modal.Title>
70 <LicenseAgreementEditor version={version} licenseModelId={licenseModelId} isReadOnlyMode={isReadOnlyMode} />
80 let {licenseAgreementList} = this.props;
81 let {localFilter} = this.state;
82 if (localFilter.trim()) {
83 const filter = new RegExp(escape(localFilter), 'i');
84 return licenseAgreementList.filter(({name = '', description = '', licenseTerm = ''}) => {
85 return escape(name).match(filter) || escape(description).match(filter) || escape(extractValue(licenseTerm)).match(filter);
89 return licenseAgreementList;
93 renderLicenseAgreementListItem(licenseAgreement, isReadOnlyMode, version) {
94 let {id, name, description, licenseTerm, featureGroupsIds = []} = licenseAgreement;
95 let {onEditLicenseAgreementClick, onDeleteLicenseAgreement} = this.props;
99 onSelect={() => onEditLicenseAgreementClick(licenseAgreement, version)}
100 onDelete={() => onDeleteLicenseAgreement(licenseAgreement, version)}
101 className='list-editor-item-view'
102 isReadOnlyMode={isReadOnlyMode}>
103 <div className='list-editor-item-view-field'>
104 <div className='title'>{i18n('Name')}</div>
105 <div className='text name'>{name}</div>
107 <div className='list-editor-item-view-field'>
108 <div className='list-editor-item-view-field-tight'>
109 <div className='title'>{i18n('Type')}</div>
110 <div className='text type'>{extractValue(licenseTerm)}</div>
112 <div className='list-editor-item-view-field-tight'>
113 <div className='title'>{i18n('Feature')}</div>
114 <div className='title'>{i18n('Groups')}</div>
115 <div className='feature-groups-count'>{featureGroupsIds.length}</div>
118 <div className='list-editor-item-view-field'>
119 <div className='title'>{i18n('Description')}</div>
120 <div className='text description'>{description}</div>
122 </ListEditorItemView>
127 export default LicenseAgreementListEditorView;