blob: 6985fcfaca562024dff46ebf5a2a0278e8f6e2eb [file] [log] [blame]
talig8e9c0652017-12-20 14:30:43 +02001/*!
2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an 'AS IS' BASIS,
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.
15 */
16import {actionTypes} from './MergeEditorConstants.js';
17
18export default (state = [], action) => {
19 switch (action.type) {
20 case actionTypes.LOAD_CONFLICT: {
21 let cdata = {...action.data};
22 // let data = state.conflicts ? {...state.conflicts.data} : {} ;
23 // data[cdata.id] = cdata;
24 let conflicts = state.conflicts ? {...state.conflicts} : {};
25 conflicts[cdata.id] = cdata;
26 return {
27 ...state,
28 conflicts
29 };
30 }
31 case actionTypes.DATA_PROCESSED: {
32 let conflicts = {...state.conflicts};
33 let {data} = action;
34 if (data && data.cid) {
35 let yours = {...conflicts[data.cid].yours};
36 let theirs = {...conflicts[data.cid].theirs};
37 let {yoursField, theirsField} = data;
38 if (yoursField) {
39 yours[yoursField.name] = yoursField.value;
40 conflicts[data.cid].yours = yours;
41 }
42 if (theirsField) {
43 theirs[theirsField.name] = theirsField.value;
44 conflicts[data.cid].theirs = theirs;
45 }
46 }
47 return {
48 ...state,
49 conflicts: {
50 ...conflicts
51 }
52 };
53 }
54 case actionTypes.LOAD_CONFLICTS:
55 let conflictFiles = [];
56 if (action.data) {
57 conflictFiles = [...action.data.conflictInfoList];
58 }
59 return {
60 inMerge: conflictFiles.length > 0,
61 conflictFiles
62 };
63 default:
64 return state;
65 }
66};