blob: 0279824ac4ee75665e14057e14d412f74ad94ba2 [file] [log] [blame]
AviZi280f8012017-06-09 02:39:56 +03001/*!
Michael Landoefa037d2017-02-19 12:57:33 +02002 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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,
AviZi280f8012017-06-09 02:39:56 +030012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13 * or implied. See the License for the specific language governing
14 * permissions and 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 },
74 data: action.flow,
75 isDisplayModal: true,
76 isModalInEditMode: Boolean(action.flow && action.flow.uniqueId)
77 };
Michael Landoefa037d2017-02-19 12:57:33 +020078
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020079 case actionTypes.CLOSE_FLOW_DETAILS_EDITOR:
80 return {
81 ...state,
82 data: undefined,
83 isDisplayModal: false,
84 isModalInEditMode: false
85 };
86 case actionTypes.OPEN_FLOW_DIAGRAM_EDITOR:
87 return {
88 ...state,
89 data: action.flow,
90 shouldShowWorkflowsEditor: false
91 };
92 case actionTypes.CLOSE_FLOW_DIAGRAM_EDITOR:
93 return {
94 ...state,
95 data: undefined,
96 shouldShowWorkflowsEditor: true
97 };
98 case actionTypes.RESET:
99 return {};
100 }
Michael Landoefa037d2017-02-19 12:57:33 +0200101
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200102 return state;
Michael Landoefa037d2017-02-19 12:57:33 +0200103};