2016-03-24 05:26:04 +00:00
|
|
|
import * as types from "../constants/actionTypes";
|
|
|
|
|
|
|
|
const initialState = {
|
2016-04-04 07:15:30 +00:00
|
|
|
all: []
|
2016-03-24 05:26:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function requestGroupsReducer (state = [], action) {
|
|
|
|
switch (action.type) {
|
2016-04-04 07:15:30 +00:00
|
|
|
|
2016-03-24 05:26:04 +00:00
|
|
|
case types.REQUEST_GROUP_UPDATE:
|
2016-04-16 23:24:57 +00:00
|
|
|
const requestGroup = state.find(r => r._id === action.requestGroup._id);
|
|
|
|
if (requestGroup) {
|
|
|
|
return state.map(requestGroup => {
|
|
|
|
if (requestGroup._id === action.requestGroup._id) {
|
|
|
|
return Object.assign({}, requestGroup, action.requestGroup);
|
|
|
|
} else {
|
|
|
|
return requestGroup;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return [action.requestGroup, ...state];
|
|
|
|
}
|
2016-04-04 07:15:30 +00:00
|
|
|
|
|
|
|
case types.REQUEST_GROUP_TOGGLE:
|
|
|
|
return state.map(rg => {
|
2016-04-16 23:24:57 +00:00
|
|
|
if (rg._id === action._id) {
|
2016-04-04 07:15:30 +00:00
|
|
|
const collapsed = !rg.collapsed;
|
|
|
|
return Object.assign({}, rg, {collapsed});
|
2016-03-24 05:26:04 +00:00
|
|
|
} else {
|
2016-04-04 07:15:30 +00:00
|
|
|
return rg;
|
2016-03-24 05:26:04 +00:00
|
|
|
}
|
|
|
|
});
|
2016-04-04 07:15:30 +00:00
|
|
|
|
2016-04-07 03:09:14 +00:00
|
|
|
case types.REQUEST_GROUP_DELETE:
|
2016-04-16 23:24:57 +00:00
|
|
|
return state.filter(rg => rg._id !== action.requestGroup._id);
|
2016-04-07 03:09:14 +00:00
|
|
|
|
2016-03-24 05:26:04 +00:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function (state = initialState, action) {
|
2016-04-05 06:08:03 +00:00
|
|
|
let all;
|
2016-03-24 05:26:04 +00:00
|
|
|
switch (action.type) {
|
2016-04-04 07:15:30 +00:00
|
|
|
|
2016-04-05 06:08:03 +00:00
|
|
|
case types.REQUEST_GROUP_ADD_CHILD_REQUEST:
|
|
|
|
all = requestGroupsReducer(state.all, action);
|
2016-04-04 07:15:30 +00:00
|
|
|
return Object.assign({}, state, {all});
|
|
|
|
|
2016-03-24 05:26:04 +00:00
|
|
|
case types.REQUEST_GROUP_TOGGLE:
|
2016-04-05 06:08:03 +00:00
|
|
|
all = requestGroupsReducer(state.all, action);
|
2016-04-04 07:15:30 +00:00
|
|
|
return Object.assign({}, state, {all});
|
|
|
|
|
2016-03-24 05:26:04 +00:00
|
|
|
case types.REQUEST_GROUP_UPDATE:
|
2016-04-05 06:08:03 +00:00
|
|
|
all = requestGroupsReducer(state.all, action);
|
2016-03-24 05:26:04 +00:00
|
|
|
return Object.assign({}, state, {all});
|
2016-04-07 03:09:14 +00:00
|
|
|
|
|
|
|
case types.REQUEST_GROUP_DELETE:
|
|
|
|
all = requestGroupsReducer(state.all, action);
|
|
|
|
return Object.assign({}, state, {all});
|
|
|
|
|
2016-03-24 05:26:04 +00:00
|
|
|
default:
|
|
|
|
return state
|
|
|
|
}
|
|
|
|
}
|