Add collaboration feature
[sdc.git] / openecomp-ui / src / sdc-app / onboarding / licenseModel / overview / VLMListView.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, {Component} from 'react';
17 import PropTypes from 'prop-types';
18 import {Collapse} from 'react-bootstrap';
19 import LicenseAgreement from './listItems/LicenseAgreement.jsx';
20 import EntitlementPool from './listItems/EntitlementPool.jsx';
21 import FeatureGroup from './listItems/FeatureGroup.jsx';
22 import LicenseKeyGroup from './listItems/LicenseKeyGroup.jsx';
23 import {overviewEditorHeaders} from './LicenseModelOverviewConstants.js';
24
25 class VLMListView extends Component {
26
27         static propTypes = {
28                 licensingDataList: PropTypes.array,
29                 showInUse: PropTypes.bool
30         };
31
32         state = {
33
34         };
35
36         render() {
37                 let {licensingDataList = []} = this.props;
38                 return (
39                         <div className='vlm-list-view'>
40                                 <div>
41                                         <ul className='vlm-list' data-test-id='vlm-list'>
42                                                 {licensingDataList.map(item => this.renderLicensingItem(item))}
43                                         </ul>
44                                 </div>
45                         </div>
46                 );
47         }
48
49         renderLicensingItem(item) {
50                 switch (item.itemType) {
51                         case overviewEditorHeaders.LICENSE_AGREEMENT :
52                                 return this.renderLicenseAgreementItem(item);
53                         case overviewEditorHeaders.FEATURE_GROUP :
54                                 return this.renderFeatureGroupItem(item);
55                         case overviewEditorHeaders.LICENSE_KEY_GROUP :
56                                 return this.renderLicenseKeyGroupItem(item);
57                         case overviewEditorHeaders.ENTITLEMENT_POOL:
58                                 return this.renderEntitlementPoolItem(item);
59                         default:
60                                 return;
61                 }
62         }
63
64         renderLicenseAgreementItem(licenseAgreement) {
65                 return (
66                         <li  key={licenseAgreement.id}>
67                                 <LicenseAgreement
68                                         laData={licenseAgreement}
69                                         isCollapsed={this.state[licenseAgreement.id]}
70                                         onClick={event => this.updateCollapsable(event, licenseAgreement.id) }
71                                         isOrphan={!this.props.showInUse}/>
72                                 <Collapse in={this.state[licenseAgreement.id]}>
73                                         <ul>
74                                                 {licenseAgreement.children && licenseAgreement.children.map(item => this.renderLicensingItem(item))}
75                                         </ul>
76                                 </Collapse>
77                         </li>
78                 );
79         }
80
81         renderFeatureGroupItem(featureGroup) {
82                 const {showInUse} = this.props;
83                 return (
84                         <li key={featureGroup.id}>
85                                 <FeatureGroup
86                                         fgData={featureGroup}
87                                         isCollapsed={this.state[featureGroup.id]}
88                                         onClick={event=> this.updateCollapsable(event, featureGroup.id) }
89                                         isOrphan={!this.props.showInUse}/>
90                                 {
91                                         showInUse && <Collapse in={this.state[featureGroup.id]}>
92                                         <ul>
93                                                 {featureGroup.children && featureGroup.children.map(item => this.renderLicensingItem(item))}
94
95                                         </ul>
96                                 </Collapse>
97                                 }
98                         </li>
99                 );
100         }
101
102         renderEntitlementPoolItem(entitlementPool) {
103                 return (
104                         <li key={entitlementPool.id}>
105                                 <EntitlementPool epData={entitlementPool} isOrphan={!this.props.showInUse}/>
106                         </li>
107                 );
108         }
109
110         renderLicenseKeyGroupItem(licenseKeyGroup) {
111                 return (
112                         <li key={licenseKeyGroup.id}>
113                                 <LicenseKeyGroup lkgData={licenseKeyGroup} isOrphan={!this.props.showInUse}/>
114                         </li>
115                 );
116         }
117
118         updateCollapsable(event, id) {
119                 event.stopPropagation();
120                 let obj = {};
121                 obj[id] = !this.state[id];
122                 this.setState(obj);
123         }
124 }
125
126 export default VLMListView;