Skip to content

Commit

Permalink
Fix wrong notification message shown when an entity is moved to trash
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsekouras committed Oct 9, 2023
1 parent cd0035d commit 76e8066
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
8 changes: 7 additions & 1 deletion packages/editor/src/store/test/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const postTypeEntity = {
item_updated: 'Updated Post',
item_published: 'Post published',
item_reverted_to_draft: 'Post reverted to draft.',
item_trashed: 'Post trashed.',
},
};

Expand Down Expand Up @@ -286,7 +287,12 @@ describe( 'Post actions', () => {

// Check that there are no notices.
const notices = registry.select( noticesStore ).getNotices();
expect( notices ).toEqual( [] );
expect( notices ).toMatchObject( [
{
status: 'success',
content: 'Post trashed.',
},
] );

// Check the new status.
const { status } = registry.select( editorStore ).getCurrentPost();
Expand Down
12 changes: 6 additions & 6 deletions packages/editor/src/store/utils/notice-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ export function getNotificationArgumentsForSaveSuccess( data ) {
return [];
}

// No notice is shown after trashing a post
if ( post.status === 'trash' && previousPost.status !== 'trash' ) {
return [];
}

const publishStatus = [ 'publish', 'private', 'future' ];
const isPublished = publishStatus.includes( previousPost.status );
const willPublish = publishStatus.includes( post.status );
const willTrash =
post.status === 'trash' && previousPost.status !== 'trash';

let noticeMessage;
let shouldShowLink = postType?.viewable ?? false;
let isDraft;

// Always should a notice, which will be spoken for accessibility.
if ( ! isPublished && ! willPublish ) {
if ( willTrash ) {
noticeMessage = postType.labels.item_trashed;
shouldShowLink = false;
} else if ( ! isPublished && ! willPublish ) {
// If saving a non-published post, don't show notice.
noticeMessage = __( 'Draft saved.' );
isDraft = true;
Expand Down
7 changes: 6 additions & 1 deletion packages/editor/src/store/utils/test/notice-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe( 'getNotificationArgumentsForSaveSuccess()', () => {
item_scheduled: 'scheduled',
item_updated: 'updated',
view_item: 'view',
item_trashed: 'trash',
},
viewable: false,
};
Expand Down Expand Up @@ -74,7 +75,11 @@ describe( 'getNotificationArgumentsForSaveSuccess()', () => {
},
],
],
[ 'when post will be trashed', [ 'publish', 'trash', true ], [] ],
[
'when post will be trashed',
[ 'publish', 'trash', true ],
[ 'trash', defaultExpectedAction ],
],
].forEach(
( [
description,
Expand Down

0 comments on commit 76e8066

Please sign in to comment.