Skip to content

Commit

Permalink
Fix: Resetting template part causes notification saying it's been del…
Browse files Browse the repository at this point in the history
…ete (#62521)

Co-authored-by: jorgefilipecosta <[email protected]>
Co-authored-by: carolinan <[email protected]>
Co-authored-by: annezazu <[email protected]>
Co-authored-by: ramonjd <[email protected]>
  • Loading branch information
5 people authored Jun 18, 2024
1 parent c72542c commit 8ae6870
Showing 1 changed file with 54 additions and 21 deletions.
75 changes: 54 additions & 21 deletions packages/editor/src/store/private-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,13 @@ export const revertTemplate =
export const removeTemplates =
( items ) =>
async ( { registry } ) => {
const isResetting = items.every(
( item ) =>
!! item &&
( item.has_theme_file ||
( item.templatePart && item.templatePart.has_theme_file ) )
);

const promiseResult = await Promise.allSettled(
items.map( ( item ) => {
return registry
Expand All @@ -395,13 +402,21 @@ export const removeTemplates =
typeof items[ 0 ].title === 'string'
? items[ 0 ].title
: items[ 0 ].title?.rendered;
successMessage = sprintf(
/* translators: The template/part's name. */
__( '"%s" deleted.' ),
decodeEntities( title )
);
successMessage = isResetting
? sprintf(
/* translators: The template/part's name. */
__( '"%s" reset.' ),
decodeEntities( title )
)
: sprintf(
/* translators: The template/part's name. */
__( '"%s" deleted.' ),
decodeEntities( title )
);
} else {
successMessage = __( 'Items deleted.' );
successMessage = isResetting
? __( 'Items reset.' )
: __( 'Items deleted.' );
}

registry
Expand All @@ -418,9 +433,9 @@ export const removeTemplates =
if ( promiseResult[ 0 ].reason?.message ) {
errorMessage = promiseResult[ 0 ].reason.message;
} else {
errorMessage = __(
'An error occurred while deleting the item.'
);
errorMessage = isResetting
? __( 'An error occurred while reverting the item.' )
: __( 'An error occurred while deleting the item.' );
}
// If we were trying to delete a multiple templates
} else {
Expand All @@ -438,19 +453,37 @@ export const removeTemplates =
'An error occurred while deleting the items.'
);
} else if ( errorMessages.size === 1 ) {
errorMessage = sprintf(
/* translators: %s: an error message */
__( 'An error occurred while deleting the items: %s' ),
[ ...errorMessages ][ 0 ]
);
errorMessage = isResetting
? sprintf(
/* translators: %s: an error message */
__(
'An error occurred while reverting the items: %s'
),
[ ...errorMessages ][ 0 ]
)
: sprintf(
/* translators: %s: an error message */
__(
'An error occurred while deleting the items: %s'
),
[ ...errorMessages ][ 0 ]
);
} else {
sprintf(
/* translators: %s: a list of comma separated error messages */
__(
'Some errors occurred while deleting the items: %s'
),
[ ...errorMessages ].join( ',' )
);
errorMessage = isResetting
? sprintf(
/* translators: %s: a list of comma separated error messages */
__(
'Some errors occurred while reverting the items: %s'
),
[ ...errorMessages ].join( ',' )
)
: sprintf(
/* translators: %s: a list of comma separated error messages */
__(
'Some errors occurred while deleting the items: %s'
),
[ ...errorMessages ].join( ',' )
);
}
}
registry
Expand Down

0 comments on commit 8ae6870

Please sign in to comment.