Sha256: 5233be9810ab3ebfabfe4e8b5eb1885217b665d3b0065b9f594fda0ec6f2f23e

Contents?: true

Size: 1.08 KB

Versions: 58

Compression:

Stored size: 1.08 KB

Contents

import { sprintf, translate as __ } from 'foremanReact/common/I18n';
import { decodeModelId } from '../../../../../globalIdHelper';
import { showToast } from '../../../../../toastHelper';

export const roleNamesToIds = (roles, names) =>
  names.reduce((memo, name) => {
    const role = roles.find(item => item.name === name);
    if (role) {
      memo.push(decodeModelId(role));
    }
    return memo;
  }, []);

const joinErrors = errors => errors.map(err => err.message).join(', ');

const formatError = error =>
  sprintf(
    __('There was a following error when assigning Ansible Roles: %s'),
    error
  );

export const onCompleted = closeModal => data => {
  const { errors } = data.assignAnsibleRoles;
  if (Array.isArray(errors) && errors.length > 0) {
    showToast({
      type: 'error',
      message: formatError(joinErrors(errors)),
    });
  } else {
    closeModal();
    showToast({
      type: 'success',
      message: __('Ansible Roles were successfully assigned.'),
    });
  }
};

export const onError = error => {
  showToast({ type: 'error', message: formatError(error) });
};

Version data entries

58 entries across 58 versions & 1 rubygems

Version Path
foreman_ansible-15.0.2 webpack/components/AnsibleHostDetail/components/RolesTab/EditRolesModal/EditRolesModalHelper.js
foreman_ansible-15.0.1 webpack/components/AnsibleHostDetail/components/RolesTab/EditRolesModal/EditRolesModalHelper.js
foreman_ansible-15.0.0 webpack/components/AnsibleHostDetail/components/RolesTab/EditRolesModal/EditRolesModalHelper.js
foreman_ansible-14.2.2 webpack/components/AnsibleHostDetail/components/RolesTab/EditRolesModal/EditRolesModalHelper.js
foreman_ansible-14.2.1 webpack/components/AnsibleHostDetail/components/RolesTab/EditRolesModal/EditRolesModalHelper.js
foreman_ansible-13.0.7 webpack/components/AnsibleHostDetail/components/RolesTab/EditRolesModal/EditRolesModalHelper.js
foreman_ansible-14.2.0 webpack/components/AnsibleHostDetail/components/RolesTab/EditRolesModal/EditRolesModalHelper.js
foreman_ansible-14.1.1 webpack/components/AnsibleHostDetail/components/RolesTab/EditRolesModal/EditRolesModalHelper.js
foreman_ansible-14.1.0 webpack/components/AnsibleHostDetail/components/RolesTab/EditRolesModal/EditRolesModalHelper.js
foreman_ansible-13.0.5 webpack/components/AnsibleHostDetail/components/RolesTab/EditRolesModal/EditRolesModalHelper.js
foreman_ansible-14.0.0 webpack/components/AnsibleHostDetail/components/RolesTab/EditRolesModal/EditRolesModalHelper.js
foreman_ansible-13.0.4 webpack/components/AnsibleHostDetail/components/RolesTab/EditRolesModal/EditRolesModalHelper.js
foreman_ansible-13.0.3 webpack/components/AnsibleHostDetail/components/RolesTab/EditRolesModal/EditRolesModalHelper.js
foreman_ansible-13.0.2 webpack/components/AnsibleHostDetail/components/RolesTab/EditRolesModal/EditRolesModalHelper.js
foreman_ansible-13.0.1 webpack/components/AnsibleHostDetail/components/RolesTab/EditRolesModal/EditRolesModalHelper.js
foreman_ansible-13.0.0 webpack/components/AnsibleHostDetail/components/RolesTab/EditRolesModal/EditRolesModalHelper.js
foreman_ansible-12.0.7 webpack/components/AnsibleHostDetail/components/RolesTab/EditRolesModal/EditRolesModalHelper.js
foreman_ansible-10.4.4 webpack/components/AnsibleHostDetail/components/RolesTab/EditRolesModal/EditRolesModalHelper.js
foreman_ansible-7.1.8 webpack/components/AnsibleHostDetail/components/RolesTab/EditRolesModal/EditRolesModalHelper.js
foreman_ansible-12.0.6 webpack/components/AnsibleHostDetail/components/RolesTab/EditRolesModal/EditRolesModalHelper.js