Skip to content
Snippets Groups Projects
Commit 841065eb authored by Sebastian Mihalache's avatar Sebastian Mihalache
Browse files

Merge branch 'develop' of gitlab.coko.foundation:xpub/xpub-faraday into develop

parents fbb4e609 afd46306
No related branches found
No related tags found
1 merge request!13Sprint #14
...@@ -81,3 +81,10 @@ export const canMakeRevision = (state, collection) => { ...@@ -81,3 +81,10 @@ export const canMakeRevision = (state, collection) => {
collection.owners.map(o => o.id).includes(currentUserId) collection.owners.map(o => o.id).includes(currentUserId)
) )
} }
export const getUserPermissions = ({ currentUser }) =>
get(currentUser, 'user.teams').map(t => ({
objectId: t.object.id,
objectType: t.object.type,
role: t.teamType.permissions,
}))
import React from 'react' import React from 'react'
import styled from 'styled-components' import styled from 'styled-components'
import { Button, th } from '@pubsweet/ui' import { Button, th } from '@pubsweet/ui'
import { compose, withHandlers } from 'recompose' import { compose, withProps } from 'recompose'
import { DashboardItems, DashboardFilters } from './' import { DashboardItems, DashboardFilters } from './'
const Dashboard = ({ const Dashboard = ({
filters,
getItems,
dashboard, dashboard,
currentUser,
filterItems, filterItems,
filterValues, filterValues,
deleteProject, deleteProject,
dashboardItems,
getFilterOptions, getFilterOptions,
changeFilterValue, changeFilterValue,
getDefaultFilterValue,
createDraftSubmission, createDraftSubmission,
...rest
}) => ( }) => (
<Root> <Root>
<Header> <Header>
...@@ -33,26 +31,17 @@ const Dashboard = ({ ...@@ -33,26 +31,17 @@ const Dashboard = ({
</Header> </Header>
<DashboardFilters <DashboardFilters
changeFilterValue={changeFilterValue} changeFilterValue={changeFilterValue}
getDefaultFilterValue={getDefaultFilterValue}
getFilterOptions={getFilterOptions} getFilterOptions={getFilterOptions}
/> />
<DashboardItems deleteProject={deleteProject} list={getItems()} /> <DashboardItems deleteProject={deleteProject} list={dashboardItems} />
</Root> </Root>
) )
export default compose( export default compose(
withHandlers({ withProps(({ dashboard, filterItems }) => ({
getItems: ({ dashboardItems: filterItems(dashboard.all),
filters, })),
dashboard,
currentUser,
filterItems,
filterValues = {},
}) => () =>
filterItems(dashboard.all).sort((a, b) => {
if (filterValues.order === 'newest') return a.created - b.created < 0
return a.created - b.created > 0
}),
}),
)(Dashboard) )(Dashboard)
// #region styles // #region styles
......
...@@ -12,36 +12,28 @@ const DashboardFilters = ({ ...@@ -12,36 +12,28 @@ const DashboardFilters = ({
changeFilter, changeFilter,
getFilterOptions, getFilterOptions,
changeFilterValue, changeFilterValue,
getDefaultFilterValue,
}) => ( }) => (
<Root> <FiltersContainer>
<FiltersContainer> <span>Filter view:</span>
<span>Filter view:</span> <FilterGroup>
<FilterGroup> <span>Priority</span>
<span>Owner</span> <Menu
<Menu inline
inline onChange={changeFilterValue('priority')}
onChange={changeFilterValue('owner')} options={getFilterOptions('priority')}
options={getFilterOptions('owner')} value={getDefaultFilterValue('priority')}
/> />
</FilterGroup> </FilterGroup>
<FilterGroup> <FilterGroup>
<span>Status</span> <span>Sort</span>
<Menu <Menu
inline inline
onChange={changeFilterValue('status')} onChange={changeFilterValue('order')}
options={getFilterOptions('status')} options={getFilterOptions('order')}
/> />
</FilterGroup> </FilterGroup>
<FilterGroup> </FiltersContainer>
<span>Sort</span>
<Menu
inline
onChange={changeFilterValue('order')}
options={getFilterOptions('order')}
/>
</FilterGroup>
</FiltersContainer>
</Root>
) )
export default compose( export default compose(
...@@ -53,19 +45,14 @@ export default compose( ...@@ -53,19 +45,14 @@ export default compose(
)(DashboardFilters) )(DashboardFilters)
// #region styles // #region styles
const FiltersContainer = styled.div`
const Root = styled.div` align-items: center;
border-bottom: ${th('borderDefault')}; border-bottom: ${th('borderDefault')};
color: ${th('colorPrimary')}; color: ${th('colorPrimary')};
display: flex; display: flex;
justify-content: space-between; justify-content: flex-start;
margin: calc(${th('subGridUnit')} * 2) 0; margin: calc(${th('subGridUnit')} * 2) 0;
padding-bottom: calc(${th('subGridUnit')} * 2); padding-bottom: calc(${th('subGridUnit')} * 2);
`
const FiltersContainer = styled.div`
align-items: center;
display: flex;
> span { > span {
align-self: flex-end; align-self: flex-end;
......
...@@ -12,6 +12,16 @@ import { createDraftSubmission } from 'pubsweet-component-wizard/src/redux/conve ...@@ -12,6 +12,16 @@ import { createDraftSubmission } from 'pubsweet-component-wizard/src/redux/conve
import { Dashboard } from './' import { Dashboard } from './'
import withFilters from './withFilters' import withFilters from './withFilters'
import { getHandlingEditors } from '../../redux/editors' import { getHandlingEditors } from '../../redux/editors'
import cfg from '../../../../xpub-faraday/config/default'
import { getUserPermissions } from '../../../../component-faraday-selectors/src'
const statuses = get(cfg, 'statuses')
const getUserRole = (user, role) => {
if (user.admin) return 'admin'
if (user.editorInChief) return 'editorInChief'
return role
}
export default compose( export default compose(
ConnectPage(() => [actions.getCollections(), actions.getUsers()]), ConnectPage(() => [actions.getCollections(), actions.getUsers()]),
...@@ -37,7 +47,14 @@ export default compose( ...@@ -37,7 +47,14 @@ export default compose(
), ),
all: sortedCollections, all: sortedCollections,
} }
return { collections, conversion, currentUser, dashboard } const userPermissions = getUserPermissions(state)
return {
dashboard,
conversion,
collections,
currentUser,
userPermissions,
}
}, },
(dispatch, { history }) => ({ (dispatch, { history }) => ({
deleteProject: collection => deleteProject: collection =>
...@@ -54,40 +71,26 @@ export default compose( ...@@ -54,40 +71,26 @@ export default compose(
withRouter, withRouter,
withJournal, withJournal,
withFilters({ withFilters({
status: { priority: {
options: [ options: [
{ label: 'All', value: 'all' }, { label: 'All', value: 'all' },
{ label: 'Submitted', value: 'submitted' }, { label: 'Needs Attention', value: 'needsAttention' },
{ label: 'Draft', value: 'draft' }, { label: 'In Progress', value: 'inProgress' },
{ label: 'HE Invited', value: 'heInvited' },
{ label: 'HE Assigned', value: 'heAssigned' },
{ label: 'Reviewers Invited', value: 'reviewersInvited' },
{ label: 'Under Review', value: 'underReview' },
],
filterFn: filterValue => item => {
if (filterValue === 'all' || filterValue === '') return true
const itemStatus = get(item, 'status')
if (!itemStatus && filterValue === 'draft') {
return true
}
return itemStatus === filterValue
},
},
owner: {
options: [
{ label: 'Everyone', value: 'all' },
{ label: 'My work', value: 'me' },
{ label: `Other's work`, value: 'other' },
], ],
filterFn: (filterValue, { currentUser }) => item => { filterFn: (filterValue, { currentUser, userPermissions = [] }) => ({
if (filterValue === 'all' || filterValue === '') return true id,
const itemOwnerIds = item.owners.map(o => o.id) status = 'draft',
if (filterValue === 'me') { }) => {
return itemOwnerIds.includes(currentUser.id) const permission = userPermissions.find(p => p.objectId === id)
} else if (filterValue === 'other') { const userRole = getUserRole(currentUser, get(permission, 'role'))
return !itemOwnerIds.includes(currentUser.id) switch (filterValue) {
case 'needsAttention':
return get(statuses, `${status}.${userRole}.needsAttention`)
case 'inProgress':
return !get(statuses, `${status}.${userRole}.needsAttention`)
default:
return true
} }
return false
}, },
}, },
order: { order: {
......
import { get } from 'lodash' import { get } from 'lodash'
import { compose, withState, withHandlers } from 'recompose' import { compose, withState, withHandlers } from 'recompose'
const hydrateFilters = defaultValues => {
const filterValues = localStorage.getItem('filterValues')
if (filterValues) return JSON.parse(filterValues)
return defaultValues
}
export default config => Component => { export default config => Component => {
const filterFns = Object.entries(config).map(([filterKey, { filterFn }]) => ({ const filterFns = Object.entries(config).map(([filterKey, { filterFn }]) => ({
key: filterKey, key: filterKey,
...@@ -11,14 +17,29 @@ export default config => Component => { ...@@ -11,14 +17,29 @@ export default config => Component => {
{}, {},
) )
return compose( return compose(
withState('filterValues', 'setFilterValues', filterValues), withState('filterValues', 'setFilterValues', hydrateFilters(filterValues)),
withHandlers({ withHandlers({
getFilterOptions: () => key => get(config, `${key}.options`) || [], getFilterOptions: () => key => get(config, `${key}.options`) || [],
changeFilterValue: ({ setFilterValues }) => filterKey => value => { getDefaultFilterValue: ({ filterValues }) => key =>
setFilterValues(v => ({ get(filterValues, key) || '',
...v, changeFilterValue: ({
[filterKey]: value, setFilterValues,
})) filterValues,
}) => filterKey => value => {
// ugly but recompose doesn't pass the new state in the callback function
let newState = {}
setFilterValues(
v => {
newState = {
...v,
[filterKey]: value,
}
return newState
},
() => {
localStorage.setItem('filterValues', JSON.stringify(newState))
},
)
}, },
filterItems: ({ filterValues, ...props }) => items => filterItems: ({ filterValues, ...props }) => items =>
filterFns.reduce( filterFns.reduce(
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment