Sha256: 51741bf196becdad6135faf1c42555f39fbcd75c11b50eefd652dd954c540792

Contents?: true

Size: 1.51 KB

Versions: 33

Compression:

Stored size: 1.51 KB

Contents

import api from 'foremanReact/API';
import {
  propsToSnakeCase,
  propsToCamelCase,
} from 'foremanReact/common/helpers';

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 getAnsibleRoles = (
  url,
  initialAssignedRoles,
  inheritedRoleIds,
  resourceId,
  resourceName,
  pagination,
  search
) => dispatch => {
  dispatch({ type: ANSIBLE_ROLES_REQUEST });

  const params = {
    ...propsToSnakeCase(pagination || {}),
    ...(search || {}),
    ...propsToSnakeCase({ resourceId, resourceName }),
  };

  return api
    .get(url, {}, params)
    .then(({ data }) =>
      dispatch({
        type: ANSIBLE_ROLES_SUCCESS,
        payload: {
          initialAssignedRoles,
          inheritedRoleIds,
          ...propsToCamelCase(data),
        },
      })
    )
    .catch(error => dispatch(errorHandler(ANSIBLE_ROLES_FAILURE, error)));
};

const errorHandler = (msg, err) => {
  const error = {
    errorMsg: 'Failed to fetch Ansible Roles from server.',
    statusText: err.response.statusText,
  };
  return { type: msg, payload: { error } };
};

export const addAnsibleRole = role => ({
  type: ANSIBLE_ROLES_ADD,
  payload: { role },
});

export const removeAnsibleRole = role => ({
  type: ANSIBLE_ROLES_REMOVE,
  payload: { role },
});

export const changeAssignedPage = pagination => ({
  type: ANSIBLE_ROLES_ASSIGNED_PAGE_CHANGE,
  payload: { pagination },
});

Version data entries

33 entries across 33 versions & 1 rubygems

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