blob: 14bf5950507f239667bd833342858e7f3f1760a7 [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 */
AviZi280f8012017-06-09 02:39:56 +030016import {actionTypes, FLOWS_EDITOR_FORM} from './FlowsConstants.js';
Michael Landoefa037d2017-02-19 12:57:33 +020017
18export default (state = {}, action) => {
19 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,
AviZi280f8012017-06-09 02:39:56 +030026 diagramType: action.diagramType,
27 readonly: action.readonly
Michael Landoefa037d2017-02-19 12:57:33 +020028 };
29 case actionTypes.ADD_OR_UPDATE_FLOW:
30 case actionTypes.ARTIFACT_LOADED:
31 let flowList = state.flowList || [];
32 let index = flowList.findIndex(flow => flow.uniqueId === action.flow.uniqueId);
33 if (index === -1) {
34 index = flowList.length;
35 }
36 let flowToBeUpdated = flowList[index];
37 flowList = [
38 ...flowList.slice(0, index),
39 {...flowToBeUpdated, ...action.flow},
40 ...flowList.slice(index + 1)
41 ];
42 return {
43 ...state,
44 flowList,
45 serviceID: action.flow.serviceID,
46 diagramType: action.flow.artifactType || state.diagramType
47 };
Michael Landoefa037d2017-02-19 12:57:33 +020048 case actionTypes.DELETE_FLOW:
49 return {
50 ...state,
51 flowList: state.flowList.filter(flow => flow.uniqueId !== action.flow.uniqueId)
52 };
53 case actionTypes.OPEN_FLOW_DETAILS_EDITOR:
54 return {
55 ...state,
AviZi280f8012017-06-09 02:39:56 +030056 formName: FLOWS_EDITOR_FORM,
57 formReady: null,
58 genericFieldInfo: {
59 artifactName : {
60 isValid: true,
61 errorText: '',
62 validations: [{type: 'required', data: true}]
63 },
64 description: {
65 isValid: true,
66 errorText: '',
67 validations: [{type: 'required', data: true}]
68 }
69 },
70 data: action.flow,
Michael Landoefa037d2017-02-19 12:57:33 +020071 isDisplayModal: true,
72 isModalInEditMode: Boolean(action.flow && action.flow.uniqueId)
73 };
74
75 case actionTypes.CLOSE_FLOW_DETAILS_EDITOR:
76 return {
77 ...state,
AviZi280f8012017-06-09 02:39:56 +030078 data: undefined,
Michael Landoefa037d2017-02-19 12:57:33 +020079 isDisplayModal: false,
80 isModalInEditMode: false
81 };
82 case actionTypes.OPEN_FLOW_DIAGRAM_EDITOR:
83 return {
84 ...state,
AviZi280f8012017-06-09 02:39:56 +030085 data: action.flow,
Michael Landoefa037d2017-02-19 12:57:33 +020086 shouldShowWorkflowsEditor: false
87 };
88 case actionTypes.CLOSE_FLOW_DIAGRAM_EDITOR:
89 return {
90 ...state,
AviZi280f8012017-06-09 02:39:56 +030091 data: undefined,
Michael Landoefa037d2017-02-19 12:57:33 +020092 shouldShowWorkflowsEditor: true
93 };
94 case actionTypes.RESET:
95 return {};
96 }
97
98 return state;
99};