[SDC-29] Amdocs OnBoard 1707 initial commit.
[sdc.git] / openecomp-ui / src / nfvo-components / listEditor / ListEditorView.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 classnames from 'classnames';
18 import ExpandableInput from 'nfvo-components/input/ExpandableInput.jsx';
19
20 const ListEditorHeader = ({onAdd, isReadOnlyMode, title, plusButtonTitle}) => {
21          return (
22                  <div className='list-editor-view-header'>
23                          {title && <div className='list-editor-view-title'>{title}</div>}
24                          <div className={`list-editor-view-add-controller${isReadOnlyMode ? ' disabled' : ''}`}>
25                                  { onAdd &&
26                                          <div className='list-editor-view-add-title' data-test-id='add-button' onClick={onAdd}>
27                                                  <span>{`+ ${plusButtonTitle}`}</span>
28                                          </div>
29                                  }
30                          </div>
31                  </div>
32          );
33 };
34
35 const ListEditorScroller = ({children, twoColumns}) => {
36         return (
37                 <div className='list-editor-view-list-scroller'>
38                         <div className={classnames('list-editor-view-list', {'two-columns': twoColumns})}>
39                                 {children}
40                         </div>
41                 </div>
42         );
43 };
44
45 const FilterWrapper = ({onFilter, filterValue}) => {
46         return (
47                 <div className='expandble-search-wrapper'>
48                         <ExpandableInput
49                                 onChange={onFilter}
50                                 iconType='search'
51                                 value={filterValue}/>
52                 </div>
53         );
54 };
55
56 class ListEditorView extends React.Component {
57
58         static defaultProps = {
59                 className: '',
60                 twoColumns: false
61         };
62
63         static propTypes = {
64                 title: React.PropTypes.string,
65                 plusButtonTitle: React.PropTypes.string,
66                 children: React.PropTypes.node,
67                 filterValue: React.PropTypes.string,
68                 onFilter: React.PropTypes.func,
69                 className: React.PropTypes.string,
70                 isReadOnlyMode: React.PropTypes.bool,
71                 placeholder: React.PropTypes.string,
72                 twoColumns: React.PropTypes.bool
73         };
74
75         render() {
76                 let {title, plusButtonTitle, onAdd, children, onFilter, className, isReadOnlyMode, twoColumns, filterValue} = this.props;
77                 return (
78                         <div className={classnames('list-editor-view', className)}>
79                                 <ListEditorHeader onAdd={onAdd} isReadOnlyMode={isReadOnlyMode} plusButtonTitle={plusButtonTitle} title={title}/>
80                                 {onFilter && (children.length || filterValue) && <FilterWrapper onFilter={onFilter} filterValue={filterValue}/>}
81                                 <ListEditorScroller children={children} twoColumns={twoColumns}/>
82                         </div>
83                 );
84         }
85
86 }
87 export default ListEditorView;