Add collaboration feature
[sdc.git] / openecomp-ui / src / sdc-app / onboarding / softwareProduct / networks / SoftwareProductNetworksView.jsx
1 /*!
2  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 import React from 'react';
17 import PropTypes from 'prop-types';
18 import i18n from 'nfvo-utils/i18n/i18n.js';
19
20 import ListEditorView from 'nfvo-components/listEditor/ListEditorView.jsx';
21 import ListEditorItemView from 'nfvo-components/listEditor/ListEditorItemView.jsx';
22 import ListEditorItemViewField from 'nfvo-components/listEditor/ListEditorItemViewField.jsx';
23
24 class SoftwareProductNetworksView extends React.Component {
25
26         static propTypes = {
27                 networksList: PropTypes.arrayOf(PropTypes.shape({
28                         id: PropTypes.string.isRequired,
29                         name: PropTypes.string.isRequired,
30                         dhcp: PropTypes.bool.isRequired
31                 })).isRequired,
32                 isReadOnlyMode: PropTypes.bool.isRequired
33         };
34
35         state = {
36                 localFilter: ''
37         };
38
39         render() {
40                 const {localFilter} = this.state;
41                 const {isReadOnlyMode} = this.props;
42
43                 return (
44                         <div className='vsp-networks-page'>
45                                 <ListEditorView
46                                         title={i18n('Networks')}
47                                         filterValue={localFilter}
48                                         placeholder={i18n('Filter Networks')}
49                                         onFilter={value => this.setState({localFilter: value})}
50                                         twoColumns>
51                                         {this.filterList().map(network => this.renderNetworksListItem({network, isReadOnlyMode}))}
52                                 </ListEditorView>
53                         </div>
54                 );
55         }
56
57         renderNetworksListItem({network, isReadOnlyMode}) {
58                 let {id, name, dhcp} = network;
59                 return (
60                         <ListEditorItemView
61                                 key={id}
62                                 className='list-editor-item-view'
63                                 isReadOnlyMode={isReadOnlyMode}>
64
65                                 <ListEditorItemViewField>
66                                         <div className='name'>{name}</div>
67                                 </ListEditorItemViewField>
68                                 <ListEditorItemViewField>
69                                         <div className='details'>
70                                                 <div className='title'>{i18n('DHCP')}</div>
71                                                 <div className='artifact-name'>{dhcp ? i18n('YES') : i18n('NO')}</div>
72                                         </div>
73                                 </ListEditorItemViewField>
74                         </ListEditorItemView>
75                 );
76         }
77
78         filterList() {
79                 let {networksList} = this.props;
80
81                 let {localFilter} = this.state;
82                 if (localFilter.trim()) {
83                         const filter = new RegExp(escape(localFilter), 'i');
84                         return networksList.filter(({name = ''}) => {
85                                 return escape(name).match(filter);
86                         });
87                 }
88                 else {
89                         return networksList;
90                 }
91         }
92 }
93
94 export default SoftwareProductNetworksView;