Fix output params
[sdc/sdc-workflow-designer.git] / workflow-designer-ui / src / main / frontend / src / features / workflow / overview / overviewSagas.js
1 /*
2 * Copyright © 2018 European Support Limited
3 *
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
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16 import { call, takeEvery, put } from 'redux-saga/effects';
17
18 import { genericNetworkErrorAction } from 'wfapp/appConstants';
19 import overviewApi from 'features/workflow/overview/overviewApi';
20 import {
21     versionListFetchAction,
22     GET_OVERVIEW,
23     UPDATE_WORKFLOW
24 } from 'features/workflow/overview/overviewConstansts';
25 import { setWorkflowAction } from 'features/workflow/workflowConstants';
26 import { notificationActions } from 'shared/notifications/notificationsActions';
27
28 export function* getOverview(action) {
29     try {
30         const versions = yield call(overviewApi.getVersions, action.payload);
31         yield put(versionListFetchAction(versions));
32         const workflow = yield call(overviewApi.getWorkflow, action.payload);
33         yield put(setWorkflowAction(workflow));
34     } catch (error) {
35         yield put(genericNetworkErrorAction(error));
36     }
37 }
38
39 export function* updateWorkflow(action) {
40     try {
41         yield call(overviewApi.updateWorkflow, action.payload);
42         yield put(
43             notificationActions.showSuccess({
44                 title: 'Update Workflow',
45                 message: 'Successfully updated'
46             })
47         );
48     } catch (e) {
49         yield put(genericNetworkErrorAction(e));
50     }
51 }
52
53 export function* watchOverview() {
54     yield takeEvery(GET_OVERVIEW, getOverview);
55     yield takeEvery(UPDATE_WORKFLOW, updateWorkflow);
56 }