Add collaboration feature
[sdc.git] / openecomp-ui / src / sdc-app / onboarding / onboard / OnboardView.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 OnboardingCatalogView from './onboardingCatalog/OnboardingCatalogView.jsx';
19 import WorkspaceView from './workspace/WorkspaceView.jsx';
20 import {tabsMapping} from './OnboardConstants.js';
21 import i18n from 'nfvo-utils/i18n/i18n.js';
22 import classnames from 'classnames';
23 import ExpandableInput from 'nfvo-components/input/ExpandableInput.jsx';
24 import objectValues from 'lodash/values.js';
25 import {catalogItemTypes} from './onboardingCatalog/OnboardingCatalogConstants.js';
26 import NotificationsView from 'sdc-app/onboarding/userNotifications/NotificationsView.jsx';
27
28 const OnboardHeaderTabs = ({onTabClick, activeTab}) => (
29         <div className='onboard-header-tabs'>
30                 <div
31                         className={classnames('onboard-header-tab', {'active': activeTab === tabsMapping.WORKSPACE })}
32                         onClick={() => onTabClick(tabsMapping.WORKSPACE)}
33                         data-test-id='onboard-workspace-tab'>
34                         {i18n('WORKSPACE')}
35                 </div>
36                 <div
37                         className={classnames('onboard-header-tab', {'active': activeTab === tabsMapping.CATALOG })}
38                         onClick={() => onTabClick(tabsMapping.CATALOG)}
39                         data-test-id='onboard-onboard-tab'>
40                         {i18n('ONBOARD CATALOG')}
41                 </div>
42         </div>
43 );
44
45 const OnboardHeader = ({onSearch, activeTab, onTabClick, searchValue}) => (
46         <div className='onboard-header'>
47                 <OnboardHeaderTabs activeTab={activeTab} onTabClick={onTabClick} />
48                 <ExpandableInput
49                         onChange={onSearch}
50                         iconType='search'
51                         value={searchValue}/>
52                 <NotificationsView />
53         </div>
54 );
55
56 class OnboardView extends React.Component {
57         static propTypes = {
58                 licenseModelList: PropTypes.array,
59                 softwareProductList: PropTypes.array,
60                 finalizedLicenseModelList: PropTypes.array,
61                 finalizedSoftwareProductList: PropTypes.array,
62                 modalToShow: PropTypes.oneOf(objectValues(catalogItemTypes)),
63                 onSelectLicenseModel: PropTypes.func.isRequired,
64                 onSelectSoftwareProduct: PropTypes.func.isRequired,
65                 onAddLicenseModelClick: PropTypes.func.isRequired,
66                 onAddSoftwareProductClick: PropTypes.func.isRequired,
67                 closeVspOverlay: PropTypes.func.isRequired,
68                 onVspOverlayChange: PropTypes.func.isRequired,
69                 onTabClick: PropTypes.func.isRequired,
70                 onCatalogTabClick: PropTypes.func.isRequired,
71                 onSearch: PropTypes.func.isRequired,
72                 activeTab: PropTypes.number.isRequired,
73                 catalogActiveTab: PropTypes.number.isRequired,
74                 searchValue: PropTypes.string.isRequired,
75                 onMigrate: PropTypes.func.isRequired,
76         };
77         renderViewByTab(activeTab){
78                 switch (activeTab){
79                         case tabsMapping.WORKSPACE:
80                                 return <WorkspaceView {...this.props} />;
81                         case tabsMapping.CATALOG:
82                         default:
83                                 return <OnboardingCatalogView {...this.props} />;
84                 }
85         }
86
87         render() {
88                 let {activeTab, onTabClick, onSearch, searchValue} = this.props;
89                 return (
90                         <div className='catalog-view'>
91                                 <OnboardHeader activeTab={activeTab} onTabClick={onTabClick} searchValue={searchValue} onSearch={value => onSearch(value)}/>
92                                 {this.renderViewByTab(activeTab)}
93                         </div>
94                 );
95         }
96 }
97
98 export default OnboardView;