Sha256: b0b0c7f7c3268544d4834b8e4be7085829c798723ab9a2e73e4515335467dc01

Contents?: true

Size: 1.08 KB

Versions: 24

Compression:

Stored size: 1.08 KB

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, hostSearch) => dispatch => {
  const url = foremanUrl(
    hostId
      ? `/job_invocations?feature=${feature}&host_ids%5B%5D=${hostId}`
      : `/job_invocations?feature=${feature}&search=${hostSearch}`
  );
  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

24 entries across 24 versions & 1 rubygems

Version Path
foreman_remote_execution-13.2.7 webpack/react_app/components/FeaturesDropdown/actions.js
foreman_remote_execution-15.0.0 webpack/react_app/components/FeaturesDropdown/actions.js
foreman_remote_execution-14.1.4 webpack/react_app/components/FeaturesDropdown/actions.js
foreman_remote_execution-14.1.3 webpack/react_app/components/FeaturesDropdown/actions.js
foreman_remote_execution-14.1.2 webpack/react_app/components/FeaturesDropdown/actions.js
foreman_remote_execution-14.1.1 webpack/react_app/components/FeaturesDropdown/actions.js
foreman_remote_execution-14.1.0 webpack/react_app/components/FeaturesDropdown/actions.js
foreman_remote_execution-14.0.2 webpack/react_app/components/FeaturesDropdown/actions.js
foreman_remote_execution-14.0.1 webpack/react_app/components/FeaturesDropdown/actions.js
foreman_remote_execution-13.2.6 webpack/react_app/components/FeaturesDropdown/actions.js
foreman_remote_execution-14.0.0 webpack/react_app/components/FeaturesDropdown/actions.js
foreman_remote_execution-13.2.5 webpack/react_app/components/FeaturesDropdown/actions.js
foreman_remote_execution-13.2.4 webpack/react_app/components/FeaturesDropdown/actions.js
foreman_remote_execution-13.2.3 webpack/react_app/components/FeaturesDropdown/actions.js
foreman_remote_execution-13.2.2 webpack/react_app/components/FeaturesDropdown/actions.js
foreman_remote_execution-12.0.7 webpack/react_app/components/FeaturesDropdown/actions.js
foreman_remote_execution-13.2.1 webpack/react_app/components/FeaturesDropdown/actions.js
foreman_remote_execution-13.2.0 webpack/react_app/components/FeaturesDropdown/actions.js
foreman_remote_execution-13.0.0 webpack/react_app/components/FeaturesDropdown/actions.js
foreman_remote_execution-12.0.5 webpack/react_app/components/FeaturesDropdown/actions.js