-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Chrome: Add a publish dropdown v1 #2887
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { connect } from 'react-redux'; | ||
import { flowRight } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { withAPIData } from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import './style.scss'; | ||
import { | ||
isCurrentPostPublished, | ||
isEditedPostBeingScheduled, | ||
} from '../../selectors'; | ||
|
||
export function PublishButtonLabel( { | ||
isPublished, | ||
isBeingScheduled, | ||
user, | ||
} ) { | ||
const isContributor = user.data && ! user.data.capabilities.publish_posts; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very nice idea to extract this logic in a variable 👍 Is there any plan to have a similar way to access API data as we have with Redux selectors? I can imagine we might want to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably related to how with make There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Selectors are just functions which happen to follow a particular first-argument convention. If it became a common pattern, I could see how it might be useful to create better organization around operating on API data. However, the implementation of |
||
|
||
if ( isContributor ) { | ||
return __( 'Submit for Review' ); | ||
} else if ( isPublished ) { | ||
return __( 'Update' ); | ||
} else if ( isBeingScheduled ) { | ||
return __( 'Schedule' ); | ||
} | ||
|
||
return __( 'Publish' ); | ||
} | ||
|
||
const applyConnect = connect( | ||
( state ) => ( { | ||
isPublished: isCurrentPostPublished( state ), | ||
isBeingScheduled: isEditedPostBeingScheduled( state ), | ||
} ) | ||
); | ||
|
||
const applyWithAPIData = withAPIData( () => { | ||
return { | ||
user: '/wp/v2/users/me?context=edit', | ||
}; | ||
} ); | ||
|
||
export default flowRight( [ | ||
applyConnect, | ||
applyWithAPIData, | ||
] )( PublishButtonLabel ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* WordPress Dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal Dependencies | ||
*/ | ||
import './style.scss'; | ||
import PostVisibility from '../../sidebar/post-visibility'; | ||
import PostSchedule from '../../sidebar/post-schedule'; | ||
import PublishButton from '../publish-button'; | ||
|
||
function PublishDropdown( { onSubmit } ) { | ||
return ( | ||
<div className="editor-publish-dropdown"> | ||
<div><strong>{ __( 'All ready to go!' ) }</strong></div> | ||
<PostVisibility /> | ||
<PostSchedule /> | ||
<div className="editor-publish-dropdown__publish-button-container"> | ||
<PublishButton onSubmit={ onSubmit } /> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default PublishDropdown; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.editor-publish-dropdown { | ||
padding: 15px; | ||
} | ||
|
||
.editor-publish-dropdown__publish-button-container { | ||
margin-top: 20px; | ||
text-align: right; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* External Dependencies | ||
*/ | ||
import { connect } from 'react-redux'; | ||
|
||
/** | ||
* WordPress Dependencies | ||
*/ | ||
import { Dropdown, Button, Dashicon } from '@wordpress/components'; | ||
|
||
/** | ||
* Internal Dependencies | ||
*/ | ||
import './style.scss'; | ||
import PublishDropdown from '../publish-dropdown'; | ||
import PublishButtonLabel from '../publish-button/label'; | ||
import { | ||
isSavingPost, | ||
isEditedPostSaveable, | ||
isEditedPostPublishable, | ||
} from '../../selectors'; | ||
|
||
function PublishWithDropdown( { isSaving, isPublishable, isSaveable } ) { | ||
const isButtonEnabled = ! isSaving && isPublishable && isSaveable; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is possible to expose it from |
||
|
||
return ( | ||
<Dropdown | ||
position="bottom left" | ||
className="editor-publish-with-dropdown" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Newbie question, file name is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that's how we do it right now :) |
||
renderToggle={ ( { isOpen, onToggle } ) => ( | ||
<Button | ||
className="editor-publish-with-dropdown__button" | ||
isPrimary | ||
onClick={ onToggle } | ||
aria-expanded={ isOpen } | ||
disabled={ ! isButtonEnabled } | ||
> | ||
<PublishButtonLabel /> | ||
<Dashicon icon="arrow-down" /> | ||
</Button> | ||
) } | ||
renderContent={ ( { onClose } ) => <PublishDropdown onSubmit={ onClose } /> } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice way to close the dropdown on submit. |
||
/> | ||
); | ||
} | ||
|
||
export default connect( | ||
( state ) => ( { | ||
isSaving: isSavingPost( state ), | ||
isSaveable: isEditedPostSaveable( state ), | ||
isPublishable: isEditedPostPublishable( state ), | ||
} ), | ||
)( PublishWithDropdown ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.editor-publish-with-dropdown { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It nicely replaces the existing override 👍 |
||
margin: 0 10px; | ||
} | ||
|
||
.wp-core-ui .editor-publish-with-dropdown__button { | ||
display: inline-flex; | ||
align-items: center; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An excellent idea to put this logic into its own component.