blob: 245dd2b55c6a02036fe418f64b53e7955b0853e4 [file] [log] [blame]
/*
* Copyright © 2016-2018 European Support Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React from 'react';
import { render } from 'react-dom';
import ReactDOM from 'react-dom';
import isEqual from 'lodash/isEqual.js';
import i18n from 'nfvo-utils/i18n/i18n.js';
import Application from 'sdc-app/Application.jsx';
import store from 'sdc-app/AppStore.js';
import Configuration from 'sdc-app/config/Configuration.js';
import ScreensHelper from 'sdc-app/common/helpers/ScreensHelper.js';
import {
onboardingMethod as onboardingMethodTypes,
onboardingOriginTypes
} from 'sdc-app/onboarding/softwareProduct/SoftwareProductConstants.js';
import { itemTypes } from './versionsPage/VersionsPageConstants.js';
import { AppContainer } from 'react-hot-loader';
import HeatSetupActionHelper from './softwareProduct/attachments/setup/HeatSetupActionHelper.js';
import { actionTypes, enums, screenTypes } from './OnboardingConstants.js';
import OnboardingActionHelper from './OnboardingActionHelper.js';
import Onboarding from './Onboarding.js';
export default class OnboardingPunchOut {
render({ options: { data, apiRoot, apiHeaders }, onEvent }, element) {
if (!this.unsubscribeFromStore) {
this.unsubscribeFromStore = store.subscribe(() =>
this.handleStoreChange()
);
}
if (!this.isConfigSet) {
Configuration.setCatalogApiRoot(apiRoot);
Configuration.setCatalogApiHeaders(apiHeaders);
this.isConfigSet = true;
}
this.onEvent = (...args) => onEvent(...args);
this.handleData(data);
if (!this.rendered) {
render(
<AppContainer>
<Application>
<Onboarding />
</Application>
</AppContainer>,
element
);
if (module.hot) {
module.hot.accept('sdc-app/onboarding/Onboarding.js', () => {
const NextOnboarding = require('sdc-app/onboarding/Onboarding.js')
.default;
render(
<AppContainer>
<Application>
<NextOnboarding />
</Application>
</AppContainer>,
element
);
});
}
this.rendered = true;
}
}
unmount(element) {
ReactDOM.unmountComponentAtNode(element);
this.rendered = false;
this.unsubscribeFromStore();
this.unsubscribeFromStore = null;
}
handleData(data) {
let { breadcrumbs: { selectedKeys = [] } = {} } = data;
let dispatch = action => store.dispatch(action);
let {
currentScreen,
users: { usersList },
softwareProductList,
finalizedSoftwareProductList,
licenseModelList,
finalizedLicenseModelList,
softwareProduct: {
softwareProductEditor: { data: vspData = {} },
softwareProductComponents = {},
softwareProductQuestionnaire = {}
},
archivedLicenseModelList
} = store.getState();
const wholeSoftwareProductList = [
...softwareProductList,
...finalizedSoftwareProductList
];
const wholeLicenseModelList = [
...licenseModelList,
...finalizedLicenseModelList,
...archivedLicenseModelList
];
let { props: { version, isReadOnlyMode }, screen } = currentScreen;
let {
componentEditor: {
data: componentData = {},
qdata: componentQData = {}
}
} = softwareProductComponents;
if (this.programmaticBreadcrumbsUpdate) {
this.prevSelectedKeys = selectedKeys;
this.programmaticBreadcrumbsUpdate = false;
return;
}
if (!isEqual(selectedKeys, this.prevSelectedKeys)) {
this.breadcrumbsPrefixSelected = isEqual(
selectedKeys,
this.prevSelectedKeys &&
this.prevSelectedKeys.slice(0, selectedKeys.length)
);
const [, screenType, prevVspId, , prevComponentId] =
this.prevSelectedKeys || [];
let preNavigate = Promise.resolve();
if (
screenType === enums.BREADCRUMS.SOFTWARE_PRODUCT &&
screen !== 'VERSIONS_PAGE' &&
!isReadOnlyMode
) {
let dataToSave = prevVspId
? prevComponentId
? { componentData, qdata: componentQData }
: {
softwareProduct: vspData,
qdata: softwareProductQuestionnaire.qdata
}
: {};
preNavigate = OnboardingActionHelper.autoSaveBeforeNavigate(
dispatch,
{
softwareProductId: prevVspId,
version,
vspComponentId: prevComponentId,
dataToSave
}
);
}
let {
currentScreen: { props: { softwareProductId } },
softwareProduct: {
softwareProductAttachments: { heatSetup, heatSetupCache }
}
} = store.getState();
let heatSetupPopupPromise =
currentScreen.screen ===
enums.SCREEN.SOFTWARE_PRODUCT_ATTACHMENTS
? HeatSetupActionHelper.heatSetupLeaveConfirmation(
dispatch,
{ softwareProductId, heatSetup, heatSetupCache }
)
: Promise.resolve();
Promise.all([preNavigate, heatSetupPopupPromise])
.then(() => {
this.prevSelectedKeys = selectedKeys;
if (selectedKeys.length === 0) {
ScreensHelper.loadScreen(dispatch, {
screen: enums.SCREEN.ONBOARDING_CATALOG
});
} else if (
selectedKeys.length === 1 ||
selectedKeys[1] === enums.BREADCRUMS.LICENSE_MODEL
) {
let [
licenseModelId,
,
licenseModelScreen
] = selectedKeys;
let licenseModel = wholeLicenseModelList.find(
vlm => vlm.id === licenseModelId
);
ScreensHelper.loadScreen(dispatch, {
screen: licenseModelScreen,
screenType: screenTypes.LICENSE_MODEL,
props: {
licenseModelId,
version,
licenseModel,
usersList
}
});
} else if (
selectedKeys.length <= 4 &&
selectedKeys[1] === enums.BREADCRUMS.SOFTWARE_PRODUCT
) {
let [
licenseModelId,
,
softwareProductId,
softwareProductScreen
] = selectedKeys;
let softwareProduct = softwareProductId
? wholeSoftwareProductList.find(
({ id }) => id === softwareProductId
)
: wholeSoftwareProductList.find(
({ vendorId }) => vendorId === licenseModelId
);
if (!softwareProductId) {
softwareProductId = softwareProduct.id;
}
if (
softwareProductScreen ===
enums.SCREEN.SOFTWARE_PRODUCT_ATTACHMENTS
) {
softwareProduct = vspData;
//check current vsp fields to determine which file has uploaded
if (
vspData.onboardingOrigin ===
onboardingOriginTypes.ZIP ||
vspData.candidateOnboardingOrigin ===
onboardingOriginTypes.ZIP
) {
softwareProductScreen =
enums.SCREEN
.SOFTWARE_PRODUCT_ATTACHMENTS_SETUP;
} else if (
vspData.onboardingOrigin ===
onboardingOriginTypes.CSAR
) {
softwareProductScreen =
enums.SCREEN
.SOFTWARE_PRODUCT_ATTACHMENTS_VALIDATION;
}
}
ScreensHelper.loadScreen(dispatch, {
screen: softwareProductScreen,
screenType: screenTypes.SOFTWARE_PRODUCT,
props: {
softwareProductId,
softwareProduct,
version,
usersList
}
});
} else if (
selectedKeys.length === 5 &&
selectedKeys[1] === enums.BREADCRUMS.SOFTWARE_PRODUCT &&
selectedKeys[3] ===
enums.BREADCRUMS.SOFTWARE_PRODUCT_COMPONENTS
) {
let [
licenseModelId,
,
softwareProductId,
,
componentId
] = selectedKeys;
let softwareProduct = softwareProductId
? wholeSoftwareProductList.find(
({ id }) => id === softwareProductId
)
: wholeSoftwareProductList.find(
({ vendorId }) => vendorId === licenseModelId
);
if (!softwareProductId) {
softwareProductId = softwareProduct.id;
}
ScreensHelper.loadScreen(dispatch, {
screen: enums.SCREEN.SOFTWARE_PRODUCT_COMPONENTS,
screenType: screenTypes.SOFTWARE_PRODUCT,
props: {
softwareProductId,
softwareProduct,
componentId,
version,
usersList
}
});
} else if (
selectedKeys.length === 6 &&
selectedKeys[1] === enums.BREADCRUMS.SOFTWARE_PRODUCT &&
selectedKeys[3] ===
enums.BREADCRUMS.SOFTWARE_PRODUCT_COMPONENTS
) {
let [
licenseModelId,
,
softwareProductId,
,
componentId,
componentScreen
] = selectedKeys;
let softwareProduct = softwareProductId
? wholeSoftwareProductList.find(
({ id }) => id === softwareProductId
)
: wholeSoftwareProductList.find(
({ vendorId }) => vendorId === licenseModelId
);
if (!softwareProductId) {
softwareProductId = softwareProduct.id;
}
ScreensHelper.loadScreen(dispatch, {
screen: componentScreen,
screenType: screenTypes.SOFTWARE_PRODUCT,
props: {
softwareProductId,
softwareProduct,
componentId,
version,
usersList
}
});
} else {
console.error(
'Unknown breadcrumbs path: ',
selectedKeys
);
}
})
.catch(() => {
store.dispatch({
type: actionTypes.SET_CURRENT_SCREEN,
currentScreen: {
...currentScreen,
forceBreadCrumbsUpdate: true
}
});
});
}
}
handleStoreChange() {
let {
currentScreen,
versionsPage: { versionsList: { itemType, itemId } },
softwareProduct: {
softwareProductEditor: {
data: currentSoftwareProduct = { onboardingMethod: '' }
},
softwareProductComponents: { componentsList }
},
licenseModel: {
licenseModelEditor: { data: currentLicenseModel = {} }
}
} = store.getState();
let breadcrumbsData = {
itemType,
itemId,
currentScreen,
currentSoftwareProduct,
currentLicenseModel,
componentsList
};
if (
currentScreen.forceBreadCrumbsUpdate ||
!isEqual(breadcrumbsData, this.prevBreadcrumbsData) ||
this.breadcrumbsPrefixSelected
) {
this.prevBreadcrumbsData = breadcrumbsData;
this.breadcrumbsPrefixSelected = false;
this.programmaticBreadcrumbsUpdate = true;
let breadcrumbs = this.buildBreadcrumbs(breadcrumbsData);
this.onEvent('breadcrumbsupdated', breadcrumbs);
store.dispatch({
type: actionTypes.SET_CURRENT_SCREEN,
currentScreen: {
...currentScreen,
forceBreadCrumbsUpdate: false
}
});
}
}
buildBreadcrumbs({
currentScreen: { screen, props },
itemType,
itemId,
currentSoftwareProduct,
currentLicenseModel,
componentsList
}) {
let {
onboardingMethod,
onboardingOrigin,
candidateOnboardingOrigin
} = currentSoftwareProduct;
let screenToBreadcrumb;
switch (screen) {
case enums.SCREEN.ONBOARDING_CATALOG:
return [];
case enums.SCREEN.VERSIONS_PAGE:
let firstMenuItems =
itemType === itemTypes.LICENSE_MODEL
? [
{
selectedKey: itemId,
menuItems: [
{
key: itemId,
displayText: props.itemName
}
]
}
]
: [
{
selectedKey:
props.additionalProps.licenseModelId ||
currentSoftwareProduct.vendorId,
menuItems: [
{
key: props.vendorId,
displayText: props.vendorName
}
]
},
{
selectedKey:
enums.BREADCRUMS.SOFTWARE_PRODUCT,
menuItems: [
{
key: enums.BREADCRUMS.LICENSE_MODEL,
displayText: i18n('License Model')
},
{
key:
enums.BREADCRUMS.SOFTWARE_PRODUCT,
displayText: i18n('Software Products')
}
]
},
{
selectedKey: itemId,
menuItems: [
{
key: itemId,
displayText: props.itemName
}
]
}
];
return [
...firstMenuItems,
{
selectedKey: enums.BREADCRUMS.VERSIONS_PAGE,
menuItems: [
{
key: enums.BREADCRUMS.VERSIONS_PAGE,
displayText: i18n('Versions Page')
}
]
}
];
case enums.SCREEN.LICENSE_AGREEMENTS:
case enums.SCREEN.FEATURE_GROUPS:
case enums.SCREEN.ENTITLEMENT_POOLS:
case enums.SCREEN.LICENSE_KEY_GROUPS:
case enums.SCREEN.LICENSE_MODEL_OVERVIEW:
case enums.SCREEN.ACTIVITY_LOG:
screenToBreadcrumb = {
[enums.SCREEN.LICENSE_AGREEMENTS]:
enums.BREADCRUMS.LICENSE_AGREEMENTS,
[enums.SCREEN.FEATURE_GROUPS]:
enums.BREADCRUMS.FEATURE_GROUPS,
[enums.SCREEN.ENTITLEMENT_POOLS]:
enums.BREADCRUMS.ENTITLEMENT_POOLS,
[enums.SCREEN.LICENSE_KEY_GROUPS]:
enums.BREADCRUMS.LICENSE_KEY_GROUPS,
[enums.SCREEN.LICENSE_MODEL_OVERVIEW]:
enums.BREADCRUMS.LICENSE_MODEL_OVERVIEW,
[enums.SCREEN.ACTIVITY_LOG]: enums.BREADCRUMS.ACTIVITY_LOG
};
return [
{
selectedKey: currentLicenseModel.id,
menuItems: [
{
key: currentLicenseModel.id,
displayText: currentLicenseModel.vendorName
}
]
},
{
selectedKey: enums.BREADCRUMS.LICENSE_MODEL,
menuItems: [
{
key: enums.BREADCRUMS.LICENSE_MODEL,
displayText: i18n('License Model')
}
]
},
{
selectedKey: screenToBreadcrumb[screen],
menuItems: [
{
key: enums.BREADCRUMS.LICENSE_MODEL_OVERVIEW,
displayText: i18n('Overview')
},
{
key: enums.BREADCRUMS.LICENSE_AGREEMENTS,
displayText: i18n('License Agreements')
},
{
key: enums.BREADCRUMS.FEATURE_GROUPS,
displayText: i18n('Feature Groups')
},
{
key: enums.BREADCRUMS.ENTITLEMENT_POOLS,
displayText: i18n('Entitlement Pools')
},
{
key: enums.BREADCRUMS.LICENSE_KEY_GROUPS,
displayText: i18n('License Key Groups')
},
{
key: enums.BREADCRUMS.ACTIVITY_LOG,
displayText: i18n('Activity Log')
}
]
}
];
case enums.SCREEN.SOFTWARE_PRODUCT_LANDING_PAGE:
case enums.SCREEN.SOFTWARE_PRODUCT_DETAILS:
case enums.SCREEN.SOFTWARE_PRODUCT_ATTACHMENTS:
case enums.SCREEN.SOFTWARE_PRODUCT_PROCESSES:
case enums.SCREEN.SOFTWARE_PRODUCT_DEPLOYMENT:
case enums.SCREEN.SOFTWARE_PRODUCT_NETWORKS:
case enums.SCREEN.SOFTWARE_PRODUCT_DEPENDENCIES:
case enums.SCREEN.SOFTWARE_PRODUCT_ACTIVITY_LOG:
case enums.SCREEN.SOFTWARE_PRODUCT_COMPONENTS:
case enums.SCREEN.SOFTWARE_PRODUCT_COMPONENT_PROCESSES:
case enums.SCREEN.SOFTWARE_PRODUCT_COMPONENT_COMPUTE:
case enums.SCREEN.SOFTWARE_PRODUCT_COMPONENT_STORAGE:
case enums.SCREEN.SOFTWARE_PRODUCT_COMPONENT_NETWORK:
case enums.SCREEN.SOFTWARE_PRODUCT_COMPONENT_GENERAL:
case enums.SCREEN.SOFTWARE_PRODUCT_COMPONENT_LOAD_BALANCING:
case enums.SCREEN.SOFTWARE_PRODUCT_COMPONENT_IMAGES:
case enums.SCREEN.SOFTWARE_PRODUCT_COMPONENT_MONITORING:
screenToBreadcrumb = {
[enums.SCREEN.SOFTWARE_PRODUCT_LANDING_PAGE]:
enums.BREADCRUMS.SOFTWARE_PRODUCT_LANDING_PAGE,
[enums.SCREEN.SOFTWARE_PRODUCT_DETAILS]:
enums.BREADCRUMS.SOFTWARE_PRODUCT_DETAILS,
[enums.SCREEN.SOFTWARE_PRODUCT_ATTACHMENTS]:
enums.BREADCRUMS.SOFTWARE_PRODUCT_ATTACHMENTS,
[enums.SCREEN.SOFTWARE_PRODUCT_PROCESSES]:
enums.BREADCRUMS.SOFTWARE_PRODUCT_PROCESSES,
[enums.SCREEN.SOFTWARE_PRODUCT_DEPLOYMENT]:
enums.BREADCRUMS.SOFTWARE_PRODUCT_DEPLOYMENT,
[enums.SCREEN.SOFTWARE_PRODUCT_NETWORKS]:
enums.BREADCRUMS.SOFTWARE_PRODUCT_NETWORKS,
[enums.SCREEN.SOFTWARE_PRODUCT_DEPENDENCIES]:
enums.BREADCRUMS.SOFTWARE_PRODUCT_DEPENDENCIES,
[enums.SCREEN.SOFTWARE_PRODUCT_COMPONENTS]:
enums.BREADCRUMS.SOFTWARE_PRODUCT_COMPONENTS,
[enums.SCREEN.SOFTWARE_PRODUCT_ACTIVITY_LOG]:
enums.BREADCRUMS.SOFTWARE_PRODUCT_ACTIVITY_LOG
};
let componentScreenToBreadcrumb = {
[enums.SCREEN.SOFTWARE_PRODUCT_COMPONENT_PROCESSES]:
enums.BREADCRUMS.SOFTWARE_PRODUCT_COMPONENT_PROCESSES,
[enums.SCREEN.SOFTWARE_PRODUCT_COMPONENT_COMPUTE]:
enums.BREADCRUMS.SOFTWARE_PRODUCT_COMPONENT_COMPUTE,
[enums.SCREEN.SOFTWARE_PRODUCT_COMPONENT_STORAGE]:
enums.BREADCRUMS.SOFTWARE_PRODUCT_COMPONENT_STORAGE,
[enums.SCREEN.SOFTWARE_PRODUCT_COMPONENT_NETWORK]:
enums.BREADCRUMS.SOFTWARE_PRODUCT_COMPONENT_NETWORK,
[enums.SCREEN.SOFTWARE_PRODUCT_COMPONENT_GENERAL]:
enums.BREADCRUMS.SOFTWARE_PRODUCT_COMPONENT_GENERAL,
[enums.SCREEN.SOFTWARE_PRODUCT_COMPONENT_LOAD_BALANCING]:
enums.BREADCRUMS
.SOFTWARE_PRODUCT_COMPONENT_LOAD_BALANCING,
[enums.SCREEN.SOFTWARE_PRODUCT_COMPONENT_IMAGES]:
enums.BREADCRUMS.SOFTWARE_PRODUCT_COMPONENT_IMAGES,
[enums.SCREEN.SOFTWARE_PRODUCT_COMPONENT_MONITORING]:
enums.BREADCRUMS.SOFTWARE_PRODUCT_COMPONENT_MONITORING
};
let returnedBreadcrumb = [
{
selectedKey: currentSoftwareProduct.vendorId,
menuItems: [
{
key: currentSoftwareProduct.vendorId,
displayText: currentSoftwareProduct.vendorName
}
]
},
{
selectedKey: enums.BREADCRUMS.SOFTWARE_PRODUCT,
menuItems: [
{
key: enums.BREADCRUMS.LICENSE_MODEL,
displayText: i18n('License Model')
},
{
key: enums.BREADCRUMS.SOFTWARE_PRODUCT,
displayText: i18n('Software Products')
}
]
},
{
selectedKey: currentSoftwareProduct.id,
menuItems: [
{
key: currentSoftwareProduct.id,
displayText: currentSoftwareProduct.name
}
]
},
.../*screen === enums.SCREEN.SOFTWARE_PRODUCT_LANDING_PAGE ? [] :*/ [
{
selectedKey:
screenToBreadcrumb[screen] ||
enums.BREADCRUMS.SOFTWARE_PRODUCT_COMPONENTS,
menuItems: [
{
key:
enums.BREADCRUMS
.SOFTWARE_PRODUCT_LANDING_PAGE,
displayText: i18n('Overview')
},
{
key:
enums.BREADCRUMS
.SOFTWARE_PRODUCT_DETAILS,
displayText: i18n('General')
},
{
key:
enums.BREADCRUMS
.SOFTWARE_PRODUCT_DEPLOYMENT,
displayText: i18n('Deployment Flavors')
},
{
key:
enums.BREADCRUMS
.SOFTWARE_PRODUCT_PROCESSES,
displayText: i18n('Process Details')
},
{
key:
enums.BREADCRUMS
.SOFTWARE_PRODUCT_NETWORKS,
displayText: i18n('Networks')
},
{
key:
enums.BREADCRUMS
.SOFTWARE_PRODUCT_DEPENDENCIES,
displayText: i18n('Components Dependencies')
},
{
key:
enums.BREADCRUMS
.SOFTWARE_PRODUCT_ATTACHMENTS,
displayText: i18n('Attachments')
},
{
key:
enums.BREADCRUMS
.SOFTWARE_PRODUCT_ACTIVITY_LOG,
displayText: i18n('Activity Log')
},
{
key:
enums.BREADCRUMS
.SOFTWARE_PRODUCT_COMPONENTS,
displayText: i18n('Components')
}
].filter(item => {
switch (item.key) {
case enums.BREADCRUMS
.SOFTWARE_PRODUCT_ATTACHMENTS:
let isHeatData =
onboardingOrigin !==
onboardingOriginTypes.NONE ||
candidateOnboardingOrigin ===
onboardingOriginTypes.ZIP;
return isHeatData;
case enums.BREADCRUMS
.SOFTWARE_PRODUCT_COMPONENTS:
return componentsList.length > 0;
case enums.BREADCRUMS
.SOFTWARE_PRODUCT_DEPLOYMENT:
let isManualMode =
onboardingMethod ===
onboardingMethodTypes.MANUAL;
return isManualMode;
case enums.BREADCRUMS
.SOFTWARE_PRODUCT_DEPENDENCIES:
return componentsList.length > 1;
default:
return true;
}
})
}
]
];
if (props.componentId) {
returnedBreadcrumb = [
...returnedBreadcrumb,
{
selectedKey: props.componentId,
menuItems: componentsList.map(
({ id, displayName }) => ({
key: id,
displayText: displayName
})
)
},
...[
{
selectedKey:
componentScreenToBreadcrumb[screen],
menuItems: [
{
key:
enums.BREADCRUMS
.SOFTWARE_PRODUCT_COMPONENT_GENERAL,
displayText: i18n('General')
},
{
key:
enums.BREADCRUMS
.SOFTWARE_PRODUCT_COMPONENT_COMPUTE,
displayText: i18n('Compute')
},
{
key:
enums.BREADCRUMS
.SOFTWARE_PRODUCT_COMPONENT_LOAD_BALANCING,
displayText: i18n(
'High Availability & Load Balancing'
)
},
{
key:
enums.BREADCRUMS
.SOFTWARE_PRODUCT_COMPONENT_NETWORK,
displayText: i18n('Networks')
},
{
key:
enums.BREADCRUMS
.SOFTWARE_PRODUCT_COMPONENT_STORAGE,
displayText: i18n('Storage')
},
{
key:
enums.BREADCRUMS
.SOFTWARE_PRODUCT_COMPONENT_IMAGES,
displayText: i18n('Images')
},
{
key:
enums.BREADCRUMS
.SOFTWARE_PRODUCT_COMPONENT_PROCESSES,
displayText: i18n('Process Details')
},
{
key:
enums.BREADCRUMS
.SOFTWARE_PRODUCT_COMPONENT_MONITORING,
displayText: i18n('Monitoring')
}
]
}
]
];
}
return returnedBreadcrumb;
}
}
}