2 * Copyright © 2016-2018 European Support Limited
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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 or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 import { actionTypes } from './SoftwareProductDeploymentConstants.js';
17 import { actionTypes as GlobalModalActions } from 'nfvo-components/modal/GlobalModalConstants.js';
18 import { modalContentMapper } from 'sdc-app/common/modal/ModalContentMapper.js';
19 import RestAPIUtil from 'nfvo-utils/RestAPIUtil.js';
20 import Configuration from 'sdc-app/config/Configuration.js';
21 import pickBy from 'lodash/pickBy';
23 function baseUrl(vspId, version) {
24 const versionId = version.id;
25 const restPrefix = Configuration.get('restPrefix');
26 return `${restPrefix}/v1.0/vendor-software-products/${vspId}/versions/${versionId}/deployment-flavors`;
29 function fetchDeploymentFlavorsList({ softwareProductId, version }) {
30 return RestAPIUtil.fetch(`${baseUrl(softwareProductId, version)}`);
33 function fetchDeploymentFlavor({
38 return RestAPIUtil.fetch(
39 `${baseUrl(softwareProductId, version)}/${deploymentFlavorId}`
43 function deleteDeploymentFlavor({
48 return RestAPIUtil.destroy(
49 `${baseUrl(softwareProductId, version)}/${deploymentFlavorId}`
53 function createDeploymentFlavor({ softwareProductId, data, version }) {
54 return RestAPIUtil.post(`${baseUrl(softwareProductId, version)}`, data);
57 function editDeploymentFlavor({
63 return RestAPIUtil.put(
64 `${baseUrl(softwareProductId, version)}/${deploymentFlavorId}`,
69 const SoftwareProductDeploymentActionHelper = {
70 fetchDeploymentFlavorsList(dispatch, { softwareProductId, version }) {
71 return fetchDeploymentFlavorsList({ softwareProductId, version }).then(
74 type: actionTypes.FETCH_SOFTWARE_PRODUCT_DEPLOYMENT_FLAVORS,
75 deploymentFlavors: response.results
81 fetchDeploymentFlavor({ softwareProductId, deploymentFlavorId, version }) {
82 return fetchDeploymentFlavor({
89 deleteDeploymentFlavor(
91 { softwareProductId, deploymentFlavorId, version }
93 return deleteDeploymentFlavor({
98 return SoftwareProductDeploymentActionHelper.fetchDeploymentFlavorsList(
100 { softwareProductId, version }
105 createDeploymentFlavor(dispatch, { softwareProductId, data, version }) {
106 return createDeploymentFlavor({
111 return SoftwareProductDeploymentActionHelper.fetchDeploymentFlavorsList(
113 { softwareProductId, version }
118 editDeploymentFlavor(
120 { softwareProductId, deploymentFlavorId, data, version }
122 let dataWithoutId = pickBy(data, (val, key) => key !== 'id');
123 return editDeploymentFlavor({
129 return SoftwareProductDeploymentActionHelper.fetchDeploymentFlavorsList(
131 { softwareProductId, version }
136 closeDeploymentFlavorEditor(dispatch) {
139 actionTypes.deploymentFlavorEditor
140 .SOFTWARE_PRODUCT_DEPLOYMENT_CLEAR_DATA
143 type: GlobalModalActions.GLOBAL_MODAL_CLOSE
147 openDeploymentFlavorEditor(
152 deploymentFlavor = {},
158 let alteredDeploymentFlavor = { ...deploymentFlavor };
159 if (componentsList.length) {
160 alteredDeploymentFlavor = {
161 ...alteredDeploymentFlavor,
162 componentComputeAssociations: deploymentFlavor.componentComputeAssociations
166 .componentComputeAssociations[0],
167 componentId: componentsList[0].id
172 componentId: componentsList[0].id,
173 computeFlavorId: null
180 actionTypes.deploymentFlavorEditor
181 .SOFTWARE_PRODUCT_DEPLOYMENT_FILL_DATA,
182 deploymentFlavor: alteredDeploymentFlavor
185 type: GlobalModalActions.GLOBAL_MODAL_SHOW,
187 modalComponentName: modalContentMapper.DEPLOYMENT_FLAVOR_EDITOR,
188 modalComponentProps: { softwareProductId, version },
189 bodyClassName: modalClassName,
191 ? 'Edit Deployment Flavor'
192 : 'Create a New Deployment Flavor'
198 export default SoftwareProductDeploymentActionHelper;