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

Show proper message on trash of an entity #25563

Merged
merged 1 commit into from
Sep 24, 2020
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
9 changes: 8 additions & 1 deletion packages/editor/src/store/utils/notice-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,18 @@ export function getNotificationArgumentsForSaveSuccess( data ) {
const publishStatus = [ 'publish', 'private', 'future' ];
const isPublished = includes( publishStatus, previousPost.status );
const willPublish = includes( publishStatus, post.status );
const isTrashed = post.status === 'trash';

let noticeMessage;
let shouldShowLink = get( postType, [ 'viewable' ], false );

if ( ! isPublished && ! willPublish ) {
// Since there is not a label for a post_type `trash` action,
// we add the message manually.
// Reference: https://developer.wordpress.org/reference/functions/get_post_type_labels/
if ( isTrashed ) {
noticeMessage = `${ postType.labels.singular_name } trashed.`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The trashed part of this string is not translatable.
Also, we should avoid translatable strings made by concatenating a variable part with other text as this is not well translatbale in some languages. This should use a new post label to be introduced in core. Thus, it requires a patch for core. Note that in WordPress 5.0 new post labels were introduced for use in Gutenberg so this wouldn't be unprecedented.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened a ticket for this: https://core.trac.wordpress.org/ticket/51387

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ntsekouras a core ticket should not be a blocker for this.

Compat shims can be added to Gutenberg.

And even when that's not possible, we should not push strings that are not translatable.

shouldShowLink = false;
} else if ( ! isPublished && ! willPublish ) {
// If saving a non-published post, don't show notice.
noticeMessage = null;
} else if ( isPublished && ! willPublish ) {
Expand Down
6 changes: 6 additions & 0 deletions 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',
singular_name: 'post',
},
viewable: false,
};
Expand Down Expand Up @@ -74,6 +75,11 @@ describe( 'getNotificationArgumentsForSaveSuccess()', () => {
},
],
],
[
'when post is trashed',
[ 'publish', 'trash' ],
[ 'post trashed.', defaultExpectedAction ],
],
].forEach(
( [
description,
Expand Down