Add collaboration feature
[sdc.git] / openecomp-ui / src / sdc-app / ModulesOptions.jsx
1 /*!
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  */
16 import React from 'react';
17 import PropTypes from 'prop-types';
18 import {connect} from 'react-redux';
19 import Input from 'nfvo-components/input/validation/InputWrapper.jsx';
20
21 import LicenseModelActionHelper from './onboarding/licenseModel/LicenseModelActionHelper.js';
22 import LicenseAgreementListEditor from './onboarding/licenseModel/licenseAgreement/LicenseAgreementListEditor.js';
23 import LicenseAgreementActionHelper from './onboarding/licenseModel/licenseAgreement/LicenseAgreementActionHelper.js';
24 import FeatureGroupListEditor from './onboarding/licenseModel/featureGroups/FeatureGroupListEditor.js';
25 import FeatureGroupsActionHelper from './onboarding/licenseModel/featureGroups/FeatureGroupsActionHelper.js';
26 import LicenseKeyGroupsListEditor from './onboarding/licenseModel/licenseKeyGroups/LicenseKeyGroupsListEditor.js';
27 import LicenseKeyGroupsActionHelper from './onboarding/licenseModel/licenseKeyGroups/LicenseKeyGroupsActionHelper.js';
28 import EntitlementPoolsListEditor from './onboarding/licenseModel/entitlementPools/EntitlementPoolsListEditor.js';
29 import EntitlementPoolsActionHelper from './onboarding/licenseModel/entitlementPools/EntitlementPoolsActionHelper.js';
30 import SoftwareProductLandingPage  from './onboarding/softwareProduct/landingPage/SoftwareProductLandingPage.js';
31 import SoftwareProductDetails  from './onboarding/softwareProduct/details/SoftwareProductDetails.js';
32 import Onboard from './onboarding/onboard/Onboard.js';
33 import SoftwareProductActionHelper from './onboarding/softwareProduct/SoftwareProductActionHelper.js';
34 import FlowsListEditor from './flows/FlowsListEditor.js';
35 import FlowsActions from './flows/FlowsActions.js';
36
37
38 const mapStateToProps = ({licenseModelList}) => {
39         return {licenseModelList};
40 };
41
42
43 const 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
56 class ModuleOptions extends React.Component {
57
58         static propTypes = {
59                 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,
66         };
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();
144                                 return <Onboard/>;
145                         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
166 export default connect(mapStateToProps, mapActionsToProps)(ModuleOptions);