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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
import {actionTypes} from './SoftwareProductDeploymentConstants.js';
import {actionTypes as GlobalModalActions} from 'nfvo-components/modal/GlobalModalConstants.js';
import {modalContentMapper} from 'sdc-app/common/modal/ModalContentMapper.js';
import RestAPIUtil from 'nfvo-utils/RestAPIUtil.js';
import Configuration from 'sdc-app/config/Configuration.js';
import pickBy from 'lodash/pickBy';
function baseUrl(vspId, version) {
const versionId = version.id;
const restPrefix = Configuration.get('restPrefix');
return `${restPrefix}/v1.0/vendor-software-products/${vspId}/versions/${versionId}/deployment-flavors`;
}
function fetchDeploymentFlavorsList({softwareProductId, version}) {
return RestAPIUtil.fetch(`${baseUrl(softwareProductId, version)}`);
}
function fetchDeploymentFlavor({softwareProductId, deploymentFlavorId, version}) {
return RestAPIUtil.fetch(`${baseUrl(softwareProductId, version)}/${deploymentFlavorId}`);
}
function deleteDeploymentFlavor({softwareProductId, deploymentFlavorId, version}) {
return RestAPIUtil.destroy(`${baseUrl(softwareProductId, version)}/${deploymentFlavorId}`);
}
function createDeploymentFlavor({softwareProductId, data, version}) {
return RestAPIUtil.post(`${baseUrl(softwareProductId, version)}`, data);
}
function editDeploymentFlavor({softwareProductId, deploymentFlavorId, data, version}) {
return RestAPIUtil.put(`${baseUrl(softwareProductId, version)}/${deploymentFlavorId}`, data);
}
const SoftwareProductDeploymentActionHelper = {
fetchDeploymentFlavorsList(dispatch, {softwareProductId, version}) {
return fetchDeploymentFlavorsList({softwareProductId, version}).then(response => {
dispatch({
type: actionTypes.FETCH_SOFTWARE_PRODUCT_DEPLOYMENT_FLAVORS,
deploymentFlavors: response.results
});
});
},
fetchDeploymentFlavor({softwareProductId, deploymentFlavorId, version}) {
return fetchDeploymentFlavor({softwareProductId, deploymentFlavorId, version});
},
deleteDeploymentFlavor(dispatch, {softwareProductId, deploymentFlavorId, version}) {
return deleteDeploymentFlavor({softwareProductId, deploymentFlavorId, version}).then(() => {
return SoftwareProductDeploymentActionHelper.fetchDeploymentFlavorsList(dispatch, {softwareProductId, version});
});
},
createDeploymentFlavor(dispatch, {softwareProductId, data, version}) {
return createDeploymentFlavor({softwareProductId, data, version}).then(() => {
return SoftwareProductDeploymentActionHelper.fetchDeploymentFlavorsList(dispatch, {softwareProductId, version});
});
},
editDeploymentFlavor(dispatch, {softwareProductId, deploymentFlavorId, data, version}) {
let dataWithoutId = pickBy(data, (val, key) => key !== 'id');
return editDeploymentFlavor({softwareProductId, deploymentFlavorId, data: dataWithoutId, version}).then(() => {
return SoftwareProductDeploymentActionHelper.fetchDeploymentFlavorsList(dispatch, {softwareProductId, version});
});
},
closeDeploymentFlavorEditor(dispatch) {
dispatch({
type: actionTypes.deploymentFlavorEditor.SOFTWARE_PRODUCT_DEPLOYMENT_CLEAR_DATA
});
dispatch({
type: GlobalModalActions.GLOBAL_MODAL_CLOSE
});
},
openDeploymentFlavorEditor(dispatch, {softwareProductId, modalClassName, deploymentFlavor = {}, componentsList, isEdit = false, version}) {
let alteredDeploymentFlavor = {...deploymentFlavor};
if (componentsList.length) {
alteredDeploymentFlavor = {...alteredDeploymentFlavor, componentComputeAssociations: deploymentFlavor.componentComputeAssociations ?
[{...deploymentFlavor.componentComputeAssociations[0], componentId: componentsList[0].id}]
:
[{componentId: componentsList[0].id, computeFlavorId: null}]
};
}
dispatch({
type: actionTypes.deploymentFlavorEditor.SOFTWARE_PRODUCT_DEPLOYMENT_FILL_DATA,
deploymentFlavor: alteredDeploymentFlavor
});
dispatch({
type: GlobalModalActions.GLOBAL_MODAL_SHOW,
data: {
modalComponentName: modalContentMapper.DEPLOYMENT_FLAVOR_EDITOR,
modalComponentProps: {softwareProductId, version},
modalClassName,
title: isEdit ? 'Edit Deployment Flavor' : 'Create a New Deployment Flavor'
}
});
},
};
export default SoftwareProductDeploymentActionHelper;
|