Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial getters for tasks, and tests #104

Merged
merged 16 commits into from Jul 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions agents/getters/getAgents.js
@@ -0,0 +1,3 @@
const getAgents = (state) => state.agents

export default getAgents
2 changes: 1 addition & 1 deletion app/containers/Dashboard.js
Expand Up @@ -4,7 +4,7 @@ import Dashboard from '../components/Dashboard'
import { actions as taskPlanActions } from '../../tasks/dux/plans'
import { actions as taskWorkActions } from '../../tasks/dux/works'
import * as orderingActions from '../../ordering/actions'
import { getDashboardProps } from '../getters'
import getDashboardProps from '../getters/getDashboardProps'

export default connect({
selector: getDashboardProps,
Expand Down
2 changes: 1 addition & 1 deletion app/containers/Layout.js
Expand Up @@ -2,7 +2,7 @@ import { connect } from 'react-redux'

import Layout from '../components/Layout'

import { getLayoutProps } from '../getters'
import getLayoutProps from '../getters/getLayoutProps'

export default connect(
getLayoutProps,
Expand Down
2 changes: 1 addition & 1 deletion app/containers/home.js
Expand Up @@ -2,7 +2,7 @@ import { connect } from 'react-redux'

import Home from '../components/home'

import { getHomeProps } from '../getters'
import getHomeProps from '../getters/getHomeProps'

export default connect(
getHomeProps
Expand Down
8 changes: 8 additions & 0 deletions app/getters/getAllRoutes.js
@@ -0,0 +1,8 @@
import { pipe, nthArg, propOr } from 'ramda'

const getAllRoutes = pipe(
nthArg(1),
propOr(null, 'routes')
)

export default getAllRoutes
5 changes: 5 additions & 0 deletions app/getters/getConfig.js
@@ -0,0 +1,5 @@
import { prop } from 'ramda'

const getConfig = prop('config')

export default getConfig
9 changes: 9 additions & 0 deletions app/getters/getDashboardProps.js
@@ -0,0 +1,9 @@
import { createStructuredSelector } from 'reselect'

import getTaskPlans from '../../tasks/getters/getTaskPlans'

const getDashboardProps = createStructuredSelector({
taskPlans: getTaskPlans
})

export default getDashboardProps
3 changes: 3 additions & 0 deletions app/getters/getHomeProps.js
@@ -0,0 +1,3 @@
const getHomeProps = (state) => ({})

export default getHomeProps
13 changes: 13 additions & 0 deletions app/getters/getLayoutProps.js
@@ -0,0 +1,13 @@
import { createStructuredSelector } from 'reselect'
import getCurrentAgent from 'dogstack-agents/agents/getters/getCurrentAgent'

import getRoutes from './getRoutes'
import getNavigationRoutes from './getNavigationRoutes'

const getLayoutProps = createStructuredSelector({
currentAgent: getCurrentAgent,
routes: getRoutes,
navigationRoutes: getNavigationRoutes
})

export default getLayoutProps
25 changes: 25 additions & 0 deletions app/getters/getNavigationRoutes.js
@@ -0,0 +1,25 @@
import { createSelector } from 'reselect'
import { indexBy, prop, filter, pipe, isNil, not, map, uncurryN } from 'ramda'

import getState from './getState'
import getRoutes from './getRoutes'

const indexByName = indexBy(prop('name'))
const filterNil = filter(pipe(isNil, not))

const getNavigationRoutes = createSelector(
getState,
getRoutes,
uncurryN(2, state => {
const mapRoutes = map(route => {
const { name, navigation } = route
if (isNil(navigation)) return
if (navigation === true) return route
const { selector } = navigation
if (isNil(selector) || selector(state)) return route
})
return pipe(mapRoutes, filterNil, indexByName)
})
)

export default getNavigationRoutes
16 changes: 16 additions & 0 deletions app/getters/getRoutes.js
@@ -0,0 +1,16 @@
import { createSelector } from 'reselect'
import { uncurryN, filter, isNil } from 'ramda'

import getState from './getState'
import getAllRoutes from './getAllRoutes'

const getRoutes = createSelector(
getState,
getAllRoutes,
uncurryN(2, state => filter(route => {
const { selector } = route
return isNil(selector) || selector(state)
}))
)

export default getRoutes
3 changes: 3 additions & 0 deletions app/getters/getState.js
@@ -0,0 +1,3 @@
const getState = state => state

export default getState