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'; |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 19 | import OnboardingCatalogViewWithFilter from './onboardingCatalog/OnboardingCatalogViewWithFilter.jsx'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 20 | import WorkspaceView from './workspace/WorkspaceView.jsx'; |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 21 | import WorkspaceViewWithFilter from './workspace/WorkspaceViewWithFilter.jsx'; |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 22 | import { tabsMapping } from './OnboardConstants.js'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 23 | import i18n from 'nfvo-utils/i18n/i18n.js'; |
| 24 | import classnames from 'classnames'; |
| 25 | import ExpandableInput from 'nfvo-components/input/ExpandableInput.jsx'; |
| 26 | import objectValues from 'lodash/values.js'; |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 27 | import { catalogItemTypes } from './onboardingCatalog/OnboardingCatalogConstants.js'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 28 | import NotificationsView from 'sdc-app/onboarding/userNotifications/NotificationsView.jsx'; |
svishnev | 1459228 | 2018-02-15 11:00:37 +0200 | [diff] [blame] | 29 | import Filter from 'sdc-app/onboarding/onboard/filter/Filter.jsx'; |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 30 | import featureToggle from 'sdc-app/features/featureToggle.js'; |
| 31 | import { featureToggleNames } from 'sdc-app/features/FeaturesConstants.js'; |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 32 | const OnboardHeaderTabs = ({ onTabClick, activeTab }) => ( |
| 33 | <div className="onboard-header-tabs"> |
| 34 | <div |
| 35 | className={classnames('onboard-header-tab', { |
| 36 | active: activeTab === tabsMapping.WORKSPACE |
| 37 | })} |
| 38 | onClick={() => onTabClick(tabsMapping.WORKSPACE)} |
| 39 | data-test-id="onboard-workspace-tab"> |
| 40 | {i18n('WORKSPACE')} |
| 41 | </div> |
| 42 | <div |
| 43 | className={classnames('onboard-header-tab', { |
| 44 | active: activeTab === tabsMapping.CATALOG |
| 45 | })} |
| 46 | onClick={() => onTabClick(tabsMapping.CATALOG)} |
| 47 | data-test-id="onboard-onboard-tab"> |
| 48 | {i18n('ONBOARD CATALOG')} |
| 49 | </div> |
| 50 | </div> |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 51 | ); |
| 52 | |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 53 | const ToggledOnboardingCatalogView = featureToggle(featureToggleNames.FILTER)({ |
| 54 | OnComp: OnboardingCatalogViewWithFilter, |
| 55 | OffComp: OnboardingCatalogView |
| 56 | }); |
| 57 | |
| 58 | const ToggledWorkspaceView = featureToggle(featureToggleNames.FILTER)({ |
| 59 | OnComp: WorkspaceViewWithFilter, |
| 60 | OffComp: WorkspaceView |
| 61 | }); |
| 62 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 63 | const OnboardHeader = ({ onSearch, activeTab, onTabClick, searchValue }) => ( |
| 64 | <div className="onboard-header"> |
| 65 | <OnboardHeaderTabs activeTab={activeTab} onTabClick={onTabClick} /> |
| 66 | <ExpandableInput |
| 67 | onChange={onSearch} |
| 68 | iconType="search" |
| 69 | value={searchValue} |
| 70 | /> |
| 71 | <NotificationsView /> |
| 72 | </div> |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 73 | ); |
| 74 | |
| 75 | class OnboardView extends React.Component { |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 76 | static propTypes = { |
| 77 | licenseModelList: PropTypes.array, |
| 78 | softwareProductList: PropTypes.array, |
| 79 | finalizedLicenseModelList: PropTypes.array, |
| 80 | finalizedSoftwareProductList: PropTypes.array, |
| 81 | archivedSoftwareProductList: PropTypes.array, |
| 82 | archivedLicenseModelList: PropTypes.array, |
| 83 | modalToShow: PropTypes.oneOf(objectValues(catalogItemTypes)), |
| 84 | onSelectLicenseModel: PropTypes.func.isRequired, |
| 85 | onSelectSoftwareProduct: PropTypes.func.isRequired, |
| 86 | onAddLicenseModelClick: PropTypes.func.isRequired, |
| 87 | onAddSoftwareProductClick: PropTypes.func.isRequired, |
| 88 | closeVspOverlay: PropTypes.func.isRequired, |
| 89 | onVspOverlayChange: PropTypes.func.isRequired, |
| 90 | onTabClick: PropTypes.func.isRequired, |
| 91 | onCatalogTabClick: PropTypes.func.isRequired, |
| 92 | onSearch: PropTypes.func.isRequired, |
| 93 | activeTab: PropTypes.number.isRequired, |
| 94 | catalogActiveTab: PropTypes.number.isRequired, |
| 95 | searchValue: PropTypes.string.isRequired, |
| 96 | onMigrate: PropTypes.func.isRequired |
| 97 | }; |
| 98 | renderViewByTab(activeTab) { |
| 99 | switch (activeTab) { |
| 100 | case tabsMapping.WORKSPACE: |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 101 | return <ToggledWorkspaceView {...this.props} />; |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 102 | case tabsMapping.CATALOG: |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 103 | return <ToggledOnboardingCatalogView {...this.props} />; |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 104 | default: |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 105 | return <ToggledWorkspaceView {...this.props} />; |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 106 | } |
| 107 | } |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 108 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 109 | render() { |
| 110 | let { activeTab, onTabClick, onSearch, searchValue } = this.props; |
| 111 | return ( |
| 112 | <div className="catalog-view"> |
| 113 | <Filter /> |
| 114 | <div className="catalog-parts"> |
| 115 | <OnboardHeader |
| 116 | activeTab={activeTab} |
| 117 | onTabClick={onTabClick} |
| 118 | searchValue={searchValue} |
| 119 | onSearch={value => onSearch(value)} |
| 120 | /> |
| 121 | {this.renderViewByTab(activeTab)} |
| 122 | </div> |
| 123 | </div> |
| 124 | ); |
| 125 | } |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | export default OnboardView; |