Sha256: 6b7d5b4765f58a4f5fb1698ff0893783e486ff45f33c1cc81f1ae3c384ad47f1

Contents?: true

Size: 1.75 KB

Versions: 13

Compression:

Stored size: 1.75 KB

Contents

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 selectWebhookFormTemplatesResponse(state).results;
};

// Webhook events selectors
const selectWebhookFormEventsResponse = state =>
  deepPropsToCamelCase(
    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 selectWebhookFormEventsResponse(state);
};

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
foreman_webhooks-3.1.1 webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookForm/WebhookFormSelectors.js
foreman_webhooks-3.1.0 webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookForm/WebhookFormSelectors.js
foreman_webhooks-3.0.5 webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookForm/WebhookFormSelectors.js
foreman_webhooks-2.0.3 webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookForm/WebhookFormSelectors.js
foreman_webhooks-3.0.4 webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookForm/WebhookFormSelectors.js
foreman_webhooks-2.0.2 webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookForm/WebhookFormSelectors.js
foreman_webhooks-3.0.3 webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookForm/WebhookFormSelectors.js
foreman_webhooks-3.0.2 webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookForm/WebhookFormSelectors.js
foreman_webhooks-3.0.1 webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookForm/WebhookFormSelectors.js
foreman_webhooks-2.0.1 webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookForm/WebhookFormSelectors.js
foreman_webhooks-3.0.0 webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookForm/WebhookFormSelectors.js
foreman_webhooks-2.0.0 webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookForm/WebhookFormSelectors.js
foreman_webhooks-1.1.0 webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookForm/WebhookFormSelectors.js