blob: 56d389bbe5e5bfb35ffb296983994bd02f094494 [file] [log] [blame]
Einav Weiss Keidar1801b242018-08-13 16:19:46 +03001/*
2 * Copyright © 2016-2018 European Support Limited
AviZi280f8012017-06-09 02:39:56 +03003 *
Michael Landoefa037d2017-02-19 12:57:33 +02004 * 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
AviZi280f8012017-06-09 02:39:56 +03007 *
Einav Weiss Keidar1801b242018-08-13 16:19:46 +03008 * http://www.apache.org/licenses/LICENSE-2.0
AviZi280f8012017-06-09 02:39:56 +03009 *
Michael Landoefa037d2017-02-19 12:57:33 +020010 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
Einav Weiss Keidar1801b242018-08-13 16:19:46 +030012 * 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.
Michael Landoefa037d2017-02-19 12:57:33 +020015 */
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020016import { actionTypes, FLOWS_EDITOR_FORM } from './FlowsConstants.js';
Michael Landoefa037d2017-02-19 12:57:33 +020017
18export default (state = {}, action) => {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020019 switch (action.type) {
20 case actionTypes.FLOW_LIST_LOADED:
21 return {
22 ...state,
23 flowList: action.results,
24 flowParticipants: action.participants,
25 serviceID: action.serviceID,
26 diagramType: action.diagramType,
27 readonly: action.readonly
28 };
29 case actionTypes.ADD_OR_UPDATE_FLOW:
30 case actionTypes.ARTIFACT_LOADED:
31 let flowList = state.flowList || [];
32 let index = flowList.findIndex(
33 flow => flow.uniqueId === action.flow.uniqueId
34 );
35 if (index === -1) {
36 index = flowList.length;
37 }
38 let flowToBeUpdated = flowList[index];
39 flowList = [
40 ...flowList.slice(0, index),
41 { ...flowToBeUpdated, ...action.flow },
42 ...flowList.slice(index + 1)
43 ];
44 return {
45 ...state,
46 flowList,
47 serviceID: action.flow.serviceID,
48 diagramType: action.flow.artifactType || state.diagramType
49 };
50 case actionTypes.DELETE_FLOW:
51 return {
52 ...state,
53 flowList: state.flowList.filter(
54 flow => flow.uniqueId !== action.flow.uniqueId
55 )
56 };
57 case actionTypes.OPEN_FLOW_DETAILS_EDITOR:
58 return {
59 ...state,
60 formName: FLOWS_EDITOR_FORM,
61 formReady: null,
62 genericFieldInfo: {
63 artifactName: {
64 isValid: true,
65 errorText: '',
66 validations: [{ type: 'required', data: true }]
67 },
68 description: {
69 isValid: true,
70 errorText: '',
71 validations: [{ type: 'required', data: true }]
72 }
73 },
Einav Weiss Keidar1801b242018-08-13 16:19:46 +030074 data: action.flow
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020075 };
Michael Landoefa037d2017-02-19 12:57:33 +020076
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020077 case actionTypes.CLOSE_FLOW_DETAILS_EDITOR:
78 return {
79 ...state,
Einav Weiss Keidar1801b242018-08-13 16:19:46 +030080 data: undefined
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020081 };
82 case actionTypes.OPEN_FLOW_DIAGRAM_EDITOR:
83 return {
84 ...state,
85 data: action.flow,
86 shouldShowWorkflowsEditor: false
87 };
88 case actionTypes.CLOSE_FLOW_DIAGRAM_EDITOR:
89 return {
90 ...state,
91 data: undefined,
92 shouldShowWorkflowsEditor: true
93 };
94 case actionTypes.RESET:
95 return {};
96 }
Michael Landoefa037d2017-02-19 12:57:33 +020097
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020098 return state;
Michael Landoefa037d2017-02-19 12:57:33 +020099};