Sha256: d8eb69a289a41449d7086d35e9bec1c3b6de76885787e0ec5eb940bb4b59ce60

Contents?: true

Size: 1.32 KB

Versions: 58

Compression:

Stored size: 1.32 KB

Contents

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

export const formatError = error =>
  sprintf(
    __(
      'There was a following error when changing Ansible variable override: %s'
    ),
    error
  );

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

export const onCompleted = (
  dataPath,
  onValidationError,
  toggleWorking,
  onSubmitSuccess
) => data => {
  const { errors, overridenAnsibleVariable } = data[dataPath];
  if (Array.isArray(errors) && errors.length > 0) {
    if (
      errors.length === 1 &&
      errors[0].path.join(' ') === 'attributes value'
    ) {
      onValidationError(errors[0].message);
    } else {
      toggleWorking(false);
      showToast({
        type: 'error',
        message: formatError(joinErrors(errors)),
      });
    }
  } else {
    onSubmitSuccess(overridenAnsibleVariable.currentValue.value);
    showToast({
      type: 'success',
      message: __('Ansible variable override successfully changed.'),
    });
  }
};

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

export const hasError = state => state.validation.key === 'error';
export const createMatcher = value => `fqdn=${value}`;

Version data entries

58 entries across 58 versions & 1 rubygems

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