Sha256: 46f779cb5326b3d08b42da356b1679d85244967123179dd9dbc4cc0c1489a5a2

Contents?: true

Size: 1.42 KB

Versions: 3

Compression:

Stored size: 1.42 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({ per_page: params.perPage, ...params }));
  if (!history.action === 'POP') {
    history.replace({
      pathname: WEBHOOKS_PATH,
      search: stringifyParams(params),
    });
  }
};

export const fetchWebhooks = (
  /* eslint-disable-next-line camelcase */
  { page, per_page, 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,
        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({ perPage: query.per_page, ...query }),
  });
};

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
foreman_webhooks-3.0.3 webpack/ForemanWebhooks/Routes/Webhooks/WebhooksPageActions.js
foreman_webhooks-3.0.2 webpack/ForemanWebhooks/Routes/Webhooks/WebhooksPageActions.js
foreman_webhooks-3.0.1 webpack/ForemanWebhooks/Routes/Webhooks/WebhooksPageActions.js