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 | */ |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [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) => { |
| 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, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 26 | diagramType: action.diagramType, |
| 27 | readonly: action.readonly |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 28 | }; |
| 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 Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 48 | 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, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 56 | 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 Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 71 | isDisplayModal: true, |
| 72 | isModalInEditMode: Boolean(action.flow && action.flow.uniqueId) |
| 73 | }; |
| 74 | |
| 75 | case actionTypes.CLOSE_FLOW_DETAILS_EDITOR: |
| 76 | return { |
| 77 | ...state, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 78 | data: undefined, |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 79 | isDisplayModal: false, |
| 80 | isModalInEditMode: false |
| 81 | }; |
| 82 | case actionTypes.OPEN_FLOW_DIAGRAM_EDITOR: |
| 83 | return { |
| 84 | ...state, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 85 | data: action.flow, |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 86 | shouldShowWorkflowsEditor: false |
| 87 | }; |
| 88 | case actionTypes.CLOSE_FLOW_DIAGRAM_EDITOR: |
| 89 | return { |
| 90 | ...state, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 91 | data: undefined, |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 92 | shouldShowWorkflowsEditor: true |
| 93 | }; |
| 94 | case actionTypes.RESET: |
| 95 | return {}; |
| 96 | } |
| 97 | |
| 98 | return state; |
| 99 | }; |