You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.5 KiB
45 lines
1.5 KiB
import { denormalize } from 'normalizr'
|
|
import { createSelector } from 'reselect'
|
|
import values from 'lodash/values'
|
|
|
|
import { groupSchema } from '../store/schemas'
|
|
import { AppState, Entity } from '../types'
|
|
|
|
export const getEntityStore = (state: AppState) => state.entities
|
|
|
|
export const getEntity = (state: AppState, type: string, id: string) => {
|
|
const store = getEntityStore(state)
|
|
const collection = store[type]
|
|
|
|
return collection ? collection[id] : undefined
|
|
}
|
|
|
|
export const getForm = (state: AppState) => state.forms.form
|
|
|
|
export const getFieldValue = (state: AppState, name: string) => {
|
|
const field = getForm(state)[name]
|
|
return field.value
|
|
}
|
|
|
|
export const getFieldNotification = (state: AppState, name: string) => {
|
|
const field = getForm(state)[name]
|
|
return field.notification
|
|
}
|
|
|
|
export const getMenuCollapsed = (state: AppState) => state.menu.collapsed
|
|
export const getAuthenticated = (state: AppState) => state.authentication.authenticated
|
|
export const getNotifications = (state: AppState) => state.notifications
|
|
export const getRequests = (state: AppState) => state.requests
|
|
|
|
export const getFetching = createSelector(getRequests, requests => {
|
|
return values(requests).reduce((fetching, request) => fetching || request.fetching, false)
|
|
})
|
|
|
|
export const getDirectoryGroupIds = (state: AppState) => state.directory.groups
|
|
|
|
export const getDirectoryGroups = createSelector(
|
|
[getEntityStore, getDirectoryGroupIds],
|
|
(store, groups) => {
|
|
return denormalize(groups, [groupSchema], store) as Entity[]
|
|
}
|
|
)
|