Skip to content

Commit

Permalink
The update button should stay enabled when we have metaboxes
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Mar 6, 2018
1 parent d23c6d9 commit e24b917
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 12 deletions.
2 changes: 2 additions & 0 deletions edit-post/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ function Header( {
<PostPublishPanelToggle
isOpen={ isPublishSidebarOpen }
onToggle={ onTogglePublishSidebar }
forceIsDirty={ hasActiveMetaboxes }
forceIsSaving={ isSaving }
/>
<IconButton
icon="admin-generic"
Expand Down
14 changes: 13 additions & 1 deletion edit-post/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import {
isPublishSidebarOpened,
getActivePlugin,
getMetaBoxes,
hasMetaBoxes,
isSavingMetaBoxes,
} from '../../store/selectors';
import { closePublishSidebar } from '../../store/actions';
import PluginsPanel from '../../components/plugins-panel/index.js';
Expand All @@ -62,6 +64,8 @@ function Layout( {
onClosePublishSidebar,
plugin,
metaBoxes,
hasActiveMetaboxes,
isSaving,
} ) {
const isSidebarOpened = layoutHasOpenSidebar &&
( openedGeneralSidebar !== 'plugin' || getSidebarSettings( plugin ) );
Expand Down Expand Up @@ -95,7 +99,13 @@ function Layout( {
<MetaBoxes location="advanced" />
</div>
</div>
{ publishSidebarOpen && <PostPublishPanel onClose={ onClosePublishSidebar } /> }
{ publishSidebarOpen && (
<PostPublishPanel
onClose={ onClosePublishSidebar }
forceIsDirty={ hasActiveMetaboxes }
forceIsSaving={ isSaving }
/>
) }
{
openedGeneralSidebar !== null && <GeneralSidebar
openedGeneralSidebar={ openedGeneralSidebar } />
Expand All @@ -114,6 +124,8 @@ export default connect(
hasFixedToolbar: isFeatureActive( state, 'fixedToolbar' ),
plugin: getActivePlugin( state ),
metaBoxes: getMetaBoxes( state ),
hasActiveMetaboxes: hasMetaBoxes( state ),
isSaving: isSavingMetaBoxes( state ),
} ),
{
onClosePublishSidebar: closePublishSidebar,
Expand Down
9 changes: 5 additions & 4 deletions editor/components/post-publish-button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export function PostPublishButton( {
isSaveable,
user,
onSubmit = noop,
forceIsSaving,
} ) {
const isButtonEnabled = user.data && ! isSaving && isPublishable && isSaveable;
const isContributor = ! get( user.data, [ 'post_type_capabilities', 'publish_posts' ], false );
Expand Down Expand Up @@ -69,18 +70,18 @@ export function PostPublishButton( {
disabled={ ! isButtonEnabled }
className={ className }
>
<PublishButtonLabel />
<PublishButtonLabel forceIsSaving={ forceIsSaving } />
</Button>
);
}

const applyConnect = connect(
( state ) => ( {
isSaving: isSavingPost( state ),
( state, { forceIsSaving, forceIsDirty } ) => ( {
isSaving: forceIsSaving || isSavingPost( state ),
isBeingScheduled: isEditedPostBeingScheduled( state ),
visibility: getEditedPostVisibility( state ),
isSaveable: isEditedPostSaveable( state ),
isPublishable: isEditedPostPublishable( state ),
isPublishable: forceIsDirty || isEditedPostPublishable( state ),
postType: getCurrentPostType( state ),
} ),
{
Expand Down
4 changes: 2 additions & 2 deletions editor/components/post-publish-button/label.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ export function PublishButtonLabel( {
}

const applyConnect = connect(
( state ) => ( {
( state, { forceIsSaving } ) => ( {
isPublished: isCurrentPostPublished( state ),
isBeingScheduled: isEditedPostBeingScheduled( state ),
isSaving: isSavingPost( state ),
isSaving: forceIsSaving || isSavingPost( state ),
isPublishing: isPublishingPost( state ),
postType: getCurrentPostType( state ),
} )
Expand Down
4 changes: 2 additions & 2 deletions editor/components/post-publish-panel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class PostPublishPanel extends Component {
}

render() {
const { onClose, user } = this.props;
const { onClose, user, forceIsDirty, forceIsSaving } = this.props;
const { loading, published } = this.state;
const canPublish = get( user.data, [ 'post_type_capabilities', 'publish_posts' ], false );

Expand All @@ -70,7 +70,7 @@ class PostPublishPanel extends Component {
<div className="editor-post-publish-panel__header">
{ ! published && (
<div className="editor-post-publish-panel__header-publish-button">
<PostPublishButton onSubmit={ this.onPublish } />
<PostPublishButton onSubmit={ this.onPublish } forceIsDirty={ forceIsDirty } forceIsSaving={ forceIsSaving } />
</div>
) }
{ published && (
Expand Down
17 changes: 14 additions & 3 deletions editor/components/post-publish-panel/toggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,28 @@ import {
getCurrentPostType,
} from '../../store/selectors';

function PostPublishPanelToggle( { user, isSaving, isPublishable, isSaveable, isPublished, isBeingScheduled, onToggle, isOpen } ) {
function PostPublishPanelToggle( {
user,
isSaving,
isPublishable,
isSaveable,
isPublished,
isBeingScheduled,
onToggle,
isOpen,
forceIsDirty,
forceIsSaving,
} ) {
const isButtonEnabled = (
! isSaving && isPublishable && isSaveable
! isSaving && ! forceIsSaving && isPublishable && isSaveable
) || isPublished;

const userCanPublishPosts = get( user.data, [ 'post_type_capabilities', 'publish_posts' ], false );
const isContributor = user.data && ! userCanPublishPosts;
const showToggle = ! isContributor && ! isPublished && ! isBeingScheduled;

if ( ! showToggle ) {
return <PostPublishButton />;
return <PostPublishButton forceIsDirty={ forceIsDirty } forceIsSaving={ forceIsSaving } />;
}

return (
Expand Down

0 comments on commit e24b917

Please sign in to comment.