From fa78b66aea850d13e0621d0fcc6ddaf5ca3772f4 Mon Sep 17 00:00:00 2001 From: Ramon Date: Mon, 9 Sep 2024 09:41:03 +1000 Subject: [PATCH 1/9] Patterns: add opt out preference to the 'Choose a Pattern' modal when adding a page (#65026) * Adds a preference to disable the loading of the Choose a pattern modal when adding new pages. * Return an empty array from the memoized value of useStartPatterns() so that the preferences modal has a value to test. * Don't reset the `isClosed` value in the same editor session. This prevents the modal popping open between page > template part > page navigation. Co-authored-by: ramonjd Co-authored-by: andrewserong Co-authored-by: kevin940726 Co-authored-by: noisysocks Co-authored-by: jasmussen Co-authored-by: jakobtrost Co-authored-by: johnstonphilip Co-authored-by: annezazu Co-authored-by: MattrCoUk Co-authored-by: jasonbahl Co-authored-by: colorful-tones Co-authored-by: Blindmikey Co-authored-by: richtabor Co-authored-by: luminuu Co-authored-by: stokesman Co-authored-by: jordesign --- packages/edit-post/src/index.js | 1 + packages/edit-site/src/index.js | 1 + packages/edit-site/src/posts.js | 1 + .../src/components/preferences-modal/index.js | 13 +++++ .../components/start-page-options/index.js | 54 ++++++++++--------- 5 files changed, 44 insertions(+), 26 deletions(-) diff --git a/packages/edit-post/src/index.js b/packages/edit-post/src/index.js index 51abac654da295..daf789cb0a2ec9 100644 --- a/packages/edit-post/src/index.js +++ b/packages/edit-post/src/index.js @@ -70,6 +70,7 @@ export function initializeEditor( showBlockBreadcrumbs: true, showIconLabels: false, showListViewByDefault: false, + enableChoosePatternModal: true, isPublishSidebarEnabled: true, } ); diff --git a/packages/edit-site/src/index.js b/packages/edit-site/src/index.js index 4ed5b96e3844d1..1aceecc4d8b1fc 100644 --- a/packages/edit-site/src/index.js +++ b/packages/edit-site/src/index.js @@ -79,6 +79,7 @@ export function initializeEditor( id, settings ) { openPanels: [ 'post-status' ], showBlockBreadcrumbs: true, showListViewByDefault: false, + enableChoosePatternModal: true, } ); if ( window.__experimentalMediaProcessing ) { diff --git a/packages/edit-site/src/posts.js b/packages/edit-site/src/posts.js index 9e2582ac23328a..78d823b56c4c11 100644 --- a/packages/edit-site/src/posts.js +++ b/packages/edit-site/src/posts.js @@ -72,6 +72,7 @@ export function initializePostsDashboard( id, settings ) { openPanels: [ 'post-status' ], showBlockBreadcrumbs: true, showListViewByDefault: false, + enableChoosePatternModal: true, } ); dispatch( editSiteStore ).updateSettings( settings ); diff --git a/packages/editor/src/components/preferences-modal/index.js b/packages/editor/src/components/preferences-modal/index.js index e7cc637dd0aed0..a8cfd8245522cd 100644 --- a/packages/editor/src/components/preferences-modal/index.js +++ b/packages/editor/src/components/preferences-modal/index.js @@ -26,6 +26,7 @@ import PageAttributesCheck from '../page-attributes/check'; import PostTypeSupportCheck from '../post-type-support-check'; import { store as editorStore } from '../../store'; import { unlock } from '../../lock-unlock'; +import { useStartPatterns } from '../start-page-options'; const { PreferencesModal, @@ -57,6 +58,7 @@ export default function EditorPreferencesModal( { extraSections = {} } ) { const { setIsListViewOpened, setIsInserterOpened } = useDispatch( editorStore ); const { set: setPreference } = useDispatch( preferencesStore ); + const hasStarterPatterns = !! useStartPatterns().length; const sections = useMemo( () => @@ -97,6 +99,16 @@ export default function EditorPreferencesModal( { extraSections = {} } ) { 'Allow right-click contextual menus' ) } /> + { hasStarterPatterns && ( + + ) } { - // filter patterns without postTypes declared if the current postType is page - // or patterns that declare the current postType in its post type array. + if ( ! blockPatternsWithPostContentBlockType?.length ) { + return []; + } + + /* + * Filter patterns without postTypes declared if the current postType is page + * or patterns that declare the current postType in its post type array. + */ return blockPatternsWithPostContentBlockType.filter( ( pattern ) => { return ( ( postType === 'page' && ! pattern.postTypes ) || @@ -110,30 +118,24 @@ function StartPageOptionsModal( { onClose } ) { export default function StartPageOptions() { const [ isClosed, setIsClosed ] = useState( false ); - const { shouldEnableModal, postType, postId } = useSelect( ( select ) => { - const { - isEditedPostDirty, - isEditedPostEmpty, - getCurrentPostType, - getCurrentPostId, - } = select( editorStore ); - const _postType = getCurrentPostType(); - - return { - shouldEnableModal: - ! isEditedPostDirty() && - isEditedPostEmpty() && - TEMPLATE_POST_TYPE !== _postType, - postType: _postType, - postId: getCurrentPostId(), - }; + const shouldEnableModal = useSelect( ( select ) => { + const { isEditedPostDirty, isEditedPostEmpty, getCurrentPostType } = + select( editorStore ); + const preferencesModalActive = + select( interfaceStore ).isModalActive( 'editor/preferences' ); + const choosePatternModalEnabled = select( preferencesStore ).get( + 'core', + 'enableChoosePatternModal' + ); + return ( + choosePatternModalEnabled && + ! preferencesModalActive && + ! isEditedPostDirty() && + isEditedPostEmpty() && + TEMPLATE_POST_TYPE !== getCurrentPostType() + ); }, [] ); - useEffect( () => { - // Should reset the modal state when navigating to a new page/post. - setIsClosed( false ); - }, [ postType, postId ] ); - if ( ! shouldEnableModal || isClosed ) { return null; } From 82bc72dedd2815fbc0d407782fde2a12c4139a7e Mon Sep 17 00:00:00 2001 From: Andrew Serong <14988353+andrewserong@users.noreply.github.com> Date: Mon, 9 Sep 2024 11:57:21 +1000 Subject: [PATCH 2/9] Preferences: Fix back button on mobile (#65141) Co-authored-by: andrewserong Co-authored-by: ramonjd Co-authored-by: t-hamano --- .../src/components/preferences-modal-tabs/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/preferences/src/components/preferences-modal-tabs/index.js b/packages/preferences/src/components/preferences-modal-tabs/index.js index f70430367cc617..d87e565f5e3364 100644 --- a/packages/preferences/src/components/preferences-modal-tabs/index.js +++ b/packages/preferences/src/components/preferences-modal-tabs/index.js @@ -110,7 +110,7 @@ export default function PreferencesModalTabs( { sections } ) { return ( @@ -142,7 +142,7 @@ export default function PreferencesModalTabs( { sections } ) { return ( Date: Mon, 9 Sep 2024 13:47:19 +0530 Subject: [PATCH 3/9] Fix: Button: Replace remaining 40px default size violation [Block library 3] (#65110) * Fix the modal button for page list to use default 40px button size * Fix convert page list to navigation links edit button to use 40px default size * Fix enable comments form to use 40px default button size * Fix featured image block open media library button to use 40px default sizee * Fix site-logo block to use 40px default button size * Fix social link apply link button to use 40px default size * Revert social link apply button size to todo state --- .../block-library/src/page-list/convert-to-links-modal.js | 6 ++---- packages/block-library/src/page-list/edit.js | 3 +-- packages/block-library/src/post-comments-form/form.js | 3 +-- packages/block-library/src/post-featured-image/edit.js | 3 +-- packages/block-library/src/site-logo/edit.js | 6 ++---- packages/block-library/src/social-link/edit.js | 2 +- 6 files changed, 8 insertions(+), 15 deletions(-) diff --git a/packages/block-library/src/page-list/convert-to-links-modal.js b/packages/block-library/src/page-list/convert-to-links-modal.js index b56b3bf7c6b4f1..f2ab425a1ef10a 100644 --- a/packages/block-library/src/page-list/convert-to-links-modal.js +++ b/packages/block-library/src/page-list/convert-to-links-modal.js @@ -32,16 +32,14 @@ export function ConvertToLinksModal( { onClick, onClose, disabled } ) {