Sha256: e77f2345746a2e79a98b8e69ff0cb186d91112fbbdf6b50893b626a58a36422d

Contents?: true

Size: 1.8 KB

Versions: 5

Compression:

Stored size: 1.8 KB

Contents

import Immutable from 'seamless-immutable';
import { STATUS } from 'foremanReact/constants';
import { deepPropsToCamelCase } from 'foremanReact/common/helpers';
import {
  selectAPIStatus,
  selectAPIResponse,
} from 'foremanReact/redux/API/APISelectors';

import {
  WEBHOOK_TEMPLATES_API_REQUEST_KEY,
  WEBHOOK_EVENTS_API_REQUEST_KEY,
} from '../../constants';

// Webhook templates selectors
const selectWebhookFormTemplatesResponse = state =>
  deepPropsToCamelCase(
    selectAPIResponse(state, WEBHOOK_TEMPLATES_API_REQUEST_KEY)
  );

const selectWebhookFormTemplatesStatus = state =>
  selectAPIStatus(state, WEBHOOK_TEMPLATES_API_REQUEST_KEY);

export const selectTemplatesHasError = state =>
  selectWebhookFormTemplatesStatus(state) === STATUS.ERROR;

export const selectTemplatesIsLoading = state => {
  const status = selectWebhookFormTemplatesStatus(state);
  return !status || status === STATUS.PENDING;
};

export const selectWebhookTemplates = state => {
  if (selectTemplatesHasError(state) || selectTemplatesIsLoading(state))
    return [];

  return Immutable.asMutable(selectWebhookFormTemplatesResponse(state).results);
};

// Webhook events selectors
const selectWebhookFormEventsResponse = state =>
  selectAPIResponse(state, WEBHOOK_EVENTS_API_REQUEST_KEY);

const selectWebhookFormEventsStatus = state =>
  selectAPIStatus(state, WEBHOOK_EVENTS_API_REQUEST_KEY);

export const selectEventsHasError = state =>
  selectWebhookFormEventsStatus(state) === STATUS.ERROR;

export const selectEventsIsLoading = state => {
  const status = selectWebhookFormEventsStatus(state);
  return !status || status === STATUS.PENDING;
};

export const selectWebhookEvents = state => {
  if (selectEventsHasError(state) || selectEventsIsLoading(state)) return [];

  return Immutable.asMutable(selectWebhookFormEventsResponse(state));
};

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
foreman_webhooks-4.0.0 webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookForm/WebhookFormSelectors.js
foreman_webhooks-3.2.3 webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookForm/WebhookFormSelectors.js
foreman_webhooks-3.2.2 webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookForm/WebhookFormSelectors.js
foreman_webhooks-3.2.1 webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookForm/WebhookFormSelectors.js
foreman_webhooks-3.2.0 webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookForm/WebhookFormSelectors.js