Sha256: 509d2fd6264fac1620da9ae2f9c1d0d4436ffffa2a645d3244035d17e9a65160

Contents?: true

Size: 1015 Bytes

Versions: 27

Compression:

Stored size: 1015 Bytes

Contents

import { foremanUrl } from 'foremanReact/common/helpers';
import { sprintf, translate as __ } from 'foremanReact/common/I18n';
import { post } from 'foremanReact/redux/API';

export const runFeature = (hostId, feature, label) => dispatch => {
  const url = foremanUrl(
    `/job_invocations?feature=${feature}&host_ids%5B%5D=${hostId}`
  );
  const redirectUrl = 'job_invocations/new';

  const successToast = ({ request }) => {
    if (request.responseURL.includes(redirectUrl)) {
      return __('Opening job invocation form');
    }
    return sprintf(__('%s job has been invoked'), label);
  };
  const errorToast = ({ message }) => message;
  dispatch(
    post({
      key: feature.toUpperCase(),
      url,
      successToast,
      errorToast,
      handleSuccess: ({ request }) => {
        if (request.responseURL.includes(redirectUrl)) {
          // checking if user should be redicted to finish setting up the job
          window.location.href = request.responseURL;
        }
      },
    })
  );
};

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
foreman_remote_execution-10.1.3 webpack/react_app/components/FeaturesDropdown/actions.js
foreman_remote_execution-11.1.3 webpack/react_app/components/FeaturesDropdown/actions.js
foreman_remote_execution-10.1.2 webpack/react_app/components/FeaturesDropdown/actions.js
foreman_remote_execution-10.1.1 webpack/react_app/components/FeaturesDropdown/actions.js
foreman_remote_execution-11.1.1 webpack/react_app/components/FeaturesDropdown/actions.js
foreman_remote_execution-11.1.0 webpack/react_app/components/FeaturesDropdown/actions.js
foreman_remote_execution-10.1.0 webpack/react_app/components/FeaturesDropdown/actions.js
foreman_remote_execution-8.3.3 webpack/react_app/components/FeaturesDropdown/actions.js
foreman_remote_execution-8.3.2 webpack/react_app/components/FeaturesDropdown/actions.js
foreman_remote_execution-11.0.0 webpack/react_app/components/FeaturesDropdown/actions.js
foreman_remote_execution-10.0.7 webpack/react_app/components/FeaturesDropdown/actions.js
foreman_remote_execution-8.3.1 webpack/react_app/components/FeaturesDropdown/actions.js
foreman_remote_execution-10.0.6 webpack/react_app/components/FeaturesDropdown/actions.js
foreman_remote_execution-10.0.5 webpack/react_app/components/FeaturesDropdown/actions.js
foreman_remote_execution-10.0.4 webpack/react_app/components/FeaturesDropdown/actions.js
foreman_remote_execution-10.0.3 webpack/react_app/components/FeaturesDropdown/actions.js
foreman_remote_execution-10.0.2 webpack/react_app/components/FeaturesDropdown/actions.js
foreman_remote_execution-10.0.1 webpack/react_app/components/FeaturesDropdown/actions.js
foreman_remote_execution-10.0.0 webpack/react_app/components/FeaturesDropdown/actions.js
foreman_remote_execution-8.3.0 webpack/react_app/components/FeaturesDropdown/actions.js