Sha256: 2384d196f4b9e77ae2948ce9c837ef9d8f8c9e1cf56dcc5c02ff28c900bae00b

Contents?: true

Size: 1.84 KB

Versions: 34

Compression:

Stored size: 1.84 KB

Contents

import Immutable from 'seamless-immutable';

import {
  ANSIBLE_ROLES_REQUEST,
  ANSIBLE_ROLES_SUCCESS,
  ANSIBLE_ROLES_FAILURE,
  ANSIBLE_ROLES_ADD,
  ANSIBLE_ROLES_REMOVE,
  ANSIBLE_ROLES_ASSIGNED_PAGE_CHANGE,
} from './AnsibleRolesSwitcherConstants';

export const initialState = Immutable({
  loading: false,
  itemCount: 0,
  pagination: {
    page: 1,
    perPage: 10,
  },
  assignedRoles: [],
  inheritedRoleIds: [],
  results: [],
  assignedPagination: {
    page: 1,
    perPage: 10,
  },
  error: { errorMsg: '', status: '', statusText: '' },
});

const ansibleRoles = (state = initialState, action) => {
  const { payload } = action;

  switch (action.type) {
    case ANSIBLE_ROLES_REQUEST:
      return state.set('loading', true);
    case ANSIBLE_ROLES_SUCCESS:
      return state.merge({
        loading: false,
        itemCount: Number(payload.subtotal),
        pagination: {
          page: Number(payload.page),
          perPage: Number(payload.perPage),
        },
        results: payload.results,
        assignedRoles: payload.initialAssignedRoles,
        inheritedRoleIds: payload.inheritedRoleIds,
      });
    case ANSIBLE_ROLES_FAILURE:
      return state.merge({ error: payload.error, loading: false });
    case ANSIBLE_ROLES_ADD:
      return state.merge({
        assignedRoles: state.assignedRoles.concat([payload.role]),
        itemCount: state.itemCount - 1,
      });
    case ANSIBLE_ROLES_REMOVE:
      return state.merge({
        assignedRoles: Immutable.flatMap(state.assignedRoles, item =>
          item.id === payload.role.id ? [] : item
        ),
        results: state.results.concat([payload.role]),
        itemCount: state.itemCount + 1,
      });
    case ANSIBLE_ROLES_ASSIGNED_PAGE_CHANGE:
      return state.set('assignedPagination', payload.pagination);
    default:
      return state;
  }
};

export default ansibleRoles;

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
foreman_ansible-6.2.0 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherReducer.js
foreman_ansible-6.1.1 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherReducer.js
foreman_ansible-6.0.2 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherReducer.js
foreman_ansible-6.1.0 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherReducer.js
foreman_ansible-6.0.1 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherReducer.js
foreman_ansible-5.1.3 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherReducer.js
foreman_ansible-6.0.0 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherReducer.js
foreman_ansible-5.1.2 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherReducer.js
foreman_ansible-5.1.1 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherReducer.js
foreman_ansible-5.1.0 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherReducer.js
foreman_ansible-4.0.3.5 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherReducer.js
foreman_ansible-4.0.3.4 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherReducer.js
foreman_ansible-4.0.3.3 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherReducer.js
foreman_ansible-4.0.3.2 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherReducer.js
foreman_ansible-5.0.1 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherReducer.js
foreman_ansible-4.0.5 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherReducer.js
foreman_ansible-4.0.3.1 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherReducer.js
foreman_ansible-4.0.4 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherReducer.js
foreman_ansible-5.0.0 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherReducer.js
foreman_ansible-4.0.3 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherReducer.js