chache result in onboarding
[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             activeTabName
50         } = this.props;
51
52         const { vlmList, vspList } = filteredItems;
53
54         switch (activeTab) {
55             case tabsMapping.ARCHIVE:
56             case tabsMapping.ACTIVE:
57                 return (
58                     <DetailsCatalogView
59                         VLMList={vlmList}
60                         VSPList={vspList}
61                         users={users}
62                         onAddVLM={!isArchived && onAddLicenseModelClick}
63                         onAddVSP={!isArchived && onAddSoftwareProductClick}
64                         onSelectVLM={(item, users) =>
65                             onSelectLicenseModel(
66                                 item,
67                                 users,
68                                 WCTabsMapping.CATALOG
69                             )
70                         }
71                         onSelectVSP={(item, users) =>
72                             onSelectSoftwareProduct(
73                                 item,
74                                 users,
75                                 WCTabsMapping.CATALOG
76                             )
77                         }
78                         activeTabName={activeTabName}
79                         filter={searchValue}
80                         onMigrate={onMigrate}
81                     />
82                 );
83
84             case tabsMapping.BY_VENDOR:
85             default:
86                 return (
87                     <VendorCatalogView
88                         isArchived={isArchived}
89                         licenseModelList={vlmList}
90                         users={users}
91                         onAddVSP={onAddSoftwareProductClick}
92                         onAddVLM={onAddLicenseModelClick}
93                         onSelectVSP={(item, users) =>
94                             onSelectSoftwareProduct(
95                                 item,
96                                 users,
97                                 WCTabsMapping.CATALOG
98                             )
99                         }
100                         onSelectVLM={(item, users) =>
101                             onSelectLicenseModel(
102                                 item,
103                                 users,
104                                 WCTabsMapping.CATALOG
105                             )
106                         }
107                         vspOverlay={vspOverlay}
108                         onVendorSelect={onVendorSelect}
109                         selectedVendor={selectedVendor}
110                         onVspOverlayChange={onVspOverlayChange}
111                         onMigrate={onMigrate}
112                         activeTabName={activeTabName}
113                         filter={searchValue}
114                     />
115                 );
116         }
117     }
118
119     render() {
120         const { selectedVendor, catalogActiveTab: activeTab } = this.props;
121         return (
122             <div className="catalog-wrapper">
123                 {!selectedVendor && <CatalogHeader />}
124                 {this.renderViewByTab(activeTab)}
125             </div>
126         );
127     }
128 }
129
130 export default OnboardingCatalogView;