cecccdd9ad3cf6c6d988d887a7c5470ecbbf1c52
[sdc.git] / openecomp-ui / src / sdc-app / onboarding / onboard / onboardingCatalog / VendorItem.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 {catalogItemTypeClasses} from './OnboardingCatalogConstants.js';
18 import CatalogTile from '../CatalogTile.jsx';
19 import classnames from 'classnames';
20 import VSPOverlay from './VSPOverlay.jsx';
21 import i18n from 'nfvo-utils/i18n/i18n.js';
22 import SVGIcon from 'nfvo-components/icon/SVGIcon.jsx';
23 import OverlayTrigger from 'react-bootstrap/lib/OverlayTrigger.js';
24 import tooltip from './Tooltip.jsx';
25
26
27 class VendorItem extends React.Component {
28
29         static PropTypes = {
30                 softwareProductList: React.PropTypes.array,
31                 vendor: React.PropTypes.object,
32                 onSelectVSP: React.PropTypes.func,
33                 shouldShowOverlay: React.PropTypes.boolm,
34                 onVendorSelect: React.PropTypes.func,
35                 onAddVSP: React.PropTypes.func,
36                 onVSPIconClick: React.PropTypes.func,
37
38         };
39
40         render() {
41                 let {vendor, onSelectVSP, shouldShowOverlay, onVendorSelect, onMigrate} = this.props;
42                 let {softwareProductList = [], vendorName} = vendor;
43                 return (
44                         <CatalogTile
45                                 catalogItemTypeClass={catalogItemTypeClasses.VENDOR}
46                                 onSelect={() =>  onVendorSelect(vendor)}>
47                                 <div className='catalog-tile-top'>
48                                         <div className='catalog-tile-icon vendor-type'>
49                                                 <div className='icon'><SVGIcon name='vendor'/></div>
50                                         </div>
51                                         <OverlayTrigger placement='top' overlay={tooltip(vendorName)}>
52                                                 <div className='catalog-tile-item-name'>{vendorName}</div>
53                                         </OverlayTrigger>       
54                                         <div
55                                                 className={classnames('catalog-tile-vsp-count', {active: shouldShowOverlay}, {clickable: softwareProductList.length})}
56                                                 onClick={(event) => this.handleVspCountClick(event)}
57                                                 data-test-id='catalog-vsp-count'>
58                                                 {i18n(`${softwareProductList.length} VSPs`)}
59                                         </div>
60                                         <div className='catalog-tile-content' onClick={(event) => this.onCreateVspClick(event)} data-test-id='catalog-create-new-vsp-from-vendor'>
61                                                 <div className='create-new-vsp-button'>
62                                                         <SVGIcon name='plus'/>&nbsp;&nbsp;&nbsp;{i18n('Create new VSP')}
63                                                 </div>
64                                         </div>
65                                 </div>
66                                 
67                                 {shouldShowOverlay && softwareProductList.length > 0
68                                 && <VSPOverlay onMigrate={onMigrate} VSPList={softwareProductList} onSelectVSP={onSelectVSP} onSeeMore={() => onVendorSelect(vendor)}/>}
69                         </CatalogTile>
70                 );
71         }
72
73         onClick(vlm) {
74                 this.setState({
75                         licenseModelToShow: vlm
76                 });
77         }
78
79         onCreateVspClick(event) {
80                 let {onAddVSP, vendor: {id}} = this.props;
81                 event.stopPropagation();
82                 event.preventDefault();
83                 onAddVSP(id);
84         }
85
86         handleVspCountClick(e){
87                 let {onVSPIconClick, vendor: {softwareProductList}} = this.props;
88                 e.stopPropagation();
89                 e.preventDefault();
90                 const hasVSP = Boolean(softwareProductList.length);
91                 onVSPIconClick(hasVSP);
92         }
93
94 }
95
96 export default VendorItem;