blob: 4f66e579d16b309ff29517a717fde313cd22ae1b [file] [log] [blame]
Michael Landoefa037d2017-02-19 12:57:33 +02001import React from 'react';
2import {connect} from 'react-redux';
3import Input from 'react-bootstrap/lib/Input.js';
4
5import LicenseModelActionHelper from './onboarding/licenseModel/LicenseModelActionHelper.js';
6import LicenseAgreementListEditor from './onboarding/licenseModel/licenseAgreement/LicenseAgreementListEditor.js';
7import LicenseAgreementActionHelper from './onboarding/licenseModel/licenseAgreement/LicenseAgreementActionHelper.js';
8import FeatureGroupListEditor from './onboarding/licenseModel/featureGroups/FeatureGroupListEditor.js';
9import FeatureGroupsActionHelper from './onboarding/licenseModel/featureGroups/FeatureGroupsActionHelper.js';
10import LicenseKeyGroupsListEditor from './onboarding/licenseModel/licenseKeyGroups/LicenseKeyGroupsListEditor.js';
11import LicenseKeyGroupsActionHelper from './onboarding/licenseModel/licenseKeyGroups/LicenseKeyGroupsActionHelper.js';
12import EntitlementPoolsListEditor from './onboarding/licenseModel/entitlementPools/EntitlementPoolsListEditor.js';
13import EntitlementPoolsActionHelper from './onboarding/licenseModel/entitlementPools/EntitlementPoolsActionHelper.js';
14import SoftwareProductLandingPage from './onboarding/softwareProduct/landingPage/SoftwareProductLandingPage.js';
15import SoftwareProductDetails from './onboarding/softwareProduct/details/SoftwareProductDetails.js';
16import OnboardingCatalog from './onboarding/OnboardingCatalog.js';
17import SoftwareProductActionHelper from './onboarding/softwareProduct/SoftwareProductActionHelper.js';
18import FlowsListEditor from './flows/FlowsListEditor.js';
19import FlowsActions from './flows/FlowsActions.js';
20
21
22const mapStateToProps = ({licenseModelList}) => {
23 return {licenseModelList};
24};
25
26
27const mapActionsToProps = dispatch => {
28 return {
29 onBootstrapped: () => LicenseModelActionHelper.fetchLicenseModels(dispatch),
30 onLicenseAgreementListEditor: licenseModelId => LicenseAgreementActionHelper.fetchLicenseAgreementList(dispatch, {licenseModelId}),
31 onFeatureGroupsListEditor: licenseModelId => FeatureGroupsActionHelper.fetchFeatureGroupsList(dispatch, {licenseModelId}),
32 onLicenseKeyGroupsListEditor: licenseModelId =>LicenseKeyGroupsActionHelper.fetchLicenseKeyGroupsList(dispatch, {licenseModelId}),
33 onEntitlementPoolsListEditor: licenseModelId => EntitlementPoolsActionHelper.fetchEntitlementPoolsList(dispatch, {licenseModelId}),
34 onOnboardingCatalog: () => SoftwareProductActionHelper.fetchSoftwareProductList(dispatch),
35 onSoftwareProductDetails: () => SoftwareProductActionHelper.fetchSoftwareProductCategories(dispatch),
36 onFlowsListEditor: () => FlowsActions.fetchFlows(dispatch)
37 };
38};
39
40class ModuleOptions extends React.Component {
41
42 static propTypes = {
43 onBootstrapped: React.PropTypes.func.isRequired,
44 onLicenseAgreementListEditor: React.PropTypes.func.isRequired,
45 onFeatureGroupsListEditor: React.PropTypes.func.isRequired,
46 onLicenseKeyGroupsListEditor: React.PropTypes.func.isRequired,
47 onEntitlementPoolsListEditor: React.PropTypes.func.isRequired,
48 onOnboardingCatalog: React.PropTypes.func.isRequired,
49 onSoftwareProductDetails: React.PropTypes.func.isRequired,
50 };
51
52 state = {
53 currentModule: localStorage.getItem('default-module'),
54 licenseModelId: localStorage.getItem('default-license-model-id')
55 };
56
57 componentDidMount() {
58 this.props.onBootstrapped();
59 }
60
61 render() {
62 let {currentModule, licenseModelId} = this.state;
63 let {licenseModelList} = this.props;
64 return (
65 <div style={{marginTop:20}}>
66 <Input
67 name='licenseModel'
68 value={licenseModelId}
69 ref='licenseModelId'
70 type='select'
71 onChange={this.handleLicenseModelIdChange}
72 className='inner-pagination select-input'>
73 <option value='' key={null}>Select License Model</option>
74 {
75 licenseModelList.map(({id, vendorName}) => <option value={id} key={id}>{`${vendorName} License Model`}</option>)
76 }
77 </Input>
78 <Input
79 name='currentView'
80 value={currentModule}
81 ref='selectedModule'
82 type='select'
83 onChange={this.handleModuleSelection}
84 className='inner-pagination select-input'>
85 <option value=''>Select Module</option>
86 <option value='EntitlementPoolsListEditor'>Entitlement Pools</option>
87 <option value='LicenseAgreementListEditor'>License Agreements</option>
88 <option value='FutureGroupListEditor'>Feature Groups</option>
89 <option value='LicenseKeyGroupsListEditor'>License Key Groups</option>
90 <option value='SoftwareProductLanding'>Software Product Landing</option>
91 <option value='SoftwareProductDetails'>Software Product Details</option>
92 <option value='OnboardingCatalog'>Onboarding Catalog</option>
93 <option value='Flows'>Flows</option>
94 </Input>
95 <div className='sub-module-view' style={{paddingTop: 10, margin: 4, borderTop: '1px solid silver'}}>
96 {this.renderModule(currentModule)}
97 </div>
98 </div>
99 );
100 }
101
102 renderModule(currentModule) {
103 const {licenseModelId} = this.state;
104 if (!licenseModelId) {
105 return;
106 }
107
108 switch (currentModule) {
109 case 'LicenseAgreementListEditor':
110 this.props.onLicenseAgreementListEditor(licenseModelId);
111 return <LicenseAgreementListEditor licenseModelId={licenseModelId}/>;
112 case 'FutureGroupListEditor':
113 this.props.onFeatureGroupsListEditor(licenseModelId);
114 return <FeatureGroupListEditor licenseModelId={licenseModelId}/>;
115 case 'EntitlementPoolsListEditor':
116 this.props.onEntitlementPoolsListEditor(licenseModelId);
117 return <EntitlementPoolsListEditor licenseModelId={licenseModelId}/>;
118 case 'LicenseKeyGroupsListEditor':
119 this.props.onLicenseKeyGroupsListEditor(licenseModelId);
120 return <LicenseKeyGroupsListEditor licenseModelId={licenseModelId}/>;
121 case 'SoftwareProductLanding':
122 return <SoftwareProductLandingPage licenseModelId={licenseModelId}/>;
123 case 'SoftwareProductDetails':
124 this.props.onSoftwareProductDetails(licenseModelId);
125 return <SoftwareProductDetails licenseModelId={licenseModelId}/>;
126 case 'OnboardingCatalog':
127 this.props.onOnboardingCatalog();
128 return <OnboardingCatalog/>;
129 case 'Flows':
130 this.props.onFlowsListEditor();
131 return <FlowsListEditor/>;
132 default:
133 return;
134 }
135 }
136
137 handleModuleSelection = () => {
138 let selectedModule = this.refs.selectedModule.getValue();
139 localStorage.setItem('default-module', selectedModule);
140 this.setState({currentModule: selectedModule});
141 }
142
143 handleLicenseModelIdChange = () => {
144 let licenseModelId = this.refs.licenseModelId.getValue();
145 localStorage.setItem('default-license-model-id', licenseModelId);
146 this.setState({licenseModelId});
147 }
148}
149
150export default connect(mapStateToProps, mapActionsToProps)(ModuleOptions);