blob: f025450a58bd7387b8b507fc8e21a935c5a84451 [file] [log] [blame]
Michael Landoefa037d2017-02-19 12:57:33 +02001/*-
2 * ============LICENSE_START=======================================================
3 * SDC
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
19 */
20
21import {actionTypes} from './FlowsConstants.js';
22
23export default (state = {}, action) => {
24 switch (action.type) {
25 case actionTypes.FLOW_LIST_LOADED:
26 return {
27 ...state,
28 flowList: action.results,
29 flowParticipants: action.participants,
30 serviceID: action.serviceID,
31 diagramType: action.diagramType
32 };
33 case actionTypes.ADD_OR_UPDATE_FLOW:
34 case actionTypes.ARTIFACT_LOADED:
35 let flowList = state.flowList || [];
36 let index = flowList.findIndex(flow => flow.uniqueId === action.flow.uniqueId);
37 if (index === -1) {
38 index = flowList.length;
39 }
40 let flowToBeUpdated = flowList[index];
41 flowList = [
42 ...flowList.slice(0, index),
43 {...flowToBeUpdated, ...action.flow},
44 ...flowList.slice(index + 1)
45 ];
46 return {
47 ...state,
48 flowList,
49 serviceID: action.flow.serviceID,
50 diagramType: action.flow.artifactType || state.diagramType
51 };
52 case actionTypes.CURRENT_FLOW_DATA_CHANGED:
53 return {
54 ...state,
55 currentFlow: {
56 ...state.currentFlow,
57 ...action.deltaData
58 }
59 };
60 case actionTypes.DELETE_FLOW:
61 return {
62 ...state,
63 flowList: state.flowList.filter(flow => flow.uniqueId !== action.flow.uniqueId)
64 };
65 case actionTypes.OPEN_FLOW_DETAILS_EDITOR:
66 return {
67 ...state,
68 currentFlow: action.flow,
69 isDisplayModal: true,
70 isModalInEditMode: Boolean(action.flow && action.flow.uniqueId)
71 };
72
73 case actionTypes.CLOSE_FLOW_DETAILS_EDITOR:
74 return {
75 ...state,
76 currentFlow: undefined,
77 isDisplayModal: false,
78 isModalInEditMode: false
79 };
80 case actionTypes.OPEN_FLOW_DIAGRAM_EDITOR:
81 return {
82 ...state,
83 currentFlow: action.flow,
84 shouldShowWorkflowsEditor: false
85 };
86 case actionTypes.CLOSE_FLOW_DIAGRAM_EDITOR:
87 return {
88 ...state,
89 currentFlow: undefined,
90 shouldShowWorkflowsEditor: true
91 };
92 case actionTypes.RESET:
93 return {};
94 }
95
96 return state;
97};