Add collaboration feature
[sdc.git] / openecomp-ui / src / nfvo-components / listEditor / ListEditorItemView.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 classnames from 'classnames';
19 import i18n from 'nfvo-utils/i18n/i18n.js';
20 import SVGIcon from 'sdc-ui/lib/react/SVGIcon.js';
21 import store from 'sdc-app/AppStore.js';
22 import {actionTypes as modalActionTypes} from 'nfvo-components/modal/GlobalModalConstants.js';
23
24 class ListEditorItem extends React.Component {
25         static propTypes = {
26                 onSelect:  PropTypes.oneOfType([PropTypes.func, PropTypes.bool]),
27                 onDelete:  PropTypes.oneOfType([PropTypes.func, PropTypes.bool]),
28                 onEdit:  PropTypes.oneOfType([PropTypes.func, PropTypes.bool]),
29                 children: PropTypes.node,
30                 isReadOnlyMode: PropTypes.bool
31         };
32
33         render() {
34                 let {onDelete, onSelect, onEdit, children, isReadOnlyMode} = this.props;
35                 let isAbilityToDelete = isReadOnlyMode === undefined ? true : !isReadOnlyMode;
36                 return (
37                         <div className={classnames('list-editor-item-view', {'selectable': Boolean(onSelect)})} data-test-id='list-editor-item'>
38                                 <div className='list-editor-item-view-content' onClick={onSelect}>
39                                         {children}
40                                 </div>
41                                 {(onEdit || onDelete) && <div className='list-editor-item-view-controller'>
42                                         {onEdit && <SVGIcon name='sliders' onClick={() => this.onClickedItem(onEdit)}/>}
43                                         {onDelete && isAbilityToDelete && <SVGIcon name='trashO' data-test-id='delete-list-item' onClick={() => this.onClickedItem(onDelete)}/>}
44                                 </div>}
45                         </div>
46                 );
47         }
48
49         onClickedItem(callBackFunc) {
50                 if(typeof callBackFunc === 'function') {
51                         let {isCheckedOut} = this.props;
52                         if (isCheckedOut === false) {
53                                 store.dispatch({
54                                         type: modalActionTypes.GLOBAL_MODAL_WARNING,
55                                         data: {
56                                                 title: i18n('Error'),
57                                                 msg: i18n('This item is checkedin/submitted, Click Check Out to continue')
58                                         }
59                                 });
60                         }
61                         else {
62                                 callBackFunc();
63                         }
64                 }
65         }
66 }
67
68 export default ListEditorItem;