summaryrefslogtreecommitdiffstats
path: root/openecomp-ui/src/sdc-app/onboarding/softwareProduct/components/SoftwareProductComponents.js
blob: 61aebdf2936342b342adff108507e8083d88467b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import {connect} from 'react-redux';
import React from 'react';
import i18n from 'nfvo-utils/i18n/i18n.js';

import SoftwareProductComponentsList from './SoftwareProductComponentsList.js';
import OnboardingActionHelper from 'sdc-app/onboarding/OnboardingActionHelper.js';
import VersionControllerUtils from 'nfvo-components/panel/versionController/VersionControllerUtils.js';
import SoftwareProductComponentsActionHelper from '../components/SoftwareProductComponentsActionHelper.js';
import {onboardingMethod} from '../SoftwareProductConstants.js';
import ConfirmationModalConstants from 'nfvo-components/modal/GlobalModalConstants.js';

const generateMessage = (name) => {
	return i18n(`Are you sure you want to delete ${name}?`);
};

const mapStateToProps = ({softwareProduct}) => {
	let {softwareProductEditor: {data: currentSoftwareProduct}, softwareProductComponents} = softwareProduct;
	let {componentsList} = softwareProductComponents;
	let isReadOnlyMode = VersionControllerUtils.isReadOnly(currentSoftwareProduct);

	return {
		currentSoftwareProduct,
		isReadOnlyMode,
		componentsList,
		isManual: currentSoftwareProduct.onboardingMethod === onboardingMethod.MANUAL

	};
};

class SoftwareProductComponentsView extends React.Component {
	render() {
		let {currentSoftwareProduct, isReadOnlyMode, componentsList, isManual, onDeleteComponent} = this.props;
		return (
			<SoftwareProductComponentsList
				isReadOnlyMode={isReadOnlyMode}
				componentsList={componentsList}
				onDeleteComponent={onDeleteComponent}
				isManual={isManual}
				currentSoftwareProduct={currentSoftwareProduct}/>);
	}

}

const mapActionToProps = (dispatch) => {
	return {
		onComponentSelect: ({id: softwareProductId, componentId, version}) => {
			OnboardingActionHelper.navigateToSoftwareProductComponentGeneralAndUpdateLeftPanel(dispatch, {softwareProductId, componentId, version });
		},
		onAddComponent: (softwareProductId) => SoftwareProductComponentsActionHelper.addComponent(dispatch, {softwareProductId}),
		onDeleteComponent: (component, softwareProductId, version) => dispatch({
			type: ConfirmationModalConstants.GLOBAL_MODAL_WARNING,
			data:{
				msg: generateMessage(component.displayName),
				onConfirmed: ()=>SoftwareProductComponentsActionHelper.deleteComponent(dispatch,
					{
						softwareProductId,
						componentId: component.id,
						version
					})
			}
		})
	};
};

export default connect(mapStateToProps, mapActionToProps, null, {withRef: true})(SoftwareProductComponentsView);