Add a workaround for replacing core notice Site updated
I considered doing this using a filter 'i18n.gettext', but with this approach, we would just replace the text. The notice also contained an action with a link to the site's homepage, so I chose this mechanism instead. Let's see if there will be more use-cases. We can eventually move it somewhere into the store and proxy all messages via our store. [MAILPOET-6336]
This commit is contained in:
committed by
Rostislav Wolný
parent
2334805b95
commit
411943f39b
@ -1,4 +1,6 @@
|
|||||||
|
import { useMemo } from '@wordpress/element';
|
||||||
import { SnackbarList } from '@wordpress/components';
|
import { SnackbarList } from '@wordpress/components';
|
||||||
|
import { __ } from '@wordpress/i18n';
|
||||||
import { useSelect, useDispatch } from '@wordpress/data';
|
import { useSelect, useDispatch } from '@wordpress/data';
|
||||||
import { store as noticesStore } from '@wordpress/notices';
|
import { store as noticesStore } from '@wordpress/notices';
|
||||||
|
|
||||||
@ -12,11 +14,33 @@ export function EditorSnackbars( { context = 'email-editor' } ) {
|
|||||||
[ context ]
|
[ context ]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Some global notices are not suitable for the email editor context
|
||||||
|
// This map allows us to change the content of the notice
|
||||||
|
const globalNoticeChangeMap = useMemo( () => {
|
||||||
|
return {
|
||||||
|
'site-editor-save-success': {
|
||||||
|
content: __( 'Template updated.', 'mailpoet' ),
|
||||||
|
removeActions: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}, [] );
|
||||||
|
|
||||||
const { removeNotice } = useDispatch( noticesStore );
|
const { removeNotice } = useDispatch( noticesStore );
|
||||||
|
|
||||||
const snackbarNotices = notices.filter(
|
const snackbarNotices = notices
|
||||||
( { type } ) => type === 'snackbar'
|
.filter( ( { type } ) => type === 'snackbar' )
|
||||||
);
|
.map( ( notice ) => {
|
||||||
|
if ( ! globalNoticeChangeMap[ notice.id ] ) {
|
||||||
|
return notice;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
...notice,
|
||||||
|
content: globalNoticeChangeMap[ notice.id ].content,
|
||||||
|
actions: globalNoticeChangeMap[ notice.id ].removeActions
|
||||||
|
? []
|
||||||
|
: notice.actions,
|
||||||
|
};
|
||||||
|
} );
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SnackbarList
|
<SnackbarList
|
||||||
|
Reference in New Issue
Block a user