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
Changes from 1 commit
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
35 changes: 13 additions & 22 deletions packages/edit-site/src/components/welcome-guide/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,27 @@ import { Guide } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { store as preferencesStore } from '@wordpress/preferences';
import { store as editorStore } from '@wordpress/editor';
import { usePrevious } from '@wordpress/compose';

/**
* Internal dependencies
*/
import useEditedEntityRecord from '../use-edited-entity-record';

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

const {
postId,
isEditorActive,
isTemplateActive,
isPostTypeTemplate,
hasBackNavigation,
} = useSelect( ( select ) => {
const { getCurrentPostId, getCurrentPostType, getEditorSettings } =
select( editorStore );
const edited = useEditedEntityRecord();
const isPostTypeTemplate = edited.record.type === 'wp_template';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const isPostTypeTemplate = edited.record.type === 'wp_template';
const isPostTypeTemplate = edited.record?.type === 'wp_template';

edited.record can be false on the first load.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aw, good catch. Yet in this case the optional chaining operator isn’t truly suited. Still, I’m not against trying to make this more explicit. I decided to leverage the isLoaded property in the return value 29bfbc0. Once that becomes true then record won’t be false.

const { isActive, hasPreviousEntity } = useSelect( ( select ) => {
const { getEditorSettings } = select( editorStore );
const { get } = select( preferencesStore );
return {
postId: getCurrentPostId(),
isEditorActive: get( 'core/edit-site', 'welcomeGuide' ),
isTemplateActive: get( 'core/edit-site', 'welcomeGuideTemplate' ),
isPostTypeTemplate: getCurrentPostType() === 'wp_template',
hasBackNavigation:
isActive: get( 'core/edit-site', 'welcomeGuideTemplate' ),
hasPreviousEntity:
!! getEditorSettings().onNavigateToPreviousEntityRecord,
};
}, [] );
const priorPostId = usePrevious( postId );
const isVisible =
postId !== priorPostId &&
isTemplateActive &&
! isEditorActive &&
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ve removed the ! isEditorActive condition because hasPreviousEntity makes it redundant. The editor welcome guide can’t be visible when editing an entity that was arrived at through another entity.

isPostTypeTemplate &&
hasBackNavigation;
const isVisible = isActive && isPostTypeTemplate && hasPreviousEntity;

if ( ! isVisible ) {
return null;
Expand Down
Loading