AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 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 | */ |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 16 | import React from 'react'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 17 | import PropTypes from 'prop-types'; |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 18 | import { connect } from 'react-redux'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 19 | import Input from 'nfvo-components/input/validation/InputWrapper.jsx'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 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'; |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 30 | import SoftwareProductLandingPage from './onboarding/softwareProduct/landingPage/SoftwareProductLandingPage.js'; |
| 31 | import SoftwareProductDetails from './onboarding/softwareProduct/details/SoftwareProductDetails.js'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 32 | import Onboard from './onboarding/onboard/Onboard.js'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 33 | import SoftwareProductActionHelper from './onboarding/softwareProduct/SoftwareProductActionHelper.js'; |
| 34 | import FlowsListEditor from './flows/FlowsListEditor.js'; |
| 35 | import FlowsActions from './flows/FlowsActions.js'; |
| 36 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 37 | const mapStateToProps = ({ licenseModelList }) => { |
| 38 | return { licenseModelList }; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 39 | }; |
| 40 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 41 | const mapActionsToProps = dispatch => { |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 42 | 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 Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | class ModuleOptions extends React.Component { |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 72 | 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 Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 81 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 82 | state = { |
| 83 | currentModule: localStorage.getItem('default-module'), |
| 84 | licenseModelId: localStorage.getItem('default-license-model-id') |
| 85 | }; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 86 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 87 | componentDidMount() { |
| 88 | this.props.onBootstrapped(); |
| 89 | } |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 90 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 91 | 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 Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 155 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 156 | renderModule(currentModule) { |
| 157 | const { licenseModelId } = this.state; |
| 158 | if (!licenseModelId) { |
| 159 | return; |
| 160 | } |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 161 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 162 | 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 Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 210 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 211 | handleModuleSelection = () => { |
| 212 | let selectedModule = this.refs.selectedModule.getValue(); |
| 213 | localStorage.setItem('default-module', selectedModule); |
| 214 | this.setState({ currentModule: selectedModule }); |
| 215 | }; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 216 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 217 | handleLicenseModelIdChange = () => { |
| 218 | let licenseModelId = this.refs.licenseModelId.getValue(); |
| 219 | localStorage.setItem('default-license-model-id', licenseModelId); |
| 220 | this.setState({ licenseModelId }); |
| 221 | }; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | export default connect(mapStateToProps, mapActionsToProps)(ModuleOptions); |