Sha256: ea8b070ed1b8ac9acc45c4dfc04287bb0be5f7031a16a0327b3c13d7be1f0e19
Contents?: true
Size: 1.98 KB
Versions: 34
Compression:
Stored size: 1.98 KB
Contents
import { differenceBy, slice, includes, uniq } from 'lodash'; import Immutable from 'seamless-immutable'; import { createSelector } from 'reselect'; const compare = (a, b) => { if (a.name < b.name) { return -1; } if (a.name > b.name) { return 1; } return 0; }; 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(uniq(switcherState(state).results)).sort(compare) ); export const selectItemCount = state => switcherState(state).itemCount; export const selectAssignedRoles = state => Immutable.asMutable( markInheritedRoles( switcherState(state).assignedRoles, switcherState(state).inheritedRoleIds ) ).sort(compare); export const selectAssignedRolesCount = state => selectAssignedRoles(state).length; export const selectLoading = state => switcherState(state).loading; export const selectAssignedPagination = state => switcherState(state).assignedPagination; 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') ); export const selectAssignedRolesPage = createSelector( selectAssignedPagination, selectAssignedRoles, (assignedPagination, assignedRoles) => { const offset = (assignedPagination.page - 1) * assignedPagination.perPage; return slice(assignedRoles, offset, offset + assignedPagination.perPage); } );
Version data entries
34 entries across 34 versions & 1 rubygems