Skip to content
Snippets Groups Projects
Commit 75a25d65 authored by john's avatar john
Browse files

set the production editor on the collection object

parent 17ae02f9
No related branches found
No related tags found
No related merge requests found
......@@ -8,53 +8,46 @@ import Division from './Division'
import Modal from '../utils/Modal'
import styles from './styles/bookBuilder.local.scss'
// import { fragmentsOfCollection } from 'pubsweet-core/app/helpers/Utils'
export class BookBuilder extends React.Component {
constructor (props) {
super(props)
this._toggleTeamManager = this._toggleTeamManager.bind(this)
// this.enableActions = false
this._getRoles = this._getRoles.bind(this)
this._isProductionEditor = this._isProductionEditor.bind(this)
this._setProductionEditor = this._setProductionEditor.bind(this)
this.setProductionEditor = this.setProductionEditor.bind(this)
this.state = {
outerContainer: {},
productionEditor: null,
showTeamManager: false
}
}
componentWillMount () {
const { actions, book } = this.props
const { getCollections, getFragments, getTeams, getUsers } = actions
const {
getCollections,
getFragments,
getTeams,
getUsers
} = this.props.actions
getUsers().then(
() => getTeams()
).then(
() => {
this._setProductionEditor()
return getCollections()
}
).then(
() => {
if (book.id) getFragments(book)
const { book } = this.props
this.setProductionEditor()
getFragments(book)
}
)
}
componentWillReceiveProps (nextProps) {
const { actions, book } = nextProps
const { getFragments } = actions
if (book.id && book.id !== this.props.book.id) {
getFragments(book)
}
}
componentDidMount () {
// I'm using the ref inside the render function it was created in
// So it won't be available until didMount
......@@ -62,9 +55,9 @@ export class BookBuilder extends React.Component {
this.setState({ outerContainer: this.refs.outerContainer })
}
// temporary HACK to add production editor to collection
_setProductionEditor () {
const { book, teams, users } = this.props
setProductionEditor () {
const { actions, book, teams, users } = this.props
const { updateCollection } = actions
const productionEditorsTeam = _.find(teams, function (t) {
return t.teamType.name === 'Production Editor' && t.object.id === book.id
......@@ -76,9 +69,28 @@ export class BookBuilder extends React.Component {
return _.includes(productionEditorsTeam.members, u.id)
})
if (_.isEmpty(productionEditors)) return
let patch
if (_.isEmpty(productionEditors)) {
patch = {
id: book.id,
productionEditor: null
}
return updateCollection(patch)
}
const currentEditor = book.productionEditor
const foundEditor = productionEditors[0] || null
if (currentEditor === foundEditor) return
patch = {
id: book.id,
productionEditor: _.pick(foundEditor, ['id', 'username'])
}
this.setState({ productionEditor: productionEditors[0].username })
updateCollection(patch)
}
_toggleTeamManager () {
......@@ -158,7 +170,7 @@ export class BookBuilder extends React.Component {
)
}
const productionEditor = this.state.productionEditor || 'unassigned'
const productionEditor = _.get(book, 'productionEditor.username') || 'unassigned'
return (
<div className='bootstrap modal pubsweet-component pubsweet-component-scroll'>
......@@ -170,7 +182,7 @@ export class BookBuilder extends React.Component {
<h1>{this.props.book.title}</h1>
<div className={styles.productionEditorContainer}>
<span>Production Editor: &nbsp; {productionEditor} </span>
<span>Production Editor: &nbsp; { productionEditor } </span>
{teamManagerButton}
<div className={styles.separator} />
</div>
......
......@@ -30,6 +30,9 @@ module.exports = {
},
theme: 'ThemeEditoria',
validations: {
collection: {
productionEditor: Joi.object().allow(null)
},
fragment: {
alignment: Joi.object(),
author: Joi.string().allow(''),
......
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