Skip to content

Commit

Permalink
Simplify the template revert snackbar by showing template name which …
Browse files Browse the repository at this point in the history
…removes the need to remove the notice (#50626)
  • Loading branch information
glendaviesnz authored May 15, 2023
1 parent 9e6b646 commit efaadb1
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions packages/edit-site/src/components/list/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import { useDispatch } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import { __ } from '@wordpress/i18n';
import { __, sprintf } from '@wordpress/i18n';
import { DropdownMenu, MenuGroup, MenuItem } from '@wordpress/components';
import { moreVertical } from '@wordpress/icons';
import { store as noticesStore } from '@wordpress/notices';
Expand All @@ -19,7 +19,7 @@ import RenameMenuItem from './rename-menu-item';
export default function Actions( { template } ) {
const { removeTemplate, revertTemplate } = useDispatch( editSiteStore );
const { saveEditedEntityRecord } = useDispatch( coreStore );
const { createSuccessNotice, createErrorNotice, removeNotice } =
const { createSuccessNotice, createErrorNotice } =
useDispatch( noticesStore );
const isRemovable = isTemplateRemovable( template );
const isRevertable = isTemplateRevertable( template );
Expand All @@ -29,24 +29,25 @@ export default function Actions( { template } ) {
}

async function revertAndSaveTemplate() {
const noticeId = 'edit-site-template-reverted';
removeNotice( noticeId );
try {
await revertTemplate( template, { allowUndo: false } );
await saveEditedEntityRecord(
'postType',
template.type,
template.id
);
const notice =
template.type === 'wp_template'
? __( 'Template reverted.' )
: __( 'Template part reverted.' );

createSuccessNotice( notice, {
type: 'snackbar',
id: noticeId,
} );
createSuccessNotice(
sprintf(
/* translators: The template/part's name. */
__( '"%s" reverted.' ),
template.title.rendered
),
{
type: 'snackbar',
id: 'edit-site-template-reverted',
}
);
} catch ( error ) {
const errorMessage =
error.message && error.code !== 'unknown_error'
Expand Down

0 comments on commit efaadb1

Please sign in to comment.