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

Patterns: Add a preference to disable the loading the of the choose pattern modal #56307

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
15 changes: 14 additions & 1 deletion packages/edit-post/src/components/preferences-modal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,16 @@ import {
import MetaBoxesSection from './meta-boxes-section';
import { store as editPostStore } from '../../store';
import BlockManager from '../block-manager';
import { useStartPatterns } from '../start-page-options';

export const PREFERENCES_MODAL_NAME = 'edit-post/preferences';

export default function EditPostPreferencesModal() {
const isLargeViewport = useViewportMatch( 'medium' );
const { closeModal } = useDispatch( interfaceStore );
const starterPatterns = useStartPatterns();
const themeHasStarterPatterns = starterPatterns.length > 0;

const [ isModalActive, showBlockBreadcrumbsOption ] = useSelect(
( select ) => {
const { getEditorSettings } = select( editorStore );
Expand Down Expand Up @@ -143,6 +147,15 @@ export default function EditPostPreferencesModal() {
) }
label={ __( 'Use theme styles' ) }
/>
{ themeHasStarterPatterns && (
<EnableFeature
featureName="enableChoosePatternModal"
help={ __(
'Shows starter patterns when creating a new page.'
) }
label={ __( 'Show starter patterns' ) }
/>
) }
{ showBlockBreadcrumbsOption && (
<EnableFeature
featureName="showBlockBreadcrumbs"
Expand Down Expand Up @@ -252,7 +265,7 @@ export default function EditPostPreferencesModal() {
),
},
],
[ isLargeViewport, showBlockBreadcrumbsOption ]
[ isLargeViewport, showBlockBreadcrumbsOption, themeHasStarterPatterns ]
);

if ( ! isModalActive ) {
Expand Down
17 changes: 14 additions & 3 deletions packages/edit-post/src/components/start-page-options/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ import {
import { useSelect, useDispatch } from '@wordpress/data';
import { useAsyncList } from '@wordpress/compose';
import { store as editorStore } from '@wordpress/editor';
import { store as preferencesStore } from '@wordpress/preferences';
import { store as interfaceStore } from '@wordpress/interface';

/**
* Internal dependencies
*/
import { store as editPostStore } from '../../store';
import { PREFERENCES_MODAL_NAME } from '../preferences-modal';

function useStartPatterns() {
export function useStartPatterns() {
// A pattern is a start pattern if it includes 'core/post-content' in its blockTypes,
// and it has no postTypes declared and the current post type is page or if
// the current post type is part of the postTypes declared.
Expand Down Expand Up @@ -92,11 +95,19 @@ export default function StartPageOptions() {
const shouldEnableModal = useSelect( ( select ) => {
const { isCleanNewPost } = select( editorStore );
const { isEditingTemplate, isFeatureActive } = select( editPostStore );

const enableChoosePatternModal = select( preferencesStore ).get(
'core/edit-post',
'enableChoosePatternModal'
);
const preferencesModalActive = select( interfaceStore ).isModalActive(
PREFERENCES_MODAL_NAME
);
return (
! isEditingTemplate() &&
! isFeatureActive( 'welcomeGuide' ) &&
isCleanNewPost()
isCleanNewPost() &&
enableChoosePatternModal &&
! preferencesModalActive
);
}, [] );

Expand Down
1 change: 1 addition & 0 deletions packages/edit-post/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export function initializeEditor(
showBlockBreadcrumbs: true,
showIconLabels: false,
showListViewByDefault: false,
enableChoosePatternModal: true,
themeStyles: true,
welcomeGuide: true,
welcomeGuideTemplate: true,
Expand Down
Loading