Sha256: 1de9852f7fc750d43208101f2e80e24242ac9e45f075a793ffd5531510e7df29

Contents?: true

Size: 1.58 KB

Versions: 68

Compression:

Stored size: 1.58 KB

Contents

import { getURIQuery } from 'foremanReact/common/helpers';

import {
  TASKS_DASHBOARD_AVAILABLE_TIMES,
  TASKS_DASHBOARD_QUERY_KEYS_TEXT,
  TASKS_DASHBOARD_QUERY_VALUES_TEXT,
  TASKS_DASHBOARD_JS_QUERY_MODES,
} from './TasksDashboardConstants';
import { updateURlQuery } from '../TasksTable/TasksTableHelpers';

export const getQueryKeyText = key => TASKS_DASHBOARD_QUERY_KEYS_TEXT[key];

export const getQueryValueText = value =>
  TASKS_DASHBOARD_QUERY_VALUES_TEXT[value];

export const timeToHoursNumber = time => {
  switch (time) {
    case TASKS_DASHBOARD_AVAILABLE_TIMES.H12:
      return 12;
    case TASKS_DASHBOARD_AVAILABLE_TIMES.H24:
      return 24;
    case TASKS_DASHBOARD_AVAILABLE_TIMES.WEEK:
      return 24 * 7;
    default:
      return 24;
  }
};

const uriToQueryMap = {
  state: 'state',
  result: 'result',
  time_mode: 'mode',
  time_horizon: 'time',
};

const queryFromUriQuery = uriQuery => {
  const query = {};

  Object.entries(uriToQueryMap).forEach(([uriField, queryField]) => {
    if (uriQuery[uriField]) query[queryField] = uriQuery[uriField];
  });

  if (query.mode === TASKS_DASHBOARD_JS_QUERY_MODES.RECENT) {
    query.mode = TASKS_DASHBOARD_QUERY_VALUES_TEXT.LAST;
  }

  return query;
};

export const getQueryFromUrl = () => {
  const uriQuery = getURIQuery(window.location.href);

  return queryFromUriQuery(uriQuery);
};

export const resolveQuery = ({ state, result, mode, time }, history) => {
  const uriQuery = {
    state,
    result,
    time_mode: mode === 'last' ? 'recent' : mode,
    time_horizon: time,
    page: 1,
  };
  updateURlQuery(uriQuery, history);
};

Version data entries

68 entries across 68 versions & 1 rubygems

Version Path
foreman-tasks-10.0.2 webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardHelper.js
foreman-tasks-10.0.1 webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardHelper.js
foreman-tasks-10.0.0 webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardHelper.js
foreman-tasks-9.2.3 webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardHelper.js
foreman-tasks-9.2.2 webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardHelper.js
foreman-tasks-9.2.1 webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardHelper.js
foreman-tasks-9.2.0 webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardHelper.js
foreman-tasks-9.1.1 webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardHelper.js
foreman-tasks-9.0.4 webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardHelper.js
foreman-tasks-9.1.0 webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardHelper.js
foreman-tasks-9.0.2 webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardHelper.js
foreman-tasks-9.0.1 webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardHelper.js
foreman-tasks-8.3.3 webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardHelper.js
foreman-tasks-9.0.0 webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardHelper.js
foreman-tasks-8.2.1 webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardHelper.js
foreman-tasks-8.1.4 webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardHelper.js
foreman-tasks-8.3.2 webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardHelper.js
foreman-tasks-8.3.1 webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardHelper.js
foreman-tasks-8.1.3 webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardHelper.js
foreman-tasks-8.3.0 webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardHelper.js