From 661d6296fd0e37476a457ddf8ea555a74c643a48 Mon Sep 17 00:00:00 2001 From: Mitchell Austin Date: Tue, 3 Sep 2024 16:32:22 -0700 Subject: [PATCH] Fix visibility of the template Welcome Guide in the Site Editor (#64789) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Require previous entity record for display * Show template edit notice only if welcome guide isn’t active * Hack around flash of presence * Use a simpler hack around flash of presence * Use edited entity record hook for post type condition * Read record type only if edited entity hook says it’s loaded Co-authored-by: ramonjd Co-authored-by: annezazu Co-authored-by: colorful-tones Co-authored-by: talldan --- .../src/components/welcome-guide/template.js | 30 ++++++++----------- .../components/post-template/block-theme.js | 24 +++++++++------ 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/packages/edit-site/src/components/welcome-guide/template.js b/packages/edit-site/src/components/welcome-guide/template.js index 0e699e6b4b242..e6568a23bb3a3 100644 --- a/packages/edit-site/src/components/welcome-guide/template.js +++ b/packages/edit-site/src/components/welcome-guide/template.js @@ -10,29 +10,23 @@ import { store as editorStore } from '@wordpress/editor'; /** * Internal dependencies */ -import { store as editSiteStore } from '../../store'; +import useEditedEntityRecord from '../use-edited-entity-record'; export default function WelcomeGuideTemplate() { const { toggle } = useDispatch( preferencesStore ); - const isVisible = useSelect( ( select ) => { - const isTemplateActive = !! select( preferencesStore ).get( - 'core/edit-site', - 'welcomeGuideTemplate' - ); - const isEditorActive = !! select( preferencesStore ).get( - 'core/edit-site', - 'welcomeGuide' - ); - const { isPage } = select( editSiteStore ); - const { getCurrentPostType } = select( editorStore ); - return ( - isTemplateActive && - ! isEditorActive && - isPage() && - getCurrentPostType() === 'wp_template' - ); + const { isLoaded, record } = useEditedEntityRecord(); + const isPostTypeTemplate = isLoaded && record.type === 'wp_template'; + const { isActive, hasPreviousEntity } = useSelect( ( select ) => { + const { getEditorSettings } = select( editorStore ); + const { get } = select( preferencesStore ); + return { + isActive: get( 'core/edit-site', 'welcomeGuideTemplate' ), + hasPreviousEntity: + !! getEditorSettings().onNavigateToPreviousEntityRecord, + }; }, [] ); + const isVisible = isActive && isPostTypeTemplate && hasPreviousEntity; if ( ! isVisible ) { return null; diff --git a/packages/editor/src/components/post-template/block-theme.js b/packages/editor/src/components/post-template/block-theme.js index 7fcc5ead14f5b..62de10a2c715f 100644 --- a/packages/editor/src/components/post-template/block-theme.js +++ b/packages/editor/src/components/post-template/block-theme.js @@ -8,6 +8,7 @@ import { __ } from '@wordpress/i18n'; import { useEntityRecord, store as coreStore } from '@wordpress/core-data'; import { check } from '@wordpress/icons'; import { store as noticesStore } from '@wordpress/notices'; +import { store as preferencesStore } from '@wordpress/preferences'; /** * Internal dependencies @@ -43,6 +44,8 @@ export default function BlockThemeControl( { id } ) { }; }, [] ); + const { get: getPreference } = useSelect( preferencesStore ); + const { editedRecord: template, hasResolved } = useEntityRecord( 'postType', 'wp_template', @@ -75,6 +78,17 @@ export default function BlockThemeControl( { id } ) { }, ] : undefined; + + const mayShowTemplateEditNotice = () => { + if ( ! getPreference( 'core/edit-site', 'welcomeGuideTemplate' ) ) { + createSuccessNotice( + __( + 'Editing template. Changes made here affect all posts and pages that use the template.' + ), + { type: 'snackbar', actions: notificationAction } + ); + } + }; return ( { __( 'Edit template' ) }