Skip to content

Commit

Permalink
Editor: Improve conditions for displaying new page assembler (#68852)
Browse files Browse the repository at this point in the history
* Editor: Improve conditions for displaying new page assembler
* Add note as inline comment

Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: carolinan <[email protected]>
  • Loading branch information
3 people authored Jan 29, 2025
1 parent 73b8e2c commit 35ba7ef
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions packages/editor/src/components/start-page-options/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,8 @@ import { store as interfaceStore } from '@wordpress/interface';
import { store as editorStore } from '../../store';

export default function StartPageOptions() {
const { postId, shouldEnable } = useSelect( ( select ) => {
const {
isEditedPostDirty,
isEditedPostEmpty,
getCurrentPostId,
getCurrentPostType,
} = select( editorStore );
const { postId, enabled } = useSelect( ( select ) => {
const { getCurrentPostId, getCurrentPostType } = select( editorStore );
const preferencesModalActive =
select( interfaceStore ).isModalActive( 'editor/preferences' );
const choosePatternModalEnabled = select( preferencesStore ).get(
Expand All @@ -27,24 +22,37 @@ export default function StartPageOptions() {
);
return {
postId: getCurrentPostId(),
shouldEnable:
enabled:
choosePatternModalEnabled &&
! preferencesModalActive &&
! isEditedPostDirty() &&
isEditedPostEmpty() &&
'page' === getCurrentPostType(),
};
}, [] );
const { isEditedPostDirty, isEditedPostEmpty } = useSelect( editorStore );
const { setIsInserterOpened } = useDispatch( editorStore );

useEffect( () => {
if ( shouldEnable ) {
if ( ! enabled ) {
return;
}

const isFreshPage = ! isEditedPostDirty() && isEditedPostEmpty();
if ( isFreshPage ) {
setIsInserterOpened( {
tab: 'patterns',
category: 'core/starter-content',
} );
}
}, [ postId, shouldEnable, setIsInserterOpened ] );

// Note: The `postId` ensures the effect re-runs when pages are switched without remounting the component.
// Examples: changing pages in the List View, creating a new page via Command Palette.
}, [
postId,
enabled,
setIsInserterOpened,
isEditedPostDirty,
isEditedPostEmpty,
] );

return null;
}

1 comment on commit 35ba7ef

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in 35ba7ef.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/13025872796
📝 Reported issues:

Please sign in to comment.