blob: 63296b57c903e9e05ab39445fbccc1f3c3e075a2 [file] [log] [blame]
AviZi280f8012017-06-09 02:39:56 +03001/*!
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 */
Michael Landoefa037d2017-02-19 12:57:33 +020016import React from 'react';
talig8e9c0652017-12-20 14:30:43 +020017import PropTypes from 'prop-types';
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020018import { connect } from 'react-redux';
AviZi280f8012017-06-09 02:39:56 +030019import Input from 'nfvo-components/input/validation/InputWrapper.jsx';
Michael Landoefa037d2017-02-19 12:57:33 +020020
21import LicenseModelActionHelper from './onboarding/licenseModel/LicenseModelActionHelper.js';
22import LicenseAgreementListEditor from './onboarding/licenseModel/licenseAgreement/LicenseAgreementListEditor.js';
23import LicenseAgreementActionHelper from './onboarding/licenseModel/licenseAgreement/LicenseAgreementActionHelper.js';
24import FeatureGroupListEditor from './onboarding/licenseModel/featureGroups/FeatureGroupListEditor.js';
25import FeatureGroupsActionHelper from './onboarding/licenseModel/featureGroups/FeatureGroupsActionHelper.js';
26import LicenseKeyGroupsListEditor from './onboarding/licenseModel/licenseKeyGroups/LicenseKeyGroupsListEditor.js';
27import LicenseKeyGroupsActionHelper from './onboarding/licenseModel/licenseKeyGroups/LicenseKeyGroupsActionHelper.js';
28import EntitlementPoolsListEditor from './onboarding/licenseModel/entitlementPools/EntitlementPoolsListEditor.js';
29import EntitlementPoolsActionHelper from './onboarding/licenseModel/entitlementPools/EntitlementPoolsActionHelper.js';
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020030import SoftwareProductLandingPage from './onboarding/softwareProduct/landingPage/SoftwareProductLandingPage.js';
31import SoftwareProductDetails from './onboarding/softwareProduct/details/SoftwareProductDetails.js';
AviZi280f8012017-06-09 02:39:56 +030032import Onboard from './onboarding/onboard/Onboard.js';
Michael Landoefa037d2017-02-19 12:57:33 +020033import SoftwareProductActionHelper from './onboarding/softwareProduct/SoftwareProductActionHelper.js';
34import FlowsListEditor from './flows/FlowsListEditor.js';
35import FlowsActions from './flows/FlowsActions.js';
36
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020037const mapStateToProps = ({ licenseModelList }) => {
38 return { licenseModelList };
Michael Landoefa037d2017-02-19 12:57:33 +020039};
40
Michael Landoefa037d2017-02-19 12:57:33 +020041const mapActionsToProps = dispatch => {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020042 return {
43 onBootstrapped: () =>
44 LicenseModelActionHelper.fetchLicenseModels(dispatch),
45 onLicenseAgreementListEditor: licenseModelId =>
46 LicenseAgreementActionHelper.fetchLicenseAgreementList(dispatch, {
47 licenseModelId
48 }),
49 onFeatureGroupsListEditor: licenseModelId =>
50 FeatureGroupsActionHelper.fetchFeatureGroupsList(dispatch, {
51 licenseModelId
52 }),
53 onLicenseKeyGroupsListEditor: licenseModelId =>
54 LicenseKeyGroupsActionHelper.fetchLicenseKeyGroupsList(dispatch, {
55 licenseModelId
56 }),
57 onEntitlementPoolsListEditor: licenseModelId =>
58 EntitlementPoolsActionHelper.fetchEntitlementPoolsList(dispatch, {
59 licenseModelId
60 }),
61 onOnboardingCatalog: () =>
62 SoftwareProductActionHelper.fetchSoftwareProductList(dispatch),
63 onSoftwareProductDetails: () =>
64 SoftwareProductActionHelper.fetchSoftwareProductCategories(
65 dispatch
66 ),
67 onFlowsListEditor: () => FlowsActions.fetchFlows(dispatch)
68 };
Michael Landoefa037d2017-02-19 12:57:33 +020069};
70
71class ModuleOptions extends React.Component {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020072 static propTypes = {
73 onBootstrapped: PropTypes.func.isRequired,
74 onLicenseAgreementListEditor: PropTypes.func.isRequired,
75 onFeatureGroupsListEditor: PropTypes.func.isRequired,
76 onLicenseKeyGroupsListEditor: PropTypes.func.isRequired,
77 onEntitlementPoolsListEditor: PropTypes.func.isRequired,
78 onOnboardingCatalog: PropTypes.func.isRequired,
79 onSoftwareProductDetails: PropTypes.func.isRequired
80 };
Michael Landoefa037d2017-02-19 12:57:33 +020081
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020082 state = {
83 currentModule: localStorage.getItem('default-module'),
84 licenseModelId: localStorage.getItem('default-license-model-id')
85 };
Michael Landoefa037d2017-02-19 12:57:33 +020086
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020087 componentDidMount() {
88 this.props.onBootstrapped();
89 }
Michael Landoefa037d2017-02-19 12:57:33 +020090
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020091 render() {
92 let { currentModule, licenseModelId } = this.state;
93 let { licenseModelList } = this.props;
94 return (
95 <div style={{ marginTop: 20 }}>
96 <Input
97 name="licenseModel"
98 value={licenseModelId}
99 ref="licenseModelId"
100 type="select"
101 onChange={this.handleLicenseModelIdChange}
102 className="inner-pagination select-input">
103 <option value="" key={null}>
104 Select License Model
105 </option>
106 {licenseModelList.map(({ id, vendorName }) => (
107 <option
108 value={id}
109 key={id}>{`${vendorName} License Model`}</option>
110 ))}
111 </Input>
112 <Input
113 name="currentView"
114 value={currentModule}
115 ref="selectedModule"
116 type="select"
117 onChange={this.handleModuleSelection}
118 className="inner-pagination select-input">
119 <option value="">Select Module</option>
120 <option value="EntitlementPoolsListEditor">
121 Entitlement Pools
122 </option>
123 <option value="LicenseAgreementListEditor">
124 License Agreements
125 </option>
126 <option value="FutureGroupListEditor">
127 Feature Groups
128 </option>
129 <option value="LicenseKeyGroupsListEditor">
130 License Key Groups
131 </option>
132 <option value="SoftwareProductLanding">
133 Software Product Landing
134 </option>
135 <option value="SoftwareProductDetails">
136 Software Product Details
137 </option>
138 <option value="OnboardingCatalog">
139 Onboarding Catalog
140 </option>
141 <option value="Flows">Flows</option>
142 </Input>
143 <div
144 className="sub-module-view"
145 style={{
146 paddingTop: 10,
147 margin: 4,
148 borderTop: '1px solid silver'
149 }}>
150 {this.renderModule(currentModule)}
151 </div>
152 </div>
153 );
154 }
Michael Landoefa037d2017-02-19 12:57:33 +0200155
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200156 renderModule(currentModule) {
157 const { licenseModelId } = this.state;
158 if (!licenseModelId) {
159 return;
160 }
Michael Landoefa037d2017-02-19 12:57:33 +0200161
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200162 switch (currentModule) {
163 case 'LicenseAgreementListEditor':
164 this.props.onLicenseAgreementListEditor(licenseModelId);
165 return (
166 <LicenseAgreementListEditor
167 licenseModelId={licenseModelId}
168 />
169 );
170 case 'FutureGroupListEditor':
171 this.props.onFeatureGroupsListEditor(licenseModelId);
172 return (
173 <FeatureGroupListEditor licenseModelId={licenseModelId} />
174 );
175 case 'EntitlementPoolsListEditor':
176 this.props.onEntitlementPoolsListEditor(licenseModelId);
177 return (
178 <EntitlementPoolsListEditor
179 licenseModelId={licenseModelId}
180 />
181 );
182 case 'LicenseKeyGroupsListEditor':
183 this.props.onLicenseKeyGroupsListEditor(licenseModelId);
184 return (
185 <LicenseKeyGroupsListEditor
186 licenseModelId={licenseModelId}
187 />
188 );
189 case 'SoftwareProductLanding':
190 return (
191 <SoftwareProductLandingPage
192 licenseModelId={licenseModelId}
193 />
194 );
195 case 'SoftwareProductDetails':
196 this.props.onSoftwareProductDetails(licenseModelId);
197 return (
198 <SoftwareProductDetails licenseModelId={licenseModelId} />
199 );
200 case 'OnboardingCatalog':
201 this.props.onOnboardingCatalog();
202 return <Onboard />;
203 case 'Flows':
204 this.props.onFlowsListEditor();
205 return <FlowsListEditor />;
206 default:
207 return;
208 }
209 }
Michael Landoefa037d2017-02-19 12:57:33 +0200210
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200211 handleModuleSelection = () => {
212 let selectedModule = this.refs.selectedModule.getValue();
213 localStorage.setItem('default-module', selectedModule);
214 this.setState({ currentModule: selectedModule });
215 };
Michael Landoefa037d2017-02-19 12:57:33 +0200216
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200217 handleLicenseModelIdChange = () => {
218 let licenseModelId = this.refs.licenseModelId.getValue();
219 localStorage.setItem('default-license-model-id', licenseModelId);
220 this.setState({ licenseModelId });
221 };
Michael Landoefa037d2017-02-19 12:57:33 +0200222}
223
224export default connect(mapStateToProps, mapActionsToProps)(ModuleOptions);