Add collaboration feature
[sdc.git] / openecomp-ui / src / sdc-app / onboarding / onboard / CatalogItemDetails.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 i18n from 'nfvo-utils/i18n/i18n.js';
19 import {catalogItemTypes, migrationStatusMapper} from './onboardingCatalog/OnboardingCatalogConstants.js';
20 import {Tile, TileInfo, TileInfoLine} from 'sdc-ui/lib/react';
21 import {TooltipWrapper} from './onboardingCatalog/Tooltip.jsx';
22
23 const ITEM_TYPE_MAP = {
24         [catalogItemTypes.LICENSE_MODEL]: {
25                 headerText: i18n('VLM'),
26                 contentIconName: 'vlm',
27                 color: 'purple'
28         },
29         [catalogItemTypes.SOFTWARE_PRODUCT]: {
30                 headerText: i18n('VSP'),
31                 contentIconName: 'vsp',
32                 color: 'blue'
33         }
34 };
35
36 const CatalogItemDetails = ({catalogItemData, catalogItemTypeClass, onSelect, onMigrate}) => {
37
38         let {vendorName, name} = catalogItemData;
39         let {headerText, color, contentIconName} = ITEM_TYPE_MAP[catalogItemTypeClass];
40
41         let onClick = (e) => {
42                 e.stopPropagation();
43                 e.preventDefault();
44                 if (catalogItemData.isOldVersion && catalogItemData.isOldVersion === migrationStatusMapper.OLD_VERSION) {
45                         onMigrate({softwareProduct: catalogItemData});
46                 } else {
47                         onSelect();
48                 }
49         };
50
51         return (
52                 <Tile
53                         headerText={headerText}
54                         headerColor={color}
55                         iconName={contentIconName}
56                         iconColor={color}
57                         onClick={onClick}
58                         dataTestId={catalogItemTypeClass}>
59                         <TileInfo data-test-id='catalog-item-content'>
60                                 {vendorName &&
61                                         <TileInfoLine type='supertitle'>
62                                                 <TooltipWrapper className='with-overlay' tooltipClassName='tile-super-info' dataTestId='catalog-item-vendor-name'>{vendorName}</TooltipWrapper>
63                                         </TileInfoLine>
64                                 }
65                                 <TileInfoLine type='title'>
66                                         <TooltipWrapper className='with-overlay' tooltipClassName='tile-title-info' dataTestId='catalog-item-name'>{name}</TooltipWrapper>
67                                 </TileInfoLine>
68                         </TileInfo>
69                 </Tile>
70         );
71
72 };
73
74 CatalogItemDetails.PropTypes = {
75         catalogItemData: PropTypes.obj,
76         catalogItemTypeClass: PropTypes.string,
77         onSelect: PropTypes.func,
78         onMigrate: PropTypes.func
79 };
80
81 export default CatalogItemDetails;