svishnev | 1459228 | 2018-02-15 11:00:37 +0200 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright © 2016-2018 European Support Limited |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 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 |
svishnev | 1459228 | 2018-02-15 11:00:37 +0200 | [diff] [blame^] | 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
svishnev | 1459228 | 2018-02-15 11:00:37 +0200 | [diff] [blame^] | 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. |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 15 | */ |
| 16 | import React from 'react'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 17 | import PropTypes from 'prop-types'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 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'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 26 | import NotificationsView from 'sdc-app/onboarding/userNotifications/NotificationsView.jsx'; |
svishnev | 1459228 | 2018-02-15 11:00:37 +0200 | [diff] [blame^] | 27 | import Filter from 'sdc-app/onboarding/onboard/filter/Filter.jsx'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 28 | |
| 29 | const OnboardHeaderTabs = ({onTabClick, activeTab}) => ( |
| 30 | <div className='onboard-header-tabs'> |
| 31 | <div |
| 32 | className={classnames('onboard-header-tab', {'active': activeTab === tabsMapping.WORKSPACE })} |
| 33 | onClick={() => onTabClick(tabsMapping.WORKSPACE)} |
| 34 | data-test-id='onboard-workspace-tab'> |
| 35 | {i18n('WORKSPACE')} |
| 36 | </div> |
| 37 | <div |
| 38 | className={classnames('onboard-header-tab', {'active': activeTab === tabsMapping.CATALOG })} |
| 39 | onClick={() => onTabClick(tabsMapping.CATALOG)} |
| 40 | data-test-id='onboard-onboard-tab'> |
| 41 | {i18n('ONBOARD CATALOG')} |
| 42 | </div> |
| 43 | </div> |
| 44 | ); |
| 45 | |
| 46 | const OnboardHeader = ({onSearch, activeTab, onTabClick, searchValue}) => ( |
| 47 | <div className='onboard-header'> |
| 48 | <OnboardHeaderTabs activeTab={activeTab} onTabClick={onTabClick} /> |
| 49 | <ExpandableInput |
| 50 | onChange={onSearch} |
| 51 | iconType='search' |
| 52 | value={searchValue}/> |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 53 | <NotificationsView /> |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 54 | </div> |
| 55 | ); |
| 56 | |
| 57 | class OnboardView extends React.Component { |
| 58 | static propTypes = { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 59 | licenseModelList: PropTypes.array, |
| 60 | softwareProductList: PropTypes.array, |
| 61 | finalizedLicenseModelList: PropTypes.array, |
| 62 | finalizedSoftwareProductList: PropTypes.array, |
| 63 | modalToShow: PropTypes.oneOf(objectValues(catalogItemTypes)), |
| 64 | onSelectLicenseModel: PropTypes.func.isRequired, |
| 65 | onSelectSoftwareProduct: PropTypes.func.isRequired, |
| 66 | onAddLicenseModelClick: PropTypes.func.isRequired, |
| 67 | onAddSoftwareProductClick: PropTypes.func.isRequired, |
| 68 | closeVspOverlay: PropTypes.func.isRequired, |
| 69 | onVspOverlayChange: PropTypes.func.isRequired, |
| 70 | onTabClick: PropTypes.func.isRequired, |
| 71 | onCatalogTabClick: PropTypes.func.isRequired, |
| 72 | onSearch: PropTypes.func.isRequired, |
| 73 | activeTab: PropTypes.number.isRequired, |
| 74 | catalogActiveTab: PropTypes.number.isRequired, |
| 75 | searchValue: PropTypes.string.isRequired, |
| 76 | onMigrate: PropTypes.func.isRequired, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 77 | }; |
| 78 | renderViewByTab(activeTab){ |
| 79 | switch (activeTab){ |
| 80 | case tabsMapping.WORKSPACE: |
| 81 | return <WorkspaceView {...this.props} />; |
| 82 | case tabsMapping.CATALOG: |
| 83 | default: |
| 84 | return <OnboardingCatalogView {...this.props} />; |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | render() { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 89 | let {activeTab, onTabClick, onSearch, searchValue} = this.props; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 90 | return ( |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 91 | <div className='catalog-view'> |
svishnev | 1459228 | 2018-02-15 11:00:37 +0200 | [diff] [blame^] | 92 | <Filter/> |
| 93 | <div className='catalog-parts'> |
| 94 | <OnboardHeader activeTab={activeTab} onTabClick={onTabClick} searchValue={searchValue} onSearch={value => onSearch(value)}/> |
| 95 | {this.renderViewByTab(activeTab)} |
| 96 | </div> |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 97 | </div> |
| 98 | ); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | export default OnboardView; |