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

Revert triggering multi-entity save panel in post with meta changes #63412

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
21 changes: 4 additions & 17 deletions packages/editor/src/components/post-publish-button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { compose } from '@wordpress/compose';
*/
import PublishButtonLabel from './label';
import { store as editorStore } from '../../store';
import { unlock } from '../../lock-unlock';

const noop = () => {};

Expand Down Expand Up @@ -46,24 +45,14 @@ export class PostPublishButton extends Component {

createOnClick( callback ) {
return ( ...args ) => {
const {
hasNonPostEntityChanges,
hasPostMetaChanges,
setEntitiesSavedStatesCallback,
isPublished,
} = this.props;
const { hasNonPostEntityChanges, setEntitiesSavedStatesCallback } =
this.props;
// If a post with non-post entities is published, but the user
// elects to not save changes to the non-post entities, those
// entities will still be dirty when the Publish button is clicked.
// We also need to check that the `setEntitiesSavedStatesCallback`
// prop was passed. See https://github.com/WordPress/gutenberg/pull/37383
//
// TODO: Explore how to manage `hasPostMetaChanges` and pre-publish workflow properly.
if (
( hasNonPostEntityChanges ||
( hasPostMetaChanges && isPublished ) ) &&
setEntitiesSavedStatesCallback
) {
if ( hasNonPostEntityChanges && setEntitiesSavedStatesCallback ) {
// The modal for multiple entity saving will open,
// hold the callback for saving/publishing the post
// so that we can call it if the post entity is checked.
Expand Down Expand Up @@ -226,8 +215,7 @@ export default compose( [
isSavingNonPostEntityChanges,
getEditedPostAttribute,
getPostEdits,
hasPostMetaChanges,
} = unlock( select( editorStore ) );
} = select( editorStore );
return {
isSaving: isSavingPost(),
isAutoSaving: isAutosavingPost(),
Expand All @@ -244,7 +232,6 @@ export default compose( [
postStatus: getEditedPostAttribute( 'status' ),
postStatusHasChanged: getPostEdits()?.status,
hasNonPostEntityChanges: hasNonPostEntityChanges(),
hasPostMetaChanges: hasPostMetaChanges(),
isSavingNonPostEntityChanges: isSavingNonPostEntityChanges(),
};
} ),
Expand Down
5 changes: 1 addition & 4 deletions packages/editor/src/components/save-publish-panels/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import PostPublishPanel from '../post-publish-panel';
import PluginPrePublishPanel from '../plugin-pre-publish-panel';
import PluginPostPublishPanel from '../plugin-post-publish-panel';
import { store as editorStore } from '../../store';
import { unlock } from '../../lock-unlock';

const { Fill, Slot } = createSlotFill( 'ActionsPanel' );

Expand All @@ -41,9 +40,7 @@ export default function SavePublishPanels( {
isEditedPostDirty,
hasNonPostEntityChanges,
} = select( editorStore );
const _hasOtherEntitiesChanges =
hasNonPostEntityChanges() ||
unlock( select( editorStore ) ).hasPostMetaChanges();
const _hasOtherEntitiesChanges = hasNonPostEntityChanges();
return {
publishSidebarOpened: isPublishSidebarOpened(),
isPublishable:
Expand Down
94 changes: 0 additions & 94 deletions test/e2e/specs/editor/various/publish-panel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,98 +113,4 @@ test.describe( 'Post publish panel', () => {
} )
).toBeFocused();
} );

test( 'should show panel and indicator when metadata has been modified', async ( {
admin,
editor,
page,
} ) => {
await admin.createNewPost( {
title: 'Test metadata changes with save panel',
} );
await editor.insertBlock( {
name: 'core/paragraph',
attributes: {
content: 'paragraph default content',
metadata: {
bindings: {
content: {
source: 'core/post-meta',
args: { key: 'text_custom_field' },
},
},
},
},
} );
const postId = await editor.publishPost();
const metadataUtils = new MetadataUtils( page );
await metadataUtils.modifyPostMetadata(
'post',
postId,
'text_custom_field',
'test value'
);
const editorTopBar = page.getByRole( 'region', {
name: 'Editor top bar',
} );

const saveButton = editorTopBar.getByRole( 'button', {
name: 'Save',
exact: true,
} );

await expect( saveButton ).toBeVisible();

await saveButton.click();

const publishPanel = page.getByRole( 'region', {
name: 'Editor publish',
} );

await expect( publishPanel ).toBeVisible();

const postMetaPanel = publishPanel.locator(
'.entities-saved-states__changes'
);

await expect( postMetaPanel ).toBeVisible();
} );
} );

/**
* Utilities for working with metadata.
*
* @param postType
* @param postId
* @param metaKey
* @param metaValue
*/
class MetadataUtils {
constructor( page ) {
this.page = page;
}

async modifyPostMetadata( postType, postId, metaKey, metaValue ) {
const parameters = {
postType,
postId,
metaKey,
metaValue,
};

await this.page.evaluate( ( _parameters ) => {
window.wp.data
.dispatch( 'core' )
.editEntityRecord(
'postType',
_parameters.postType,
_parameters.postId,
{
meta: {
[ _parameters.metaKey ]: _parameters.metaValue,
},
}
);
}, parameters );
}
}
Loading