ec3d4550ef508bfb9a7a24cd1434a866845008b4
[sdc.git] / openecomp-ui / src / sdc-app / onboarding / onboard / onboardingCatalog / OnboardingCatalogView.jsx
1 /*
2  * Copyright © 2016-2018 European Support Limited
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 or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 import React from 'react';
17 import i18n from 'nfvo-utils/i18n/i18n.js';
18 import DetailsCatalogView from 'sdc-app/onboarding/onboard/DetailsCatalogView.jsx';
19 import VendorCatalogView from './VendorCatalogView.jsx';
20 import { tabsMapping } from './OnboardingCatalogConstants.js';
21 import { tabsMapping as WCTabsMapping } from 'sdc-app/onboarding/onboard/OnboardConstants.js';
22
23 const CatalogHeader = () => (
24     <div className="catalog-header">
25         <div className="catalog-header-tabs">
26             <div className="catalog-header-tab active">
27                 {i18n('ONBOARD CATALOG')}
28             </div>
29         </div>
30     </div>
31 );
32
33 class OnboardingCatalogView extends React.Component {
34     renderViewByTab(activeTab) {
35         const {
36             users,
37             vspOverlay,
38             onSelectLicenseModel,
39             onSelectSoftwareProduct,
40             onAddLicenseModelClick,
41             onAddSoftwareProductClick,
42             onVspOverlayChange,
43             onVendorSelect,
44             selectedVendor,
45             searchValue,
46             onMigrate,
47             filteredItems,
48             isArchived
49         } = this.props;
50
51         const { vlmList, vspList } = filteredItems;
52
53         switch (activeTab) {
54             case tabsMapping.ARCHIVE:
55             case tabsMapping.ACTIVE:
56                 return (
57                     <DetailsCatalogView
58                         VLMList={vlmList}
59                         VSPList={vspList}
60                         users={users}
61                         onAddVLM={!isArchived && onAddLicenseModelClick}
62                         onAddVSP={!isArchived && onAddSoftwareProductClick}
63                         onSelectVLM={(item, users) =>
64                             onSelectLicenseModel(
65                                 item,
66                                 users,
67                                 WCTabsMapping.CATALOG
68                             )
69                         }
70                         onSelectVSP={(item, users) =>
71                             onSelectSoftwareProduct(
72                                 item,
73                                 users,
74                                 WCTabsMapping.CATALOG
75                             )
76                         }
77                         filter={searchValue}
78                         onMigrate={onMigrate}
79                     />
80                 );
81
82             case tabsMapping.BY_VENDOR:
83             default:
84                 return (
85                     <VendorCatalogView
86                         isArchived={isArchived}
87                         licenseModelList={vlmList}
88                         users={users}
89                         onAddVSP={onAddSoftwareProductClick}
90                         onAddVLM={onAddLicenseModelClick}
91                         onSelectVSP={(item, users) =>
92                             onSelectSoftwareProduct(
93                                 item,
94                                 users,
95                                 WCTabsMapping.CATALOG
96                             )
97                         }
98                         onSelectVLM={(item, users) =>
99                             onSelectLicenseModel(
100                                 item,
101                                 users,
102                                 WCTabsMapping.CATALOG
103                             )
104                         }
105                         vspOverlay={vspOverlay}
106                         onVendorSelect={onVendorSelect}
107                         selectedVendor={selectedVendor}
108                         onVspOverlayChange={onVspOverlayChange}
109                         onMigrate={onMigrate}
110                         filter={searchValue}
111                     />
112                 );
113         }
114     }
115
116     render() {
117         const { selectedVendor, catalogActiveTab: activeTab } = this.props;
118         return (
119             <div className="catalog-wrapper">
120                 {!selectedVendor && <CatalogHeader />}
121                 {this.renderViewByTab(activeTab)}
122             </div>
123         );
124     }
125 }
126
127 export default OnboardingCatalogView;