Sha256: e9e93a55352cc02301157a70a97e029277bfed510be2331cb80a4d54f7cb3c98

Contents?: true

Size: 828 Bytes

Versions: 10

Compression:

Stored size: 828 Bytes

Contents

import { snakeCase } from 'lodash';
import { compose } from 'redux';
import {
  selectSort,
  selectPage,
  selectPerPage,
  selectSearch,
} from './WebhooksPageSelectors';

export const buildQuery = (query, state) => {
  const querySort = pickSort(query, state);

  return {
    page: query.page || selectPage(state),
    perPage: query.perPage || selectPerPage(state),
    searchQuery:
      query.searchQuery === undefined ? selectSearch(state) : query.searchQuery,
    ...(querySort && { sort: querySort }),
  };
};

export const pickSort = (query, state) =>
  checkSort(query.sort)
    ? transformSort(query.sort)
    : checkSort(compose(transformSort, selectSort)(state));

const checkSort = sort => (sort && sort.by && sort.order ? sort : undefined);

const transformSort = sort => ({ ...sort, by: snakeCase(sort.by) });

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
foreman_webhooks-2.0.3 webpack/ForemanWebhooks/Routes/Webhooks/WebhooksPageHelpers.js
foreman_webhooks-2.0.2 webpack/ForemanWebhooks/Routes/Webhooks/WebhooksPageHelpers.js
foreman_webhooks-2.0.1 webpack/ForemanWebhooks/Routes/Webhooks/WebhooksPageHelpers.js
foreman_webhooks-3.0.0 webpack/ForemanWebhooks/Routes/Webhooks/WebhooksPageHelpers.js
foreman_webhooks-2.0.0 webpack/ForemanWebhooks/Routes/Webhooks/WebhooksPageHelpers.js
foreman_webhooks-1.1.0 webpack/ForemanWebhooks/Routes/Webhooks/WebhooksPageHelpers.js
foreman_webhooks-1.0.0 webpack/ForemanWebhooks/Routes/Webhooks/WebhooksPageHelpers.js
foreman_webhooks-0.0.3 webpack/ForemanWebhooks/Routes/Webhooks/WebhooksPageHelpers.js
foreman_webhooks-0.0.2 webpack/ForemanWebhooks/Routes/Webhooks/WebhooksPageHelpers.js
foreman_webhooks-0.0.1 webpack/ForemanWebhooks/Routes/Webhooks/WebhooksPageHelpers.js