Sha256: e6563d6a8c86e1e1ba650550f9c16a18ef38ceb551b821e6078ae16a42950184

Contents?: true

Size: 1.23 KB

Versions: 4

Compression:

Stored size: 1.23 KB

Contents

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

import { buildQuery } from './WebhooksPageHelpers';
import {
  WEBHOOKS_API_PATH,
  WEBHOOKS_PATH,
  WEBHOOKS_API_REQUEST_KEY,
} from './constants';

export const initializeWebhooks = () => dispatch => {
  const params = getParams();
  dispatch(fetchWebhooks(params));
  if (!history.action === 'POP') {
    history.replace({
      pathname: WEBHOOKS_PATH,
      search: stringifyParams(params),
    });
  }
};

export const fetchWebhooks = (
  { page, perPage, searchQuery, sort },
  url = WEBHOOKS_API_PATH
) => async dispatch => {
  const sortString =
    sort && Object.keys(sort).length > 0 ? `${sort.by} ${sort.order}` : '';

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

export const fetchAndPush = (params = {}) => (dispatch, getState) => {
  const query = buildQuery(params, getState());
  dispatch(fetchWebhooks(query));
  history.push({
    pathname: WEBHOOKS_PATH,
    search: stringifyParams(query),
  });
};

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
foreman_webhooks-1.0.0 webpack/ForemanWebhooks/Routes/Webhooks/WebhooksPageActions.js
foreman_webhooks-0.0.3 webpack/ForemanWebhooks/Routes/Webhooks/WebhooksPageActions.js
foreman_webhooks-0.0.2 webpack/ForemanWebhooks/Routes/Webhooks/WebhooksPageActions.js
foreman_webhooks-0.0.1 webpack/ForemanWebhooks/Routes/Webhooks/WebhooksPageActions.js