Skip to content

Commit

Permalink
Fix visibility of the template Welcome Guide in the Site Editor (#64789)
Browse files Browse the repository at this point in the history
* 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 <ramonopoly@git.wordpress.org>
Co-authored-by: annezazu <annezazu@git.wordpress.org>
Co-authored-by: colorful-tones <colorful-tones@git.wordpress.org>
Co-authored-by: talldan <talldanwp@git.wordpress.org>
  • Loading branch information
5 people authored Sep 3, 2024
1 parent ef309ba commit 661d629
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
30 changes: 12 additions & 18 deletions packages/edit-site/src/components/welcome-guide/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 15 additions & 9 deletions packages/editor/src/components/post-template/block-theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -43,6 +44,8 @@ export default function BlockThemeControl( { id } ) {
};
}, [] );

const { get: getPreference } = useSelect( preferencesStore );

const { editedRecord: template, hasResolved } = useEntityRecord(
'postType',
'wp_template',
Expand Down Expand Up @@ -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 (
<DropdownMenu
popoverProps={ POPOVER_PROPS }
Expand All @@ -99,15 +113,7 @@ export default function BlockThemeControl( { id } ) {
postType: 'wp_template',
} );
onClose();
createSuccessNotice(
__(
'Editing template. Changes made here affect all posts and pages that use the template.'
),
{
type: 'snackbar',
actions: notificationAction,
}
);
mayShowTemplateEditNotice();
} }
>
{ __( 'Edit template' ) }
Expand Down

0 comments on commit 661d629

Please sign in to comment.