03cba838890f48d76a176f221bc8361f62cba252
[aai/sparky-fe.git] / src / generic-components / componentManager / ComponentManagerContainer.jsx
1 /*
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017-2018 Amdocs
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21 import React, {Component, PropTypes} from 'react';
22 import ButtonGroup from 'react-bootstrap/lib/ButtonGroup';
23 import Button from 'react-bootstrap/lib/Button';
24
25 import i18n from 'utils/i18n/i18n';
26
27 const ICON_CLASS_CLOSE = 'fa fa-times';
28
29 export default class ComponentManagerContainer extends Component {
30
31   static propType = {
32     id: PropTypes.string,
33     title: PropTypes.string,
34     actions: PropTypes.array,
35     showHeader: PropTypes.bool,
36     showTitle: PropTypes.bool,
37     showBorder: PropTypes.bool,
38   };
39
40   static defaultProps = {
41     id: '',
42     title: 'Some Title',
43     actions: [],
44     showHeader: true,
45     showTitle: true,
46     showBorder: true
47   };
48
49   constructor(props) {
50     super(props);
51   }
52
53   render() {
54     let {
55           title,
56           actions,
57           children,
58           showHeader,
59           showTitle,
60           showBorder
61         } = this.props;
62     let buttons = [];
63     actions.forEach((action) => {
64       switch (action.type) {
65         case 'close':
66           buttons.push(
67             <Button
68               type='submit'
69               key={action.type}
70               className='close-button'
71               onClick={ () => {
72                 action.callback(action.id);
73               }}>
74               <i className={ICON_CLASS_CLOSE} aria-hidden='true'></i>
75             </Button>
76           );
77           break;
78         case 'custom':
79           buttons.push(
80             <Button
81               type='submit'
82               key={action.type}
83               className='custom-button'
84               onClick={action.callback}>
85               <i className={'fa ' + action.icon} aria-hidden='true'></i>
86             </Button>
87           );
88           break;
89       }
90     });
91
92     let containerClass = showBorder
93       ? 'titled-container titled-container-boarders'
94       : 'titled-container';
95     let headerClass = showHeader ? 'titled-container-header' : 'hidden';
96     let titleClass = showTitle ? '' : 'hidden';
97
98     return (
99       <div className={containerClass}>
100         <ButtonGroup>{buttons}</ButtonGroup>
101         <div className={headerClass}>
102           <span className={titleClass}>{i18n(title)}</span>
103         </div>
104         <div className='contents'>
105           {children}
106         </div>
107       </div>
108     );
109   }
110 }