Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix visibility of the template Welcome Guide in the Site Editor #64789

Merged
merged 6 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions packages/edit-site/src/components/welcome-guide/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ import { __ } from '@wordpress/i18n';
import { store as preferencesStore } from '@wordpress/preferences';
import { store as editorStore } from '@wordpress/editor';

/**
* Internal dependencies
*/
import { store as editSiteStore } from '../../store';

export default function WelcomeGuideTemplate() {
const { toggle } = useDispatch( preferencesStore );

Expand All @@ -24,13 +19,14 @@ export default function WelcomeGuideTemplate() {
'core/edit-site',
'welcomeGuide'
);
const { isPage } = select( editSiteStore );
const { getCurrentPostType } = select( editorStore );
const { getCurrentPostType, getEditorSettings } = select( editorStore );
const hasBackNavigation =
!! getEditorSettings().onNavigateToPreviousEntityRecord;
return (
isTemplateActive &&
! isEditorActive &&
isPage() &&
getCurrentPostType() === 'wp_template'
getCurrentPostType() === 'wp_template' &&
hasBackNavigation
);
}, [] );

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
Loading