[SDC-29] Amdocs OnBoard 1707 initial commit.
[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 i18n from 'nfvo-utils/i18n/i18n.js';
18
19 import ListEditorView from 'nfvo-components/listEditor/ListEditorView.jsx';
20 import ListEditorItemView from 'nfvo-components/listEditor/ListEditorItemView.jsx';
21 import ListEditorItemViewField from 'nfvo-components/listEditor/ListEditorItemViewField.jsx';
22
23 class SoftwareProductNetworksView extends React.Component {
24
25         static propTypes = {
26                 networksList: React.PropTypes.arrayOf(React.PropTypes.shape({
27                         id: React.PropTypes.string.isRequired,
28                         name: React.PropTypes.string.isRequired,
29                         dhcp: React.PropTypes.bool.isRequired
30                 })).isRequired
31         };
32
33         state = {
34                 localFilter: ''
35         };
36
37         render() {
38                 const {localFilter} = this.state;
39
40                 return (
41                         <div className='vsp-networks-page'>
42                                 <ListEditorView
43                                         title={i18n('Networks')}
44                                         filterValue={localFilter}
45                                         placeholder={i18n('Filter Networks')}
46                                         onFilter={value => this.setState({localFilter: value})}
47                                         twoColumns>
48                                         {this.filterList().map(network => this.renderNetworksListItem(network))}
49                                 </ListEditorView>
50                         </div>
51                 );
52         }
53
54         renderNetworksListItem(network) {
55                 let {id, name, dhcp} = network;
56                 return (
57                         <ListEditorItemView
58                                 key={id}
59                                 className='list-editor-item-view'
60                                 isReadOnlyMode={true}>
61
62                                 <ListEditorItemViewField>
63                                         <div className='name'>{name}</div>
64                                 </ListEditorItemViewField>
65                                 <ListEditorItemViewField>
66                                         <div className='details'>
67                                                 <div className='title'>{i18n('DHCP')}</div>
68                                                 <div className='artifact-name'>{dhcp ? i18n('YES') : i18n('NO')}</div>
69                                         </div>
70                                 </ListEditorItemViewField>
71                         </ListEditorItemView>
72                 );
73         }
74
75         filterList() {
76                 let {networksList} = this.props;
77
78                 let {localFilter} = this.state;
79                 if (localFilter.trim()) {
80                         const filter = new RegExp(escape(localFilter), 'i');
81                         return networksList.filter(({name = ''}) => {
82                                 return escape(name).match(filter);
83                         });
84                 }
85                 else {
86                         return networksList;
87                 }
88         }
89 }
90
91 export default SoftwareProductNetworksView;