Sha256: 959cd3fb0a2d0290dbcb3646e38b9cebdc0085abfad1b08b61a54664d3fa4c41

Contents?: true

Size: 1.48 KB

Versions: 3

Compression:

Stored size: 1.48 KB

Contents

import history from 'foremanReact/history';
import { get } from 'foremanReact/redux/API';
import { stringifyParams, getParams } from 'foremanReact/common/urlHelpers';

import { buildQuery } from './IndexPageHelpers';
import {
  HOST_REPORTS_API_PATH,
  HOST_REPORTS_PATH,
  HOST_REPORTS_API_REQUEST_KEY,
} from './constants';

export const initializeHostReports = () => dispatch => {
  const params = getParams();
  dispatch(fetchHostReports({ per_page: params.perPage, ...params }));
  if (!history.action === 'POP') {
    history.replace({
      pathname: HOST_REPORTS_PATH,
      search: stringifyParams(params),
    });
  }
};

export const fetchHostReports = (
  /* eslint-disable-next-line camelcase */
  { page, per_page, searchQuery, sort },
  url = HOST_REPORTS_API_PATH
) => async dispatch => {
  const sortString =
    sort && Object.keys(sort).length > 0 ? `${sort.by} ${sort.order}` : '';

  return dispatch(
    get({
      key: HOST_REPORTS_API_REQUEST_KEY,
      url,
      params: {
        page,
        per_page,
        search: searchQuery,
        order: sortString,
      },
    })
  );
};

export const fetchAndPush = (params = {}) => (dispatch, getState) => {
  const query = buildQuery(params, getState());
  dispatch(fetchHostReports(query));
  history.push({
    pathname: HOST_REPORTS_PATH,
    search: stringifyParams({ perPage: query.per_page, ...query }),
  });
};

export const reloadWithSearch = query => dispatch => {
  dispatch(fetchAndPush({ searchQuery: query, page: 1 }));
};

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
foreman_host_reports-1.0.2 webpack/src/Router/HostReports/IndexPage/IndexPageActions.js
foreman_host_reports-1.0.1 webpack/src/Router/HostReports/IndexPage/IndexPageActions.js
foreman_host_reports-1.0.0 webpack/src/Router/HostReports/IndexPage/IndexPageActions.js