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 |
Yarin Dekel | 811fb48 | 2018-11-04 15:00:34 +0200 | [diff] [blame] | 7 | * |
svishnev | 1459228 | 2018-02-15 11:00:37 +0200 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Yarin Dekel | 811fb48 | 2018-11-04 15:00:34 +0200 | [diff] [blame] | 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'; |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 20 | import { tabsMapping } from './OnboardConstants.js'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 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'; |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 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'; |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 28 | const OnboardHeaderTabs = ({ onTabClick, activeTab }) => ( |
| 29 | <div className="onboard-header-tabs"> |
| 30 | <div |
| 31 | className={classnames('onboard-header-tab', { |
| 32 | active: activeTab === tabsMapping.WORKSPACE |
| 33 | })} |
| 34 | onClick={() => onTabClick(tabsMapping.WORKSPACE)} |
| 35 | data-test-id="onboard-workspace-tab"> |
| 36 | {i18n('WORKSPACE')} |
| 37 | </div> |
| 38 | <div |
| 39 | className={classnames('onboard-header-tab', { |
| 40 | active: activeTab === tabsMapping.CATALOG |
| 41 | })} |
| 42 | onClick={() => onTabClick(tabsMapping.CATALOG)} |
| 43 | data-test-id="onboard-onboard-tab"> |
| 44 | {i18n('ONBOARD CATALOG')} |
| 45 | </div> |
| 46 | </div> |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 47 | ); |
| 48 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 49 | const OnboardHeader = ({ onSearch, activeTab, onTabClick, searchValue }) => ( |
| 50 | <div className="onboard-header"> |
| 51 | <OnboardHeaderTabs activeTab={activeTab} onTabClick={onTabClick} /> |
| 52 | <ExpandableInput |
| 53 | onChange={onSearch} |
| 54 | iconType="search" |
| 55 | value={searchValue} |
| 56 | /> |
| 57 | <NotificationsView /> |
| 58 | </div> |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 59 | ); |
| 60 | |
| 61 | class OnboardView extends React.Component { |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 62 | static propTypes = { |
| 63 | licenseModelList: PropTypes.array, |
| 64 | softwareProductList: PropTypes.array, |
| 65 | finalizedLicenseModelList: PropTypes.array, |
| 66 | finalizedSoftwareProductList: PropTypes.array, |
| 67 | archivedSoftwareProductList: PropTypes.array, |
| 68 | archivedLicenseModelList: PropTypes.array, |
| 69 | modalToShow: PropTypes.oneOf(objectValues(catalogItemTypes)), |
| 70 | onSelectLicenseModel: PropTypes.func.isRequired, |
| 71 | onSelectSoftwareProduct: PropTypes.func.isRequired, |
| 72 | onAddLicenseModelClick: PropTypes.func.isRequired, |
| 73 | onAddSoftwareProductClick: PropTypes.func.isRequired, |
| 74 | closeVspOverlay: PropTypes.func.isRequired, |
| 75 | onVspOverlayChange: PropTypes.func.isRequired, |
| 76 | onTabClick: PropTypes.func.isRequired, |
| 77 | onCatalogTabClick: PropTypes.func.isRequired, |
| 78 | onSearch: PropTypes.func.isRequired, |
| 79 | activeTab: PropTypes.number.isRequired, |
| 80 | catalogActiveTab: PropTypes.number.isRequired, |
Yarin Dekel | 811fb48 | 2018-11-04 15:00:34 +0200 | [diff] [blame] | 81 | searchValue: PropTypes.object.isRequired, |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 82 | onMigrate: PropTypes.func.isRequired |
| 83 | }; |
| 84 | renderViewByTab(activeTab) { |
| 85 | switch (activeTab) { |
| 86 | case tabsMapping.WORKSPACE: |
svishnev | 8ae8f7e | 2018-07-02 14:05:17 +0300 | [diff] [blame] | 87 | return <WorkspaceView {...this.props} />; |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 88 | case tabsMapping.CATALOG: |
svishnev | 8ae8f7e | 2018-07-02 14:05:17 +0300 | [diff] [blame] | 89 | return <OnboardingCatalogView {...this.props} />; |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 90 | default: |
svishnev | 8ae8f7e | 2018-07-02 14:05:17 +0300 | [diff] [blame] | 91 | return <WorkspaceView {...this.props} />; |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 92 | } |
| 93 | } |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 94 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 95 | render() { |
Yarin Dekel | 811fb48 | 2018-11-04 15:00:34 +0200 | [diff] [blame] | 96 | let { |
| 97 | activeTab, |
| 98 | activeTabName, |
| 99 | onTabClick, |
| 100 | onSearch, |
| 101 | searchValue |
| 102 | } = this.props; |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 103 | return ( |
| 104 | <div className="catalog-view"> |
| 105 | <Filter /> |
| 106 | <div className="catalog-parts"> |
| 107 | <OnboardHeader |
| 108 | activeTab={activeTab} |
| 109 | onTabClick={onTabClick} |
Yarin Dekel | 811fb48 | 2018-11-04 15:00:34 +0200 | [diff] [blame] | 110 | searchValue={searchValue[activeTabName]} |
| 111 | onSearch={value => onSearch(value, activeTabName)} |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 112 | /> |
| 113 | {this.renderViewByTab(activeTab)} |
| 114 | </div> |
| 115 | </div> |
| 116 | ); |
| 117 | } |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | export default OnboardView; |