Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add label elements to scheduler and visibility #3317

Merged
merged 3 commits into from
Nov 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions editor/sidebar/post-schedule/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
/**
* External dependencies
*/
import { flowRight } from 'lodash';

/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { PanelRow, Dropdown, withAPIData } from '@wordpress/components';
import { PanelRow, Dropdown, withAPIData, withInstanceId } from '@wordpress/components';

/**
* Internal dependencies
Expand All @@ -11,19 +16,21 @@ import './style.scss';
import PostScheduleLabel from '../../post-schedule/label';
import PostScheduleForm from '../../post-schedule';

export function PostSchedule( { user } ) {
export function PostSchedule( { user, instanceId } ) {
if ( ! user.data || ! user.data.capabilities.publish_posts ) {
return null;
}
const postScheduleSelectorId = 'post-schedule-selector-' + instanceId;

return (
<PanelRow className="editor-post-schedule">
<span>{ __( 'Publish' ) }</span>
<label htmlFor={ postScheduleSelectorId }>{ __( 'Publish' ) }</label>
<Dropdown
position="bottom left"
contentClassName="editor-post-schedule__dialog"
renderToggle={ ( { onToggle, isOpen } ) => (
<button
id={ postScheduleSelectorId }
type="button"
className="editor-post-schedule__toggle button-link"
onClick={ onToggle }
Expand All @@ -38,8 +45,11 @@ export function PostSchedule( { user } ) {
);
}

export default withAPIData( () => {
return {
user: '/wp/v2/users/me?context=edit',
};
} )( PostSchedule );
const applyWithAPIData = withAPIData( () => ( {
user: '/wp/v2/users/me?context=edit',
} ) );

export default flowRight( [
applyWithAPIData,
withInstanceId,
] )( PostSchedule );
26 changes: 18 additions & 8 deletions editor/sidebar/post-visibility/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
/**
* External dependencies
*/
import { flowRight } from 'lodash';

/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { PanelRow, Dropdown, withAPIData } from '@wordpress/components';
import { PanelRow, Dropdown, withAPIData, withInstanceId } from '@wordpress/components';

/**
* Internal Dependencies
Expand All @@ -11,19 +16,21 @@ import './style.scss';
import PostVisibilityLabel from '../../post-visibility/label';
import PostVisibilityForm from '../../post-visibility';

export function PostVisibility( { user } ) {
export function PostVisibility( { user, instanceId } ) {
const canEdit = user.data && user.data.capabilities.publish_posts;
const postVisibilitySelectorId = 'post-visibility-selector-' + instanceId;

return (
<PanelRow className="editor-post-visibility">
<span>{ __( 'Visibility' ) }</span>
<label htmlFor={ postVisibilitySelectorId }>{ __( 'Visibility' ) }</label>
{ ! canEdit && <span><PostVisibilityLabel /></span> }
{ canEdit && (
<Dropdown
position="bottom left"
contentClassName="editor-post-visibility__dialog"
renderToggle={ ( { isOpen, onToggle } ) => (
<button
id={ postVisibilitySelectorId }
type="button"
aria-expanded={ isOpen }
className="editor-post-visibility__toggle button-link"
Expand All @@ -39,8 +46,11 @@ export function PostVisibility( { user } ) {
);
}

export default withAPIData( () => {
return {
user: '/wp/v2/users/me?context=edit',
};
} )( PostVisibility );
const applyWithAPIData = withAPIData( () => ( {
user: '/wp/v2/users/me?context=edit',
} ) );

export default flowRight( [
applyWithAPIData,
withInstanceId,
] )( PostVisibility );