fabric8-planner
Version:
A planner front-end for Fabric8.
104 lines • 4.68 kB
JavaScript
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
import { createEntityAdapter } from '@ngrx/entity';
import * as WorkItemActions from './../actions/work-item.actions';
import { initialState } from './../states/work-item.state';
var workItemAdapter = createEntityAdapter();
export var WorkItemReducer = function (state, action) {
if (state === void 0) { state = initialState; }
switch (action.type) {
case WorkItemActions.ADD_SUCCESS: {
var newState = __assign({}, state);
if (action.payload.parentID && state.entities[action.payload.parentID]) {
newState.entities[action.payload.parentID].hasChildren = true;
newState.entities[action.payload.parentID].childrenLoaded = true;
newState.entities[action.payload.parentID].treeStatus = 'expanded';
}
return __assign({ nextLink: newState.nextLink }, workItemAdapter.addOne(action.payload, {
ids: newState.ids,
entities: newState.entities
}));
}
case WorkItemActions.ADD_ERROR: {
return state;
}
case WorkItemActions.GET_SUCCESS: {
return __assign({}, workItemAdapter.addMany(action.payload.workItems, workItemAdapter.removeAll(state)), { nextLink: action.payload.nextLink });
}
case WorkItemActions.GET_MORE_WORKITEMS_SUCCESS: {
return __assign({}, workItemAdapter.addMany(action.payload.workItems, state), { nextLink: action.payload.nextLink });
}
case WorkItemActions.GET_ERROR: {
return state;
}
case WorkItemActions.GET_CHILDREN_ERROR: {
state.entities[action.payload.id].treeStatus = 'collapsed';
return __assign({}, state);
}
case WorkItemActions.GET_CHILDREN_SUCCESS: {
var newSTate = workItemAdapter.addMany(action.payload.children, state);
if (newSTate.entities[action.payload.parent.id]) {
newSTate.entities[action.payload.parent.id].childrenLoaded = true;
newSTate.entities[action.payload.parent.id].treeStatus = 'expanded';
}
return __assign({}, newSTate);
}
case WorkItemActions.UPDATE_SUCCESS: {
return workItemAdapter.updateOne({
id: action.payload.id,
changes: action.payload
}, state);
}
case WorkItemActions.UPDATE_ERROR: {
return __assign({}, state);
}
case WorkItemActions.CREATE_LINK: {
var newState = __assign({}, state);
if (action.payload.sourceTreeStatus === 'expanded') {
if (newState.entities[action.payload.target.id]) {
newState.entities[action.payload.target.id].parentID = action.payload.source.id;
}
}
else if (action.payload.sourceTreeStatus === 'disabled') {
if (newState.entities[action.payload.target.id] &&
newState.entities[action.payload.source.id]) {
newState.entities[action.payload.source.id].hasChildren = true;
newState.entities[action.payload.source.id].treeStatus = 'collapsed';
newState = __assign({ nextLink: newState.nextLink }, workItemAdapter.removeOne(action.payload.target.id, {
ids: newState.ids,
entities: newState.entities
}));
}
}
return __assign({}, newState);
}
case WorkItemActions.DELETE_LINK: {
if (action.payload.target) {
state.entities[action.payload.target.id].parentID = '';
}
return __assign({}, state);
}
case WorkItemActions.RESET_WORKITEMS: {
return workItemAdapter.removeAll(state);
}
case WorkItemActions.DELETE_SUCCESS: {
var newState = __assign({}, state);
var deletedWorkItem = action.payload;
newState = __assign({ nextLink: newState.nextLink }, workItemAdapter.removeOne(deletedWorkItem.id, newState));
return __assign({}, newState);
}
case WorkItemActions.DELETE_ERROR: {
return __assign({}, state);
}
default: {
return state;
}
}
};
//# sourceMappingURL=work-item.reducer.js.map