1
0
mirror of https://github.com/yldio/copilot.git synced 2024-11-29 14:40:04 +02:00
copilot/frontend/src/state/selectors.js

39 lines
1.0 KiB
JavaScript
Raw Normal View History

const find = require('lodash.find');
const forceArray = require('force-array');
2016-12-20 13:29:54 +02:00
const get = require('lodash.get');
const reselect = require('reselect');
const {
createSelector
} = reselect;
2016-12-20 13:29:54 +02:00
const account = (state) => get(state, 'account.data', {});
const orgUiSections = (state) => get(state, 'orgs.ui.sections', []);
const orgs = (state) => get(state, 'orgs.data', []);
const projects = (state) => get(state, 'projects.data', []);
const orgById = (id) => createSelector(
orgs,
(orgs) => find(orgs, ['id', id])
);
const projectsByOrgId = (orgId) => createSelector(
[projects, orgById(orgId)],
(projects, org) => projects.filter((p) => p.org === org.uuid)
);
const orgSections = (orgId) => createSelector(
[orgById(orgId), orgUiSections],
(org, sections) => sections.filter(
(section) => forceArray(org.hide).indexOf(section) < 0
)
);
module.exports = {
accountSelector: account,
orgByIdSelector: orgById,
orgsSelector: orgs,
orgSectionsSelector: orgSections,
projectsByOrgIdSelector: projectsByOrgId
};