Sha256: 2d0bce960957cbe9c49b97dbfb9f72977a42a6163b6348ddf35d56754f9e1c98

Contents?: true

Size: 1.7 KB

Versions: 25

Compression:

Stored size: 1.7 KB

Contents

import api from 'foremanReact/API';
import {
  propsToSnakeCase,
  propsToCamelCase,
} from 'foremanReact/common/helpers';
import { translate as __ } from 'foremanReact/common/I18n';

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

export const getAnsibleRoles = (
  url,
  initialAssignedRoles,
  inheritedRoleIds,
  resourceId,
  resourceName,
  pagination,
  search
) => async dispatch => {
  dispatch({ type: ANSIBLE_ROLES_REQUEST });

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

  try {
    const res = await api.get(url, {}, params);
    return dispatch({
      type: ANSIBLE_ROLES_SUCCESS,
      payload: {
        initialAssignedRoles,
        inheritedRoleIds,
        ...propsToCamelCase(res.data),
      },
    });
  } catch (error) {
    return 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 moveAnsibleRole = roles => ({
  type: ANSIBLE_ROLES_MOVE,
  payload: { roles },
});

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

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
foreman_ansible-15.0.6 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherActions.js
foreman_ansible-14.2.3 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherActions.js
foreman_ansible-15.0.5 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherActions.js
foreman_ansible-15.0.4 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherActions.js
foreman_ansible-15.0.3 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherActions.js
foreman_ansible-15.0.2 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherActions.js
foreman_ansible-15.0.1 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherActions.js
foreman_ansible-15.0.0 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherActions.js
foreman_ansible-14.2.2 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherActions.js
foreman_ansible-14.2.1 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherActions.js
foreman_ansible-13.0.7 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherActions.js
foreman_ansible-14.2.0 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherActions.js
foreman_ansible-14.1.1 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherActions.js
foreman_ansible-14.1.0 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherActions.js
foreman_ansible-13.0.5 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherActions.js
foreman_ansible-14.0.0 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherActions.js
foreman_ansible-13.0.4 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherActions.js
foreman_ansible-13.0.3 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherActions.js
foreman_ansible-13.0.2 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherActions.js
foreman_ansible-13.0.1 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherActions.js