Skip to content

Commit

Permalink
Add snackbar
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Sep 13, 2021
1 parent b8e9e9f commit a25d9da
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
6 changes: 4 additions & 2 deletions packages/editor/src/store/test/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,15 @@ describe( 'Post generator actions', () => {
'yields an action for dispatching a success notice',
() => true,
() => {
if ( ! isAutosave && currentPostStatus === 'publish' ) {
if ( ! isAutosave ) {
const { value } = fulfillment.next( postType );
expect( value ).toEqual(
controls.dispatch(
noticesStore,
'createSuccessNotice',
'Updated Post',
currentPostStatus === 'publish'
? 'Updated Post'
: 'Saved',
{
actions: [],
id: 'SAVE_POST_NOTICE_ID',
Expand Down
36 changes: 17 additions & 19 deletions packages/editor/src/store/utils/notice-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ export function getNotificationArgumentsForSaveSuccess( data ) {
let noticeMessage;
let shouldShowLink = get( postType, [ 'viewable' ], false );

// Always should a notice, which will be spoken for accessibility.
if ( ! isPublished && ! willPublish ) {
// If saving a non-published post, don't show notice.
noticeMessage = null;
noticeMessage = __( 'Saved' );
shouldShowLink = false;
} else if ( isPublished && ! willPublish ) {
// If undoing publish status, show specific notice
noticeMessage = postType.labels.item_reverted_to_draft;
Expand All @@ -55,25 +57,21 @@ export function getNotificationArgumentsForSaveSuccess( data ) {
noticeMessage = postType.labels.item_updated;
}

if ( noticeMessage ) {
const actions = [];
if ( shouldShowLink ) {
actions.push( {
label: postType.labels.view_item,
url: post.link,
} );
}
return [
noticeMessage,
{
id: SAVE_POST_NOTICE_ID,
type: 'snackbar',
actions,
},
];
const actions = [];
if ( shouldShowLink ) {
actions.push( {
label: postType.labels.view_item,
url: post.link,
} );
}

return [];
return [
noticeMessage,
{
id: SAVE_POST_NOTICE_ID,
type: 'snackbar',
actions,
},
];
}

/**
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 ],
[],
[ 'Saved', defaultExpectedAction ],
],
[
'when previous post is published and post will be unpublished',
Expand Down

0 comments on commit a25d9da

Please sign in to comment.