blob: 0fc64b328cd59379f8835481e062af4f838c2a0f [file] [log] [blame]
svishnev14592282018-02-15 11:00:37 +02001/*
2 * Copyright © 2016-2018 European Support Limited
AviZi280f8012017-06-09 02:39:56 +03003 *
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
svishnev14592282018-02-15 11:00:37 +02007 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
AviZi280f8012017-06-09 02:39:56 +030010 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
svishnev14592282018-02-15 11:00:37 +020012 * 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.
AviZi280f8012017-06-09 02:39:56 +030015 */
16import React from 'react';
talig8e9c0652017-12-20 14:30:43 +020017import PropTypes from 'prop-types';
AviZi280f8012017-06-09 02:39:56 +030018import OnboardingCatalogView from './onboardingCatalog/OnboardingCatalogView.jsx';
svishnevea5e43c2018-04-15 09:06:57 +030019import OnboardingCatalogViewWithFilter from './onboardingCatalog/OnboardingCatalogViewWithFilter.jsx';
AviZi280f8012017-06-09 02:39:56 +030020import WorkspaceView from './workspace/WorkspaceView.jsx';
svishnevea5e43c2018-04-15 09:06:57 +030021import WorkspaceViewWithFilter from './workspace/WorkspaceViewWithFilter.jsx';
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020022import { tabsMapping } from './OnboardConstants.js';
AviZi280f8012017-06-09 02:39:56 +030023import i18n from 'nfvo-utils/i18n/i18n.js';
24import classnames from 'classnames';
25import ExpandableInput from 'nfvo-components/input/ExpandableInput.jsx';
26import objectValues from 'lodash/values.js';
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020027import { catalogItemTypes } from './onboardingCatalog/OnboardingCatalogConstants.js';
talig8e9c0652017-12-20 14:30:43 +020028import NotificationsView from 'sdc-app/onboarding/userNotifications/NotificationsView.jsx';
svishnev14592282018-02-15 11:00:37 +020029import Filter from 'sdc-app/onboarding/onboard/filter/Filter.jsx';
svishnevea5e43c2018-04-15 09:06:57 +030030import featureToggle from 'sdc-app/features/featureToggle.js';
31import { featureToggleNames } from 'sdc-app/features/FeaturesConstants.js';
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020032const 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>
AviZi280f8012017-06-09 02:39:56 +030051);
52
svishnevea5e43c2018-04-15 09:06:57 +030053const ToggledOnboardingCatalogView = featureToggle(featureToggleNames.FILTER)({
54 OnComp: OnboardingCatalogViewWithFilter,
55 OffComp: OnboardingCatalogView
56});
57
58const ToggledWorkspaceView = featureToggle(featureToggleNames.FILTER)({
59 OnComp: WorkspaceViewWithFilter,
60 OffComp: WorkspaceView
61});
62
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020063const 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>
AviZi280f8012017-06-09 02:39:56 +030073);
74
75class OnboardView extends React.Component {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020076 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:
svishnevea5e43c2018-04-15 09:06:57 +0300101 return <ToggledWorkspaceView {...this.props} />;
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200102 case tabsMapping.CATALOG:
svishnevea5e43c2018-04-15 09:06:57 +0300103 return <ToggledOnboardingCatalogView {...this.props} />;
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200104 default:
svishnevea5e43c2018-04-15 09:06:57 +0300105 return <ToggledWorkspaceView {...this.props} />;
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200106 }
107 }
AviZi280f8012017-06-09 02:39:56 +0300108
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200109 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 }
AviZi280f8012017-06-09 02:39:56 +0300126}
127
128export default OnboardView;