Skip to content
Snippets Groups Projects
Commit 8919b18b authored by john's avatar john
Browse files

attempt to automate team creation

parent 42ace9e9
No related branches found
No related tags found
No related merge requests found
import { each, filter, isEmpty } from 'lodash'
import Actions from 'pubsweet-client/src/actions' import Actions from 'pubsweet-client/src/actions'
import React from 'react' import React from 'react'
import { bindActionCreators } from 'redux' import { bindActionCreators } from 'redux'
...@@ -6,14 +7,16 @@ import { connect } from 'react-redux' ...@@ -6,14 +7,16 @@ import { connect } from 'react-redux'
import AddBook from './AddBook' import AddBook from './AddBook'
import BookList from './BookList' import BookList from './BookList'
import DashboardHeader from './DashboardHeader' import DashboardHeader from './DashboardHeader'
import { teamTypes } from '../utils/config'
import styles from './dashboard.local.scss' import styles from './dashboard.local.scss'
export class Dashboard extends React.Component { export class Dashboard extends React.Component {
constructor (props) { constructor (props) {
super(props) super(props)
this.createCollection = this.createCollection.bind(this) this.createBook = this.createBook.bind(this)
this.removeCollection = this.removeCollection.bind(this) this.makeTeamsForBook = this.makeTeamsForBook.bind(this)
this.removeBook = this.removeBook.bind(this)
this.toggleModal = this.toggleModal.bind(this) this.toggleModal = this.toggleModal.bind(this)
this.state = { this.state = {
...@@ -21,13 +24,35 @@ export class Dashboard extends React.Component { ...@@ -21,13 +24,35 @@ export class Dashboard extends React.Component {
} }
} }
componentWillMount () {
const { getTeams } = this.props.actions
getTeams()
}
/*
If a book has no teams, it is a new one.
Make the default teams for it automatically.
*/
componentDidUpdate () {
// console.log('did')
const { books, teams } = this.props
each(books, book => {
const teamsForBook = filter(teams, t => {
return t.object.id === book.id
})
if (isEmpty(teamsForBook)) this.makeTeamsForBook(book)
})
}
toggleModal () { toggleModal () {
this.setState({ this.setState({
showModal: !this.state.showModal showModal: !this.state.showModal
}) })
} }
createCollection (newTitle) { createBook (newTitle) {
const { createCollection } = this.props.actions const { createCollection } = this.props.actions
const collection = { const collection = {
...@@ -37,11 +62,32 @@ export class Dashboard extends React.Component { ...@@ -37,11 +62,32 @@ export class Dashboard extends React.Component {
createCollection(collection) createCollection(collection)
} }
removeCollection (collection) { removeBook (collection) {
const { deleteCollection } = this.props.actions const { deleteCollection } = this.props.actions
deleteCollection(collection) deleteCollection(collection)
} }
makeTeamsForBook (book) {
const { createTeam } = this.props.actions
each(teamTypes, teamType => {
// TODO -- Review the idea that the name needs to be plural for some teams
// const name = teamType.name === 'Production Editor' ? teamType.name : teamType.name + 's'
//
// const newTeam = {
// members: [],
// name: name,
// object: {
// id: book.id,
// type: 'collection'
// },
// teamType: teamType
// }
//
// createTeam(newTeam)
})
}
render () { render () {
const { books } = this.props const { books } = this.props
const { showModal } = this.state const { showModal } = this.state
...@@ -58,13 +104,13 @@ export class Dashboard extends React.Component { ...@@ -58,13 +104,13 @@ export class Dashboard extends React.Component {
<BookList <BookList
books={books} books={books}
container={this} container={this}
remove={this.removeCollection} remove={this.removeBook}
/> />
</div> </div>
<AddBook <AddBook
container={this} container={this}
create={this.createCollection} create={this.createBook}
show={showModal} show={showModal}
toggle={this.toggleModal} toggle={this.toggleModal}
/> />
...@@ -74,13 +120,15 @@ export class Dashboard extends React.Component { ...@@ -74,13 +120,15 @@ export class Dashboard extends React.Component {
} }
Dashboard.propTypes = { Dashboard.propTypes = {
books: React.PropTypes.arrayOf(React.PropTypes.object), actions: React.PropTypes.object.isRequired,
actions: React.PropTypes.object.isRequired books: React.PropTypes.arrayOf(React.PropTypes.object), // TODO -- ??
teams: React.PropTypes.arrayOf(React.PropTypes.object)
} }
function mapStateToProps (state, { params }) { function mapStateToProps (state, { params }) {
return { return {
books: state.collections books: state.collections,
teams: state.teams
} }
} }
......
...@@ -3,7 +3,8 @@ import { AnnotationComponent } from 'substance' ...@@ -3,7 +3,8 @@ import { AnnotationComponent } from 'substance'
class TrackChangeComponent extends AnnotationComponent { class TrackChangeComponent extends AnnotationComponent {
didMount () { didMount () {
this.context.editorSession.onUpdate('document', this.onTrackChangesUpdated, this) const { editorSession } = this.context
editorSession.onUpdate('document', this.onTrackChangesUpdated, this)
} }
render ($$) { render ($$) {
......
const teamTypes = CONFIG.authsome.teams
const chapter = { const chapter = {
dropdownValues: { dropdownValues: {
front: [ front: [
...@@ -23,4 +25,4 @@ const chapter = { ...@@ -23,4 +25,4 @@ const chapter = {
} }
} }
export { chapter } export { chapter, teamTypes }
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