Sha256: f5fe353c74e1c194e6939fd70ae9b69a0bdb1d583e94cfde6ae6f777e0e3b96b

Contents?: true

Size: 1.51 KB

Versions: 65

Compression:

Stored size: 1.51 KB

Contents

import { differenceBy, includes } from 'lodash';
import Immutable from 'seamless-immutable';
import { createSelector } from 'reselect';
import { propsToCamelCase } from 'foremanReact/common/helpers';

const switcherState = state => state.foremanAnsible.ansibleRolesSwitcher;

const markInheritedRoles = (roles, inheritedRoleIds) =>
  roles.map(role =>
    includes(inheritedRoleIds, role.id) ? { ...role, inherited: true } : role
  );

export const selectResults = state =>
  Immutable(
    Immutable.asMutable(switcherState(state).results.map(propsToCamelCase))
  );

export const selectItemCount = state => switcherState(state).itemCount;

export const selectAssignedRoles = state =>
  Immutable.asMutable(
    markInheritedRoles(
      switcherState(state).assignedRoles.map(propsToCamelCase),
      switcherState(state).inheritedRoleIds
    )
  );

export const selectToDestroyRoles = state =>
  switcherState(state).toDestroyRoles;

export const selectLoading = state => switcherState(state).loading;
export const selectError = state => switcherState(state).error;
export const selectPagination = state => switcherState(state).pagination;

export const selectPaginationMemoized = createSelector(
  selectPagination,
  selectResults,
  (pagination, results) =>
    results.length > pagination.perPage
      ? { ...pagination, perPage: results.length }
      : pagination
);

export const selectUnassignedRoles = createSelector(
  selectResults,
  selectAssignedRoles,
  (results, assignedRoles) => differenceBy(results, assignedRoles, 'id')
);

Version data entries

65 entries across 65 versions & 1 rubygems

Version Path
foreman_ansible-15.0.2 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherSelectors.js
foreman_ansible-15.0.1 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherSelectors.js
foreman_ansible-15.0.0 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherSelectors.js
foreman_ansible-14.2.2 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherSelectors.js
foreman_ansible-14.2.1 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherSelectors.js
foreman_ansible-13.0.7 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherSelectors.js
foreman_ansible-14.2.0 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherSelectors.js
foreman_ansible-14.1.1 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherSelectors.js
foreman_ansible-14.1.0 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherSelectors.js
foreman_ansible-13.0.5 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherSelectors.js
foreman_ansible-14.0.0 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherSelectors.js
foreman_ansible-13.0.4 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherSelectors.js
foreman_ansible-13.0.3 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherSelectors.js
foreman_ansible-13.0.2 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherSelectors.js
foreman_ansible-13.0.1 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherSelectors.js
foreman_ansible-13.0.0 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherSelectors.js
foreman_ansible-12.0.7 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherSelectors.js
foreman_ansible-10.4.4 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherSelectors.js
foreman_ansible-7.1.8 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherSelectors.js
foreman_ansible-12.0.6 webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherSelectors.js