Skip to content

Commit

Permalink
Prevent stacking of the entity revert and site save notices (#50302)
Browse files Browse the repository at this point in the history
  • Loading branch information
glendaviesnz authored May 15, 2023
1 parent a9fbca5 commit 024d004
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
12 changes: 9 additions & 3 deletions packages/edit-site/src/components/list/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ import RenameMenuItem from './rename-menu-item';
export default function Actions( { template } ) {
const { removeTemplate, revertTemplate } = useDispatch( editSiteStore );
const { saveEditedEntityRecord } = useDispatch( coreStore );
const { createSuccessNotice, createErrorNotice } =
const { createSuccessNotice, createErrorNotice, removeNotice } =
useDispatch( noticesStore );

const isRemovable = isTemplateRemovable( template );
const isRevertable = isTemplateRevertable( template );

Expand All @@ -30,16 +29,23 @@ 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( __( 'Entity reverted.' ), {
createSuccessNotice( notice, {
type: 'snackbar',
id: noticeId,
} );
} catch ( error ) {
const errorMessage =
Expand Down
7 changes: 3 additions & 4 deletions packages/edit-site/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,8 @@ export function setIsSaveViewOpened( isOpen ) {
export const revertTemplate =
( template, { allowUndo = true } = {} ) =>
async ( { registry } ) => {
const noticeId = 'edit-site-template-reverted';
registry.dispatch( noticesStore ).removeNotice( noticeId );
if ( ! isTemplateRevertable( template ) ) {
registry
.dispatch( noticesStore )
Expand Down Expand Up @@ -466,17 +468,14 @@ export const revertTemplate =
.dispatch( noticesStore )
.createSuccessNotice( __( 'Template reverted.' ), {
type: 'snackbar',
id: noticeId,
actions: [
{
label: __( 'Undo' ),
onClick: undoRevert,
},
],
} );
} else {
registry
.dispatch( noticesStore )
.createSuccessNotice( __( 'Template reverted.' ) );
}
} catch ( error ) {
const errorMessage =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export default function EntitiesSavedStates( { close, onSave = identity } ) {
const { __unstableMarkLastChangeAsPersistent } =
useDispatch( blockEditorStore );

const { createSuccessNotice, createErrorNotice } =
const { createSuccessNotice, createErrorNotice, removeNotice } =
useDispatch( noticesStore );

// To group entities by type.
Expand Down Expand Up @@ -148,6 +148,8 @@ export default function EntitiesSavedStates( { close, onSave = identity } ) {
};

const saveCheckedEntitiesAndActivate = () => {
const saveNoticeId = 'site-editor-save-success';
removeNotice( saveNoticeId );
const entitiesToSave = dirtyEntityRecords.filter(
( { kind, name, key, property } ) => {
return ! unselectedEntities.some(
Expand Down Expand Up @@ -208,6 +210,7 @@ export default function EntitiesSavedStates( { close, onSave = identity } ) {
} else {
createSuccessNotice( __( 'Site updated.' ), {
type: 'snackbar',
id: saveNoticeId,
} );
}
} )
Expand Down

0 comments on commit 024d004

Please sign in to comment.