Sha256: 43e9dd612895f4f2e4b7f4671af736e60ac5f8485148165f446ed9e32c8698e7

Contents?: true

Size: 1.65 KB

Versions: 15

Compression:

Stored size: 1.65 KB

Contents

import API from 'foremanReact/API';
import { timeToHoursNumber, resolveQuery } from './TasksDashboardHelper';
import {
  FOREMAN_TASKS_DASHBOARD_INIT,
  FOREMAN_TASKS_DASHBOARD_UPDATE_TIME,
  FOREMAN_TASKS_DASHBOARD_UPDATE_QUERY,
  TASKS_DASHBOARD_CURRENT_TIME,
  FOREMAN_TASKS_DASHBOARD_FETCH_TASKS_SUMMARY_REQUEST,
  FOREMAN_TASKS_DASHBOARD_FETCH_TASKS_SUMMARY_SUCCESS,
  FOREMAN_TASKS_DASHBOARD_FETCH_TASKS_SUMMARY_FAILURE,
} from './TasksDashboardConstants';
import { selectTime } from './TasksDashboardSelectors';

export const initializeDashboard = ({ time, query }) => ({
  type: FOREMAN_TASKS_DASHBOARD_INIT,
  payload: { time, query },
});

export const updateTime = time => ({
  type: FOREMAN_TASKS_DASHBOARD_UPDATE_TIME,
  payload: time,
});

export const updateQuery = query => (dispatch, getState) => {
  if (query.time === TASKS_DASHBOARD_CURRENT_TIME)
    query.time = selectTime(getState());

  dispatch({
    type: FOREMAN_TASKS_DASHBOARD_UPDATE_QUERY,
    payload: query,
  });

  resolveQuery(query);
};

export const fetchTasksSummary = time => async dispatch => {
  try {
    dispatch(startRequest());

    const hours = timeToHoursNumber(time);

    const { data } = await API.get(`/foreman_tasks/tasks/summary/${hours}`);

    return dispatch(requestSuccess(data));
  } catch (error) {
    return dispatch(requestFailure(error));
  }
};

const startRequest = () => ({
  type: FOREMAN_TASKS_DASHBOARD_FETCH_TASKS_SUMMARY_REQUEST,
});

const requestSuccess = data => ({
  type: FOREMAN_TASKS_DASHBOARD_FETCH_TASKS_SUMMARY_SUCCESS,
  payload: data,
});

const requestFailure = error => ({
  type: FOREMAN_TASKS_DASHBOARD_FETCH_TASKS_SUMMARY_FAILURE,
  payload: error,
});

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
foreman-tasks-0.16.3 webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardActions.js
foreman-tasks-0.15.11 webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardActions.js
foreman-tasks-0.16.2 webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardActions.js
foreman-tasks-0.15.10 webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardActions.js
foreman-tasks-0.16.1 webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardActions.js
foreman-tasks-0.17.0 webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardActions.js
foreman-tasks-0.15.9 webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardActions.js
foreman-tasks-0.15.8 webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardActions.js
foreman-tasks-0.15.7 webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardActions.js
foreman-tasks-0.16.0 webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardActions.js
foreman-tasks-0.15.6 webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardActions.js
foreman-tasks-0.15.5 webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardActions.js
foreman-tasks-0.15.4 webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardActions.js
foreman-tasks-0.15.3 webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardActions.js
foreman-tasks-0.15.2 webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardActions.js