huridocs/uwazi

View on GitHub
app/react/Relationships/reducers/hubActionsReducer.js

Summary

Maintainability
A
0 mins
Test Coverage
F
42%
import { fromJS } from 'immutable';
import * as types from '../actions/actionTypes';

const initialState = {
  editing: false,
  saving: false,
  addTo: { hubIndex: null, rightRelationshipIndex: null },
};

export default function (state = initialState, action = {}) {
  switch (action.type) {
    case types.EDIT_RELATIONSHIPS:
      return state.set('editing', action.value);

    case types.SET_RELATIONSHIPS_ADD_TO_DATA:
      return state
        .setIn(['addTo', 'hubIndex'], action.index)
        .setIn(['addTo', 'rightRelationshipIndex'], action.rightIndex);

    case types.SAVING_RELATIONSHIPS:
      return state.set('saving', true);

    case types.SAVED_RELATIONSHIPS:
      return state.set('saving', false);

    default:
      return fromJS(state);
  }
}