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 RestAPIUtil from 'nfvo-utils/RestAPIUtil.js';
17 import Configuration from 'sdc-app/config/Configuration.js';
18 import { actionTypes } from './SoftwareProductComponentProcessesConstants.js';
19 import i18n from 'nfvo-utils/i18n/i18n.js';
21 actionTypes as modalActionTypes,
23 } from 'nfvo-components/modal/GlobalModalConstants.js';
24 import { modalContentMapper } from 'sdc-app/common/modal/ModalContentMapper.js';
26 function baseUrl(softwareProductId, version, componentId) {
27 const restPrefix = Configuration.get('restPrefix');
28 return `${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/versions/${
30 }/components/${componentId}/processes`;
33 function fetchProcessesList({ softwareProductId, version, componentId }) {
34 return RestAPIUtil.fetch(
35 `${baseUrl(softwareProductId, version, componentId)}`
39 function deleteProcess({ softwareProductId, version, componentId, processId }) {
40 return RestAPIUtil.destroy(
41 `${baseUrl(softwareProductId, version, componentId)}/${processId}`
45 function putProcess({ softwareProductId, version, componentId, process }) {
46 return RestAPIUtil.put(
47 `${baseUrl(softwareProductId, version, componentId)}/${process.id}`,
50 description: process.description,
51 type: process.type === '' ? null : process.type
56 function postProcess({ softwareProductId, version, componentId, process }) {
57 return RestAPIUtil.post(
58 `${baseUrl(softwareProductId, version, componentId)}`,
61 description: process.description,
62 type: process.type === '' ? null : process.type
67 function uploadFileToProcess({
74 return RestAPIUtil.post(
79 )}/${processId}/upload`,
84 const SoftwareProductComponentProcessesActionHelper = {
85 fetchProcessesList(dispatch, { softwareProductId, version, componentId }) {
87 type: actionTypes.FETCH_SOFTWARE_PRODUCT_COMPONENTS_PROCESSES,
91 return fetchProcessesList({
97 type: actionTypes.FETCH_SOFTWARE_PRODUCT_COMPONENTS_PROCESSES,
98 processesList: response.results
105 { process, softwareProductId, version, componentId }
107 return deleteProcess({
110 processId: process.id,
114 type: actionTypes.DELETE_SOFTWARE_PRODUCT_COMPONENTS_PROCESS,
115 processId: process.id
122 { softwareProductId, version, componentId, previousProcess, process }
124 if (previousProcess) {
133 process.formData.name !== previousProcess.artifactName
135 uploadFileToProcess({
138 processId: process.id,
139 formData: process.formData,
144 type: actionTypes.EDIT_SOFTWARE_PRODUCT_COMPONENTS_PROCESS,
154 }).then(response => {
155 if (process.formData) {
156 uploadFileToProcess({
159 processId: response.value,
160 formData: process.formData,
165 type: actionTypes.ADD_SOFTWARE_PRODUCT_COMPONENTS_PROCESS,
175 hideDeleteConfirm(dispatch) {
178 actionTypes.SOFTWARE_PRODUCT_PROCESS_DELETE_COMPONENTS_CONFIRM,
179 processToDelete: false
183 openDeleteProcessesConfirm(dispatch, { process }) {
186 actionTypes.SOFTWARE_PRODUCT_PROCESS_DELETE_COMPONENTS_CONFIRM,
187 processToDelete: process
193 { process, softwareProductId, version, isReadOnlyMode, componentId }
196 type: actionTypes.SOFTWARE_PRODUCT_PROCESS_COMPONENTS_EDITOR_OPEN,
197 process: process ? process : {}
200 type: modalActionTypes.GLOBAL_MODAL_SHOW,
202 modalComponentName: modalContentMapper.COMP_PROCESS_EDITOR,
203 modalComponentProps: {
208 size: modalSizes.LARGE
210 bodyClassName: 'edit-process-modal',
212 ? i18n('Edit Process Details')
213 : i18n('Create New Process Details')
217 closeEditor(dispatch) {
219 type: actionTypes.SOFTWARE_PRODUCT_PROCESS_COMPONENTS_EDITOR_CLOSE
222 type: modalActionTypes.GLOBAL_MODAL_CLOSE
227 export default SoftwareProductComponentProcessesActionHelper;