Sha256: 46c81b9f4240cad2367395243bf03e222a03849a58ef68493b957116a441c79a

Contents?: true

Size: 1.55 KB

Versions: 54

Compression:

Stored size: 1.55 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));

export const clearPollTaskData = key => ({
  type: `${pollTaskKey(key)}_UPDATE`,
  key: pollTaskKey(key),
  payload: {},
});

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
katello-4.15.0.rc2 webpack/scenes/Tasks/TaskActions.js
katello-4.15.0.rc1 webpack/scenes/Tasks/TaskActions.js
katello-4.14.1 webpack/scenes/Tasks/TaskActions.js
katello-4.14.0 webpack/scenes/Tasks/TaskActions.js
katello-4.14.0.rc3 webpack/scenes/Tasks/TaskActions.js
katello-4.14.0.rc2 webpack/scenes/Tasks/TaskActions.js
katello-4.14.0.rc1.1 webpack/scenes/Tasks/TaskActions.js
katello-4.14.0.rc1 webpack/scenes/Tasks/TaskActions.js
katello-4.13.1 webpack/scenes/Tasks/TaskActions.js
katello-4.13.0 webpack/scenes/Tasks/TaskActions.js
katello-4.12.1 webpack/scenes/Tasks/TaskActions.js
katello-4.13.0.rc1 webpack/scenes/Tasks/TaskActions.js
katello-4.12.0 webpack/scenes/Tasks/TaskActions.js
katello-4.12.0.rc3 webpack/scenes/Tasks/TaskActions.js
katello-4.12.0.rc2 webpack/scenes/Tasks/TaskActions.js
katello-4.12.0.rc1 webpack/scenes/Tasks/TaskActions.js
katello-4.11.1 webpack/scenes/Tasks/TaskActions.js
katello-4.11.0 webpack/scenes/Tasks/TaskActions.js
katello-4.11.0.rc2 webpack/scenes/Tasks/TaskActions.js
katello-4.11.0.rc1 webpack/scenes/Tasks/TaskActions.js