Skip to content

Commit

Permalink
Show 'View Preview' link for 'Draft Saved' snackbar notice (#39482)
Browse files Browse the repository at this point in the history
* Show 'View Preview' link in snackbar notice for Draft Saved

* Update strings for translation and consistency

* Update unit test to match updated string in notice

* Update another unit test to match updated string in notice
  • Loading branch information
brookewp authored Mar 22, 2022
1 parent c67d146 commit e6574eb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/editor/src/store/test/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ describe( 'Post actions', () => {
expect( notices ).toMatchObject( [
{
status: 'success',
content: 'Draft saved',
content: 'Draft saved.',
},
] );
} );
Expand Down
7 changes: 4 additions & 3 deletions packages/editor/src/store/utils/notice-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ export function getNotificationArgumentsForSaveSuccess( data ) {

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

// Always should a notice, which will be spoken for accessibility.
if ( ! isPublished && ! willPublish ) {
// If saving a non-published post, don't show notice.
noticeMessage = __( 'Draft saved' );
shouldShowLink = false;
noticeMessage = __( 'Draft saved.' );
isDraft = true;
} else if ( isPublished && ! willPublish ) {
// If undoing publish status, show specific notice.
noticeMessage = postType.labels.item_reverted_to_draft;
Expand All @@ -65,7 +66,7 @@ export function getNotificationArgumentsForSaveSuccess( data ) {
const actions = [];
if ( shouldShowLink ) {
actions.push( {
label: postType.labels.view_item,
label: isDraft ? __( 'View Preview' ) : postType.labels.view_item,
url: post.link,
} );
}
Expand Down
2 changes: 1 addition & 1 deletion packages/editor/src/store/utils/test/notice-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe( 'getNotificationArgumentsForSaveSuccess()', () => {
[
'when previous post is not published and post will not be published',
[ 'draft', 'draft', false ],
[ 'Draft saved', defaultExpectedAction ],
[ 'Draft saved.', defaultExpectedAction ],
],
[
'when previous post is published and post will be unpublished',
Expand Down

0 comments on commit e6574eb

Please sign in to comment.