Sha256: 8676b35204b520026a273591bffb14a481b403e7f0a5ee5274777d74f220e77e

Contents?: true

Size: 1.76 KB

Versions: 3

Compression:

Stored size: 1.76 KB

Contents

import { translate as __, sprintf } from 'foremanReact/common/I18n';
import { addToast } from 'foremanReact/redux/actions/toasts';
import { TASKS_DASHBOARD_JS_QUERY_MODES } from '../TasksDashboard/TasksDashboardConstants';
import { timeToHoursNumber } from '../TasksDashboard/TasksDashboardHelper';

export const convertDashboardQuery = query => {
  const {
    time_mode: timeMode,
    time_horizon: timeHorizon,
    state,
    result,
    search,
  } = query;

  const hours = timeToHoursNumber(timeHorizon);
  const timestamp = new Date(new Date() - hours * 60 * 60 * 1000);
  let dashboardTime = '';
  const stateQuery = state ? `state=${state}` : '';
  const resultQuery = result ? `result=${result}` : '';
  if (timeMode === TASKS_DASHBOARD_JS_QUERY_MODES.RECENT) {
    dashboardTime = `(state_updated_at>${timestamp.toISOString()} or state_updated_at = NULL)`;
  } else if (timeMode === TASKS_DASHBOARD_JS_QUERY_MODES.OLDER) {
    dashboardTime = `(state_updated_at>${timestamp.toISOString()})`;
  }
  const newQuery = [stateQuery, resultQuery, search, dashboardTime]
    .filter(Boolean)
    .join(' and ');
  return newQuery;
};

export const resumeToastInfo = {
  resumed: { type: 'success', text: __('was resumed') },
  failed: { type: 'error', text: __('could not be resumed') },
  skipped: { type: 'warning', text: __('task has to be resumable') },
};

export const cancelToastInfo = {
  cancelled: { type: 'success', text: __('was cancelled') },
  skipped: { type: 'warning', text: __('task has to be cancellable') },
};

export const toastDispatch = ({ type, name, toastInfo, dispatch }) => {
  dispatch(
    addToast({
      type: toastInfo[type].type,
      message: sprintf('%(name)s Task execution %(type)s', {
        name,
        type: toastInfo[type].text,
      }),
    })
  );
};

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
foreman-tasks-1.1.3 webpack/ForemanTasks/Components/TasksTable/TasksTableActionHelpers.js
foreman-tasks-1.1.2 webpack/ForemanTasks/Components/TasksTable/TasksTableActionHelpers.js
foreman-tasks-1.1.1 webpack/ForemanTasks/Components/TasksTable/TasksTableActionHelpers.js