blob: 28fab80da941c2df619cd961524b8d1e132dc47c [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';
Michael Landoefa037d2017-02-19 12:57:33 +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';
30import 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
37
38const mapStateToProps = ({licenseModelList}) => {
39 return {licenseModelList};
40};
41
42
43const mapActionsToProps = dispatch => {
44 return {
45 onBootstrapped: () => LicenseModelActionHelper.fetchLicenseModels(dispatch),
46 onLicenseAgreementListEditor: licenseModelId => LicenseAgreementActionHelper.fetchLicenseAgreementList(dispatch, {licenseModelId}),
47 onFeatureGroupsListEditor: licenseModelId => FeatureGroupsActionHelper.fetchFeatureGroupsList(dispatch, {licenseModelId}),
48 onLicenseKeyGroupsListEditor: licenseModelId =>LicenseKeyGroupsActionHelper.fetchLicenseKeyGroupsList(dispatch, {licenseModelId}),
49 onEntitlementPoolsListEditor: licenseModelId => EntitlementPoolsActionHelper.fetchEntitlementPoolsList(dispatch, {licenseModelId}),
50 onOnboardingCatalog: () => SoftwareProductActionHelper.fetchSoftwareProductList(dispatch),
51 onSoftwareProductDetails: () => SoftwareProductActionHelper.fetchSoftwareProductCategories(dispatch),
52 onFlowsListEditor: () => FlowsActions.fetchFlows(dispatch)
53 };
54};
55
56class ModuleOptions extends React.Component {
57
58 static propTypes = {
talig8e9c0652017-12-20 14:30:43 +020059 onBootstrapped: PropTypes.func.isRequired,
60 onLicenseAgreementListEditor: PropTypes.func.isRequired,
61 onFeatureGroupsListEditor: PropTypes.func.isRequired,
62 onLicenseKeyGroupsListEditor: PropTypes.func.isRequired,
63 onEntitlementPoolsListEditor: PropTypes.func.isRequired,
64 onOnboardingCatalog: PropTypes.func.isRequired,
65 onSoftwareProductDetails: PropTypes.func.isRequired,
Michael Landoefa037d2017-02-19 12:57:33 +020066 };
67
68 state = {
69 currentModule: localStorage.getItem('default-module'),
70 licenseModelId: localStorage.getItem('default-license-model-id')
71 };
72
73 componentDidMount() {
74 this.props.onBootstrapped();
75 }
76
77 render() {
78 let {currentModule, licenseModelId} = this.state;
79 let {licenseModelList} = this.props;
80 return (
81 <div style={{marginTop:20}}>
82 <Input
83 name='licenseModel'
84 value={licenseModelId}
85 ref='licenseModelId'
86 type='select'
87 onChange={this.handleLicenseModelIdChange}
88 className='inner-pagination select-input'>
89 <option value='' key={null}>Select License Model</option>
90 {
91 licenseModelList.map(({id, vendorName}) => <option value={id} key={id}>{`${vendorName} License Model`}</option>)
92 }
93 </Input>
94 <Input
95 name='currentView'
96 value={currentModule}
97 ref='selectedModule'
98 type='select'
99 onChange={this.handleModuleSelection}
100 className='inner-pagination select-input'>
101 <option value=''>Select Module</option>
102 <option value='EntitlementPoolsListEditor'>Entitlement Pools</option>
103 <option value='LicenseAgreementListEditor'>License Agreements</option>
104 <option value='FutureGroupListEditor'>Feature Groups</option>
105 <option value='LicenseKeyGroupsListEditor'>License Key Groups</option>
106 <option value='SoftwareProductLanding'>Software Product Landing</option>
107 <option value='SoftwareProductDetails'>Software Product Details</option>
108 <option value='OnboardingCatalog'>Onboarding Catalog</option>
109 <option value='Flows'>Flows</option>
110 </Input>
111 <div className='sub-module-view' style={{paddingTop: 10, margin: 4, borderTop: '1px solid silver'}}>
112 {this.renderModule(currentModule)}
113 </div>
114 </div>
115 );
116 }
117
118 renderModule(currentModule) {
119 const {licenseModelId} = this.state;
120 if (!licenseModelId) {
121 return;
122 }
123
124 switch (currentModule) {
125 case 'LicenseAgreementListEditor':
126 this.props.onLicenseAgreementListEditor(licenseModelId);
127 return <LicenseAgreementListEditor licenseModelId={licenseModelId}/>;
128 case 'FutureGroupListEditor':
129 this.props.onFeatureGroupsListEditor(licenseModelId);
130 return <FeatureGroupListEditor licenseModelId={licenseModelId}/>;
131 case 'EntitlementPoolsListEditor':
132 this.props.onEntitlementPoolsListEditor(licenseModelId);
133 return <EntitlementPoolsListEditor licenseModelId={licenseModelId}/>;
134 case 'LicenseKeyGroupsListEditor':
135 this.props.onLicenseKeyGroupsListEditor(licenseModelId);
136 return <LicenseKeyGroupsListEditor licenseModelId={licenseModelId}/>;
137 case 'SoftwareProductLanding':
138 return <SoftwareProductLandingPage licenseModelId={licenseModelId}/>;
139 case 'SoftwareProductDetails':
140 this.props.onSoftwareProductDetails(licenseModelId);
141 return <SoftwareProductDetails licenseModelId={licenseModelId}/>;
142 case 'OnboardingCatalog':
143 this.props.onOnboardingCatalog();
AviZi280f8012017-06-09 02:39:56 +0300144 return <Onboard/>;
Michael Landoefa037d2017-02-19 12:57:33 +0200145 case 'Flows':
146 this.props.onFlowsListEditor();
147 return <FlowsListEditor/>;
148 default:
149 return;
150 }
151 }
152
153 handleModuleSelection = () => {
154 let selectedModule = this.refs.selectedModule.getValue();
155 localStorage.setItem('default-module', selectedModule);
156 this.setState({currentModule: selectedModule});
157 }
158
159 handleLicenseModelIdChange = () => {
160 let licenseModelId = this.refs.licenseModelId.getValue();
161 localStorage.setItem('default-license-model-id', licenseModelId);
162 this.setState({licenseModelId});
163 }
164}
165
166export default connect(mapStateToProps, mapActionsToProps)(ModuleOptions);