From 0a23261d2972d417ae5d7e8f97b8aab30e4d2ed6 Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Mon, 22 Jul 2024 19:15:06 +0200 Subject: [PATCH] Site Editor: remove snackbars Fixes #38442 --- .../jetpack/changelog/rm-site-snackbars | 4 + .../plugins/jetpack/extensions/index.json | 1 - .../plugins/site-editor-snackbars/editor.js | 4 - .../plugins/site-editor-snackbars/index.js | 76 ------------------- .../site-editor-snackbars.php | 29 ------- 5 files changed, 4 insertions(+), 110 deletions(-) create mode 100644 projects/plugins/jetpack/changelog/rm-site-snackbars delete mode 100644 projects/plugins/jetpack/extensions/plugins/site-editor-snackbars/editor.js delete mode 100644 projects/plugins/jetpack/extensions/plugins/site-editor-snackbars/index.js delete mode 100644 projects/plugins/jetpack/extensions/plugins/site-editor-snackbars/site-editor-snackbars.php diff --git a/projects/plugins/jetpack/changelog/rm-site-snackbars b/projects/plugins/jetpack/changelog/rm-site-snackbars new file mode 100644 index 0000000000000..31c8eff382313 --- /dev/null +++ b/projects/plugins/jetpack/changelog/rm-site-snackbars @@ -0,0 +1,4 @@ +Significance: patch +Type: enhancement + +Site Editor: remove extra site editor notices in favor of the ones provided by WordPress directly. diff --git a/projects/plugins/jetpack/extensions/index.json b/projects/plugins/jetpack/extensions/index.json index fb51b70578947..551d3ed6fd8b2 100644 --- a/projects/plugins/jetpack/extensions/index.json +++ b/projects/plugins/jetpack/extensions/index.json @@ -50,7 +50,6 @@ "payments-intro", "post-publish-qr-post-panel", "payment-buttons", - "site-editor-snackbars", "videopress/video", "ai-assistant-support", "ai-assistant-form-support", diff --git a/projects/plugins/jetpack/extensions/plugins/site-editor-snackbars/editor.js b/projects/plugins/jetpack/extensions/plugins/site-editor-snackbars/editor.js deleted file mode 100644 index f77fa9326a0e3..0000000000000 --- a/projects/plugins/jetpack/extensions/plugins/site-editor-snackbars/editor.js +++ /dev/null @@ -1,4 +0,0 @@ -import { registerJetpackPlugin } from '@automattic/jetpack-shared-extension-utils'; -import { name, settings } from '.'; - -registerJetpackPlugin( name, settings ); diff --git a/projects/plugins/jetpack/extensions/plugins/site-editor-snackbars/index.js b/projects/plugins/jetpack/extensions/plugins/site-editor-snackbars/index.js deleted file mode 100644 index bdcfaa2088a2d..0000000000000 --- a/projects/plugins/jetpack/extensions/plugins/site-editor-snackbars/index.js +++ /dev/null @@ -1,76 +0,0 @@ -import { subscribe, useDispatch, useSelect } from '@wordpress/data'; -import { useEffect, useState } from '@wordpress/element'; -import { sprintf, __ } from '@wordpress/i18n'; - -const SiteEditorSnackbars = () => { - const [ canvasMode, setCanvasMode ] = useState(); - - const { createInfoNotice, removeNotice } = useDispatch( 'core/notices' ); - - const { entityTitle, entityType, isSiteEditor } = useSelect( select => { - if ( ! select( 'core/edit-site' ) ) { - return { isSiteEditor: false }; - } - - const { getEditedPostType, getEditedPostId } = select( 'core/edit-site' ); - const { getEntityRecord, getPostType } = select( 'core' ); - - const entityRecord = getEntityRecord( 'postType', getEditedPostType(), getEditedPostId() ); - const postType = getPostType( getEditedPostType() ); - - return { - isSiteEditor: true, - entityTitle: entityRecord?.title?.raw ?? '', - entityType: postType?.labels?.singular_name ?? '', - }; - } ); - - // Since Gutenberg doesn't provide a stable selector to get the current canvas mode, - // we need to infer it from the URL. - useEffect( () => { - if ( ! isSiteEditor ) { - return; - } - - const unsubscribe = subscribe( () => { - // Gutenberg adds a `canvas` query param after changing the canvas mode, but - // the subscriber callback runs before the URL actually changes, so we need - // to delay its execution. - setTimeout( () => { - const params = new URLSearchParams( window.location.search ); - - if ( ! params.has( 'canvas' ) ) { - return unsubscribe(); - } - - setCanvasMode( params.get( 'canvas' ) ); - }, 0 ); - }, 'core/edit-site' ); - - return () => unsubscribe(); - }, [ isSiteEditor ] ); - - // Show a snackbar indicating what's being edited. - useEffect( () => { - const noticeId = 'jetpack/site-editor/snackbars'; - removeNotice( noticeId ); - - if ( ! isSiteEditor || canvasMode !== 'edit' || ! entityTitle || ! entityType ) { - return; - } - - const message = sprintf( - /* translators: %1$s and %2$s are the title and type, respectively, of the entity being edited (e.g. "Editing the Index template", or "Editing the Header template part").*/ - __( 'Editing the %1$s %2$s', 'jetpack' ), - entityTitle, - entityType.toLowerCase() - ); - createInfoNotice( message, { id: noticeId, type: 'snackbar' } ); - }, [ isSiteEditor, canvasMode, createInfoNotice, removeNotice, entityTitle, entityType ] ); - - return null; -}; - -export const name = 'site-editor-snackbars'; - -export const settings = { render: SiteEditorSnackbars }; diff --git a/projects/plugins/jetpack/extensions/plugins/site-editor-snackbars/site-editor-snackbars.php b/projects/plugins/jetpack/extensions/plugins/site-editor-snackbars/site-editor-snackbars.php deleted file mode 100644 index 51b0a78b8c38f..0000000000000 --- a/projects/plugins/jetpack/extensions/plugins/site-editor-snackbars/site-editor-snackbars.php +++ /dev/null @@ -1,29 +0,0 @@ -