-
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 Post Publish Panel #4158
Changes from all 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,102 @@ | ||
/** | ||
* External Dependencies | ||
*/ | ||
import { get } from 'lodash'; | ||
import { connect } from 'react-redux'; | ||
|
||
/** | ||
* WordPress Dependencies | ||
*/ | ||
import { PanelBody, Button, ClipboardButton, withAPIData } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { Component, compose } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal Dependencies | ||
*/ | ||
import { getCurrentPost, getCurrentPostType } from '../../store/selectors'; | ||
|
||
class PostPublishPanelPostpublish extends Component { | ||
constructor() { | ||
super( ...arguments ); | ||
this.state = { | ||
showCopyConfirmation: false, | ||
}; | ||
this.onCopy = this.onCopy.bind( this ); | ||
this.onSelectInput = this.onSelectInput.bind( this ); | ||
} | ||
|
||
componentWillUnmount() { | ||
clearTimeout( this.dismissCopyConfirmation ); | ||
} | ||
|
||
onCopy() { | ||
this.setState( { | ||
showCopyConfirmation: true, | ||
} ); | ||
|
||
clearTimeout( this.dismissCopyConfirmation ); | ||
this.dismissCopyConfirmation = setTimeout( () => { | ||
this.setState( { | ||
showCopyConfirmation: false, | ||
} ); | ||
}, 4000 ); | ||
} | ||
|
||
onSelectInput( event ) { | ||
event.target.select(); | ||
} | ||
|
||
render() { | ||
const { post, postType } = this.props; | ||
const viewPostLabel = get( postType, [ 'data', 'labels', 'view_item' ] ); | ||
|
||
return ( | ||
<div className="post-publish-panel__postpublish"> | ||
<PanelBody className="post-publish-panel__postpublish-header"> | ||
<a href={ post.link }>{ post.title || __( '(no title)' ) }</a>{ __( ' is now live.' ) } | ||
</PanelBody> | ||
<PanelBody> | ||
<div><strong>{ __( 'What\'s next?' ) }</strong></div> | ||
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. Prefer 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. We may have to tweak our ESlint settings to do so. 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. I prefer as currently proposed 😉 |
||
<input | ||
className="post-publish-panel__postpublish-link-input" | ||
readOnly | ||
value={ post.link } | ||
onFocus={ this.onSelectInput } | ||
/> | ||
<div className="post-publish-panel__postpublish-buttons"> | ||
<Button className="button" href={ post.link }> | ||
{ viewPostLabel } | ||
</Button> | ||
|
||
<ClipboardButton className="button" text={ post.link } onCopy={ this.onCopy }> | ||
{ this.state.showCopyConfirmation ? __( 'Copied!' ) : __( 'Copy Link' ) } | ||
</ClipboardButton> | ||
</div> | ||
</PanelBody> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
const applyConnect = connect( | ||
( state ) => { | ||
return { | ||
post: getCurrentPost( state ), | ||
postTypeSlug: getCurrentPostType( state ), | ||
}; | ||
} | ||
); | ||
|
||
const applyWithAPIData = withAPIData( ( props ) => { | ||
const { postTypeSlug } = props; | ||
|
||
return { | ||
postType: `/wp/v2/types/${ postTypeSlug }?context=edit`, | ||
}; | ||
} ); | ||
|
||
export default compose( [ | ||
applyConnect, | ||
applyWithAPIData, | ||
] )( PostPublishPanelPostpublish ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { PanelBody } from '@wordpress/components'; | ||
|
||
/** | ||
* Internal Dependencies | ||
*/ | ||
import PostVisibility from '../post-visibility'; | ||
import PostVisibilityLabel from '../post-visibility/label'; | ||
import PostSchedule from '../post-schedule'; | ||
import PostScheduleLabel from '../post-schedule/label'; | ||
|
||
function PostPublishPanelPrepublish() { | ||
return ( | ||
<div className="editor-post-publish-panel__prepublish"> | ||
<div><strong>{ __( 'Are you ready to publish?' ) }</strong></div> | ||
<p>{ __( 'Here, you can do a last-minute check up of your settings below, before you publish.' ) }</p> | ||
<PanelBody initialOpen={ false } title={ [ | ||
__( 'Visibility: ' ), | ||
<span className="editor-post-publish-panel__link" key="label"><PostVisibilityLabel /></span>, | ||
] }> | ||
<PostVisibility /> | ||
</PanelBody> | ||
<PanelBody initialOpen={ false } title={ [ | ||
__( 'Publish: ' ), | ||
<span className="editor-post-publish-panel__link" key="label"><PostScheduleLabel /></span>, | ||
] }> | ||
<PostSchedule /> | ||
</PanelBody> | ||
</div> | ||
); | ||
} | ||
|
||
export default PostPublishPanelPrepublish; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,22 +4,10 @@ | |
} | ||
|
||
.editor-post-publish-panel__content { | ||
padding: 16px; | ||
|
||
.components-panel__body { | ||
margin-left: -16px; | ||
margin-right: -16px; | ||
margin-bottom: -16px; | ||
margin-top: 10px; | ||
border: none; | ||
|
||
.components-panel__body-toggle { | ||
font-weight: normal; | ||
} | ||
} | ||
|
||
.editor-post-visibility__dialog-legend { | ||
display: none; | ||
.spinner { | ||
display: block; | ||
float: none; | ||
margin: 100px auto 0; | ||
} | ||
} | ||
|
||
|
@@ -37,6 +25,10 @@ | |
text-align: right; | ||
} | ||
|
||
.editor-post-publish-panel__header-published { | ||
flex-grow: 1; | ||
} | ||
|
||
.wp-core-ui .editor-post-publish-panel__toggle.button-primary { | ||
display: inline-flex; | ||
align-items: center; | ||
|
@@ -54,3 +46,65 @@ | |
color: $blue-medium-700; | ||
text-decoration: underline; | ||
} | ||
|
||
.editor-post-publish-panel__prepublish { | ||
padding: 16px; | ||
|
||
.components-panel__body { | ||
margin-left: -16px; | ||
margin-right: -16px; | ||
margin-bottom: -16px; | ||
margin-top: 10px; | ||
border: none; | ||
|
||
.components-panel__body-toggle { | ||
font-weight: normal; | ||
} | ||
} | ||
|
||
.editor-post-visibility__dialog-legend { | ||
display: none; | ||
} | ||
} | ||
|
||
.post-publish-panel__postpublish .components-panel__body { | ||
border-bottom: 1px solid $light-gray-500; | ||
border-top: none; | ||
} | ||
|
||
.wp-core-ui .post-publish-panel__postpublish-buttons { | ||
display: flex; | ||
align-content: space-between; | ||
|
||
> * { | ||
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. Why need this selector? It generally degrades performance a tiny bit. 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. Since the "ClipboardButton" needs a wrapper, we can't target children buttons using a selector. I can replace it with something like |
||
flex-grow: 1; | ||
margin-right: 10px; | ||
|
||
&:last-child { | ||
margin-right: 0; | ||
} | ||
} | ||
|
||
.components-button { | ||
text-align: center; | ||
} | ||
|
||
.components-clipboard-button { | ||
width: 100%; | ||
} | ||
} | ||
|
||
.post-publish-panel__postpublish-link-input[readonly] { | ||
width: 100%; | ||
border: 1px solid $light-gray-500; | ||
padding: 10px; | ||
border-radius: $button-style__radius-roundrect; | ||
margin: 15px 0; | ||
background: $white; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
} | ||
|
||
.post-publish-panel__postpublish-header { | ||
font-weight: 500; | ||
} |
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.
There's no issue here, but this pattern is so easy to get wrong, makes me wonder if we ought to explore a higher-order component like https://www.npmjs.com/package/@hocs/safe-timers or our own.
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.
mmm! sounds like a good idea to me.