Commit d07e2d38 authored by nickstiffler's avatar nickstiffler Committed by Yannis Barlas
Browse files

feat(dashboard): filter by team member in editor section

parent d0a92078
......@@ -65,8 +65,10 @@ const DashboardWrapper = styled.div`
const Dashboard = props => {
const {
allCurators,
allEditors,
allScienceOfficers,
allSectionEditors,
authorArticles,
client,
createManuscript,
......@@ -159,6 +161,18 @@ const Dashboard = props => {
},
]
const globalTeamMembers = [
...allScienceOfficers,
...allCurators,
...allEditors,
...allSectionEditors,
]
const teamMemberOptions = globalTeamMembers.map(member => ({
label: member.displayName,
value: member.id,
}))
const headerActions = [
<SubmitButton
client={client}
......@@ -193,10 +207,16 @@ const Dashboard = props => {
previewData: null,
savedStatuses: storedStatuses,
showModal: false,
teamFilter: null,
}}
>
{({ state, setState }) => {
const { previewData, showModal, savedStatuses } = state
const {
previewData,
showModal,
savedStatuses,
teamMemberFilter,
} = state
const openModal = article =>
setState({
......@@ -215,28 +235,35 @@ const Dashboard = props => {
openModal(article)
}
const filterArticles = selectedStatuses => {
const filterArticles = (selectedStatuses, teamMember) => {
const filteredArticles =
selectedStatuses.length > 0
? editorArticles.filter(article =>
selectedStatuses
.map(s => s.value)
.includes(article.displayStatus),
)
: editorArticles.filter(
article =>
!['published', 'rejected', 'declined'].includes(
article.displayStatus,
),
)
if (teamMember) {
filterByTeamMember(teamMember, filteredArticles)
} else {
setState({ filteredArticles })
}
}
const handleSelectedStatuses = selectedStatuses => {
localStorage.setItem(
'selectedStatuses',
JSON.stringify(selectedStatuses),
)
setState({ savedStatuses: selectedStatuses })
if (selectedStatuses.length > 0) {
const filteredArticles = editorArticles.filter(article =>
selectedStatuses
.map(s => s.value)
.includes(article.displayStatus),
)
setState({ filteredArticles })
} else {
const filteredArticles = editorArticles.filter(
article =>
!['published', 'rejected', 'declined'].includes(
article.displayStatus,
),
)
setState({ filteredArticles })
}
filterArticles(selectedStatuses, state.teamMemberFilter)
}
const deleteFilterArticle = articleId => {
......@@ -248,15 +275,48 @@ const Dashboard = props => {
})
}
const filterByTeamMember = (teamMember, articles) => {
const teamTypes = [
'curator',
'scienceOfficer',
'editor',
'sectionEditor',
]
const filteredArticles = articles.filter(article =>
teamTypes.some(
type => article[type] && article[type].id === teamMember.value,
),
)
setState({ filteredArticles })
}
const handleSelectedTeamMember = teamMember => {
setState({ teamMemberFilter: teamMember })
if (teamMember) {
filterByTeamMember(teamMember, state.filteredArticles)
} else {
filterArticles(savedStatuses, teamMember)
}
}
const editorActions = [
<Select
closeMenuOnSelect={false}
isMulti
onChange={filterArticles}
onChange={handleSelectedStatuses}
options={options}
placeholder="Filter By Status"
value={savedStatuses}
/>,
<Select
isClearable
isSearchable
onChange={handleSelectedTeamMember}
options={teamMemberOptions}
placeholder="Filter By Team Member"
value={teamMemberFilter}
/>,
]
return (
......
......@@ -256,9 +256,18 @@ const mapProps = args => {
globalTeams &&
getTeamByType(globalTeams, 'scienceOfficers').members.map(m => m.user)
const allCurators =
globalTeams &&
getTeamByType(globalTeams, 'globalCurator').members.map(m => m.user)
const allSectionEditors =
globalTeams &&
getTeamByType(globalTeams, 'globalSectionEditor').members.map(m => m.user)
return {
allCurators,
allEditors,
allScienceOfficers,
allSectionEditors,
authorArticles,
curatorArticles,
createManuscript: args.createManuscript.createManuscript,
......
Markdown is supported
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