Sha256: 7237aa0bb9e16c63fa6b4cf7a2a046dd280a3976f458512377ecdb337f87bfe8

Contents?: true

Size: 1.43 KB

Versions: 9

Compression:

Stored size: 1.43 KB

Contents

import { addToast } from 'foremanReact/components/ToastsList';
import { propsToSnakeCase } from 'foremanReact/common/helpers';
import { get } from 'foremanReact/redux/API';
import { stopInterval, withInterval } from 'foremanReact/redux/middlewares/IntervalMiddleware';
import { foremanTasksApi } from '../../services/api';
import { bulkSearchKey, pollTaskKey, taskFinishedToast } from './helpers';

export const toastTaskFinished = task => async (dispatch) => {
  dispatch(addToast(taskFinishedToast(task)));
};

const taskBulkSearchParams = params => ({
  search: Object.entries(propsToSnakeCase(params))
    .map((item) => {
      if (item[0] === 'action') {
        return `${item[0]}~${item[1]}`;
      }
      return `${item[0]}=${item[1]}`;
    })
    .join(' and '),
});

const getTasks = (key, params = {}) => get({
  key,
  url: `${foremanTasksApi.baseApiPath}/tasks`,
  params: taskBulkSearchParams(params),
});

export const startPollingTasks = (key, taskSearchParams = {}) =>
  withInterval(getTasks(bulkSearchKey(key), taskSearchParams));

export const stopPollingTasks = key => stopInterval(bulkSearchKey(key));

const getTask = (key, task, handleSuccess) => get({
  key,
  url: `${foremanTasksApi.baseApiPath}/tasks/${task.id}`,
  handleSuccess,
});

export const startPollingTask = (key, task, handleSuccess) =>
  withInterval(getTask(pollTaskKey(key), task, handleSuccess));

export const stopPollingTask = key => stopInterval(pollTaskKey(key));

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
katello-4.4.2.2 webpack/scenes/Tasks/TaskActions.js
katello-4.4.2.1 webpack/scenes/Tasks/TaskActions.js
katello-4.4.2 webpack/scenes/Tasks/TaskActions.js
katello-4.4.1 webpack/scenes/Tasks/TaskActions.js
katello-4.4.0.2 webpack/scenes/Tasks/TaskActions.js
katello-4.4.0.1 webpack/scenes/Tasks/TaskActions.js
katello-4.4.0 webpack/scenes/Tasks/TaskActions.js
katello-4.4.0.rc2 webpack/scenes/Tasks/TaskActions.js
katello-4.4.0.rc1 webpack/scenes/Tasks/TaskActions.js