AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 1 | /*! |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 2 | * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 3 | * |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 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 |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 12 | * 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 Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 15 | */ |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 16 | import { actionTypes, FLOWS_EDITOR_FORM } from './FlowsConstants.js'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 17 | |
| 18 | export default (state = {}, action) => { |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 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, |
| 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 Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 78 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 79 | 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 Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 101 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 102 | return state; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 103 | }; |