diff --git a/editor/sidebar/post-author/index.js b/editor/sidebar/post-author/index.js new file mode 100644 index 00000000000000..15faef8d28fa67 --- /dev/null +++ b/editor/sidebar/post-author/index.js @@ -0,0 +1,90 @@ +/** + * External dependencies + */ +import { connect } from 'react-redux'; + +/** + * WordPress dependencies + */ +import { __ } from 'i18n'; +import { PanelRow, withInstanceId } from 'components'; +import { Component } from 'element'; + +/** + * Internal dependencies + */ +import './style.scss'; +import { getEditedPostAttribute } from '../../selectors'; +import { editPost } from '../../actions'; + +class PostAuthor extends Component { + constructor() { + super( ...arguments ); + this.state = { + authors: [], + }; + } + + fetchAuthors() { + this.fetchAuthorsRequest = new wp.api.collections.Users().fetch( { data: { + roles: 'author,editor,administrator', + per_page: 100, + } } ); + this.fetchAuthorsRequest.then( ( authors ) => { + this.setState( { authors } ); + } ); + } + + componentDidMount() { + this.fetchAuthors(); + } + + componentWillUnmount() { + if ( this.fetchAuthorsRequest ) { + return this.fetchAuthorsRequest.abort(); + } + } + + render() { + const { onUpdateAuthor, postAuthor, instanceId } = this.props; + const { authors } = this.state; + const selectId = 'post-author-selector-' + instanceId; + + if ( authors.length < 2 ) { + return null; + } + + // Disable reason: A select with an onchange throws a warning + + /* eslint-disable jsx-a11y/no-onchange */ + return ( + + + + + ); + /* eslint-enable jsx-a11y/no-onchange */ + } +} + +export default connect( + ( state ) => { + return { + postAuthor: getEditedPostAttribute( state, 'author' ), + }; + }, + { + onUpdateAuthor( author ) { + return editPost( { author } ); + }, + }, +)( withInstanceId( PostAuthor ) ); diff --git a/editor/sidebar/post-author/style.scss b/editor/sidebar/post-author/style.scss new file mode 100644 index 00000000000000..a423d651051b82 --- /dev/null +++ b/editor/sidebar/post-author/style.scss @@ -0,0 +1,3 @@ +.editor-post-author__select { + margin: -5px 0; +} diff --git a/editor/sidebar/post-status/index.js b/editor/sidebar/post-status/index.js index 7b4a9e18c9a45d..a201b83c3812b2 100644 --- a/editor/sidebar/post-status/index.js +++ b/editor/sidebar/post-status/index.js @@ -17,6 +17,7 @@ import PostVisibility from '../post-visibility'; import PostTrash from '../post-trash'; import PostSchedule from '../post-schedule'; import PostSticky from '../post-sticky'; +import PostAuthor from '../post-author'; import { getEditedPostAttribute, getSuggestedPostFormat, @@ -64,6 +65,7 @@ class PostStatus extends Component { { format } + );