From 42f6a2c99b10f67107ddeab03ee8392036e2cca2 Mon Sep 17 00:00:00 2001 From: George Hotelling Date: Wed, 9 Nov 2022 11:25:55 -0700 Subject: [PATCH 01/25] Rebased: Initial work on nav edit button It was easier to nuke the commit history than to manually sync a bunch of commits, so this is all the commits in the branch squashed --- packages/block-editor/package.json | 2 ++ .../navigation-item-editor/index.js | 36 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 packages/edit-site/src/components/sidebar-edit-mode/navigation-item-editor/index.js diff --git a/packages/block-editor/package.json b/packages/block-editor/package.json index e90f7aaf4619f..e029304922902 100644 --- a/packages/block-editor/package.json +++ b/packages/block-editor/package.json @@ -39,6 +39,7 @@ "@wordpress/blocks": "file:../blocks", "@wordpress/components": "file:../components", "@wordpress/compose": "file:../compose", + "@wordpress/core-data": "file:../core-data", "@wordpress/data": "file:../data", "@wordpress/date": "file:../date", "@wordpress/deprecated": "file:../deprecated", @@ -48,6 +49,7 @@ "@wordpress/html-entities": "file:../html-entities", "@wordpress/i18n": "file:../i18n", "@wordpress/icons": "file:../icons", + "@wordpress/interface": "file:../interface", "@wordpress/is-shallow-equal": "file:../is-shallow-equal", "@wordpress/keyboard-shortcuts": "file:../keyboard-shortcuts", "@wordpress/keycodes": "file:../keycodes", diff --git a/packages/edit-site/src/components/sidebar-edit-mode/navigation-item-editor/index.js b/packages/edit-site/src/components/sidebar-edit-mode/navigation-item-editor/index.js new file mode 100644 index 0000000000000..bb289e7b31983 --- /dev/null +++ b/packages/edit-site/src/components/sidebar-edit-mode/navigation-item-editor/index.js @@ -0,0 +1,36 @@ +/** + * WordPress dependencies + */ +import { FlexBlock, Flex } from '@wordpress/components'; +import { __ } from '@wordpress/i18n'; +import { navigation } from '@wordpress/icons'; + +/** + * Internal dependencies + */ +import DefaultSidebar from '../default-sidebar'; + +export default function NavigationItemSidebar() { + return ( + + + { __( 'Navigation Menus' ) } + + { __( 'Beta' ) } + + + + } + > +

Hello, world

+
+ ); +} From 0a29db5e1eba1c6b18910c2a52d3952adc7a1f9f Mon Sep 17 00:00:00 2001 From: George Hotelling Date: Wed, 9 Nov 2022 14:21:55 -0700 Subject: [PATCH 02/25] Lint --- package-lock.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/package-lock.json b/package-lock.json index adb96b28da921..0841e48e22103 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17493,6 +17493,7 @@ "@wordpress/blocks": "file:packages/blocks", "@wordpress/components": "file:packages/components", "@wordpress/compose": "file:packages/compose", + "@wordpress/core-data": "file:packages/core-data", "@wordpress/data": "file:packages/data", "@wordpress/date": "file:packages/date", "@wordpress/deprecated": "file:packages/deprecated", @@ -17502,6 +17503,7 @@ "@wordpress/html-entities": "file:packages/html-entities", "@wordpress/i18n": "file:packages/i18n", "@wordpress/icons": "file:packages/icons", + "@wordpress/interface": "file:packages/interface", "@wordpress/is-shallow-equal": "file:packages/is-shallow-equal", "@wordpress/keyboard-shortcuts": "file:packages/keyboard-shortcuts", "@wordpress/keycodes": "file:packages/keycodes", From 6f9434d823140899b74527de821d1116e9f7b840 Mon Sep 17 00:00:00 2001 From: George Hotelling Date: Thu, 10 Nov 2022 09:31:32 -0700 Subject: [PATCH 03/25] Remove extra dependency --- packages/block-editor/package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/block-editor/package.json b/packages/block-editor/package.json index e029304922902..b34862516cb9d 100644 --- a/packages/block-editor/package.json +++ b/packages/block-editor/package.json @@ -49,7 +49,6 @@ "@wordpress/html-entities": "file:../html-entities", "@wordpress/i18n": "file:../i18n", "@wordpress/icons": "file:../icons", - "@wordpress/interface": "file:../interface", "@wordpress/is-shallow-equal": "file:../is-shallow-equal", "@wordpress/keyboard-shortcuts": "file:../keyboard-shortcuts", "@wordpress/keycodes": "file:../keycodes", From 430fe3e265284838caea7df1a98a08c14f183289 Mon Sep 17 00:00:00 2001 From: George Hotelling Date: Thu, 10 Nov 2022 10:26:17 -0700 Subject: [PATCH 04/25] Hide edit button from non-automenus --- .../off-canvas-editor/block-edit-button.js | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/packages/block-editor/src/components/off-canvas-editor/block-edit-button.js b/packages/block-editor/src/components/off-canvas-editor/block-edit-button.js index 15ae423ad5ddb..4ed5bed44bbd5 100644 --- a/packages/block-editor/src/components/off-canvas-editor/block-edit-button.js +++ b/packages/block-editor/src/components/off-canvas-editor/block-edit-button.js @@ -11,13 +11,39 @@ import { useDispatch } from '@wordpress/data'; import { store as blockEditorStore } from '../../store'; const BlockEditButton = ( { label, clientId } ) => { - const { selectBlock } = useDispatch( blockEditorStore ); + const { toggleBlockHighlight } = useDispatch( blockEditorStore ); + const [ convertModalOpen, setConvertModalOpen ] = useState( false ); + const { totalPages } = usePageData(); + const MAX_PAGE_COUNT = 100; + + const block = useSelect( + ( select ) => { + return select( blockEditorStore ).getBlock( clientId ); + }, + [ clientId ] + ); const onClick = () => { - selectBlock( clientId ); + toggleBlockHighlight( clientId, true ); + setConvertModalOpen( ! convertModalOpen ); }; - return + + + + ); +}; const BlockEditButton = ( { label, clientId } ) => { const { toggleBlockHighlight } = useDispatch( blockEditorStore ); const [ convertModalOpen, setConvertModalOpen ] = useState( false ); - const { totalPages } = usePageData(); - const MAX_PAGE_COUNT = 100; + const { pages, totalPages } = usePageData(); const block = useSelect( ( select ) => { @@ -37,6 +222,7 @@ const BlockEditButton = ( { label, clientId } ) => { setConvertModalOpen( false ) } clientId={ clientId } + pages={ pages } /> ) } { allowConvertToLinks && ( diff --git a/packages/edit-site/src/components/block-editor/index.js b/packages/edit-site/src/components/block-editor/index.js index 0f42214b45442..4e5c9d094bd57 100644 --- a/packages/edit-site/src/components/block-editor/index.js +++ b/packages/edit-site/src/components/block-editor/index.js @@ -6,7 +6,7 @@ import classnames from 'classnames'; /** * WordPress dependencies */ -import { useSelect, useDispatch } from '@wordpress/data'; +import { useSelect, useDispatch, resolveSelect } from '@wordpress/data'; import { useCallback, useMemo, useRef, Fragment } from '@wordpress/element'; import { useEntityBlockEditor, store as coreStore } from '@wordpress/core-data'; import { @@ -122,6 +122,28 @@ export default function BlockEditor( { setIsInserterOpen } ) { [ settingsBlockPatternCategories, restBlockPatternCategories ] ); + const fetchPagesEntities = async ( options = {} ) => + resolveSelect( coreStore ).getEntityRecords( + 'postType', + 'page', + options + ); + // const { fetchPagesEntities } = useSelect( ( select ) => { + // const { getEntityRecords } = select( coreStore ); + + // return { + // fetchPagesEntities: ( options = {} ) => { + // return getEntityRecords( 'postType', 'page', { + // orderby: 'menu_order', + // order: 'asc', + // _fields: [ 'id', 'link', 'parent', 'title', 'menu_order' ], + // per_page: -1, + // context: 'view', + // } ); + // }, + // }; + // } ); + const settings = useMemo( () => { const { __experimentalAdditionalBlockPatterns, @@ -133,6 +155,7 @@ export default function BlockEditor( { setIsInserterOpen } ) { ...restStoredSettings, __experimentalBlockPatterns: blockPatterns, __experimentalBlockPatternCategories: blockPatternCategories, + __experimentalFetchPageEntities: fetchPagesEntities, }; }, [ storedSettings, blockPatterns, blockPatternCategories ] ); From 29331c449ff4cfc837760777c18be0ff92f2b255 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Wed, 16 Nov 2022 15:35:22 +0000 Subject: [PATCH 07/25] Fetch pages via block editor settings --- .../off-canvas-editor/block-edit-button.js | 42 +++++-------------- .../src/components/block-editor/index.js | 30 ++++--------- 2 files changed, 20 insertions(+), 52 deletions(-) diff --git a/packages/block-editor/src/components/off-canvas-editor/block-edit-button.js b/packages/block-editor/src/components/off-canvas-editor/block-edit-button.js index 5b3956c8d7ac6..4d44bc658c74d 100644 --- a/packages/block-editor/src/components/off-canvas-editor/block-edit-button.js +++ b/packages/block-editor/src/components/off-canvas-editor/block-edit-button.js @@ -3,7 +3,7 @@ */ import { edit } from '@wordpress/icons'; import { __ } from '@wordpress/i18n'; -import { useRef, useMemo, useState, useEffect } from '@wordpress/element'; +import { useMemo, useState } from '@wordpress/element'; import { Button, Modal } from '@wordpress/components'; import { useSelect, useDispatch } from '@wordpress/data'; import { createBlock as create } from '@wordpress/blocks'; @@ -24,40 +24,21 @@ import { store as blockEditorStore } from '../../store'; const MAX_PAGE_COUNT = 100; const usePageData = () => { - const isMounted = useRef(); - const [ pages, setPages ] = useState(); - - useEffect( () => { - isMounted.current = true; - - return () => ( isMounted.current = false ); - }, [] ); - // 1. Grab editor settings // 2. Call the selector when we need it - const { fetchPages } = useSelect( ( select ) => { + const { pages } = useSelect( ( select ) => { const { getSettings } = select( blockEditorStore ); return { - fetchPages: getSettings().__experimentalFetchPageEntities, + pages: getSettings().__experimentalFetchPageEntities( { + orderby: 'menu_order', + order: 'asc', + _fields: [ 'id', 'link', 'parent', 'title', 'menu_order' ], + per_page: -1, + context: 'view', + } ), }; - }, [] ); // empty array is required to avoid invalidating fetchPages - - useEffect( () => { - ( async () => { - // If `__experimentalFetchPageEntities` is not defined in block editor settings, - // do not attempt to fetch Pages. - if ( ! fetchPages || ! isMounted.current ) { - return; - } - - debugger; - - const pagesResult = await fetchPages(); - setPages( pagesResult ); - // Todo: handle errors with catch - } )(); - }, [ fetchPages ] ); + }, [] ); return useMemo( () => { // TODO: Once the REST API supports passing multiple values to @@ -91,12 +72,11 @@ const usePageData = () => { /** * WordPress dependencies */ -const PAGE_FIELDS = [ 'id', 'title', 'link', 'type', 'parent' ]; const convertSelectedBlockToNavigationLinks = ( { pages, clientId, replaceBlock, createBlock } ) => () => { - if ( ! pages ) { + if ( ! pages?.length ) { return; } diff --git a/packages/edit-site/src/components/block-editor/index.js b/packages/edit-site/src/components/block-editor/index.js index 4e5c9d094bd57..62e79ac14cefa 100644 --- a/packages/edit-site/src/components/block-editor/index.js +++ b/packages/edit-site/src/components/block-editor/index.js @@ -6,7 +6,7 @@ import classnames from 'classnames'; /** * WordPress dependencies */ -import { useSelect, useDispatch, resolveSelect } from '@wordpress/data'; +import { useSelect, useDispatch } from '@wordpress/data'; import { useCallback, useMemo, useRef, Fragment } from '@wordpress/element'; import { useEntityBlockEditor, store as coreStore } from '@wordpress/core-data'; import { @@ -122,27 +122,15 @@ export default function BlockEditor( { setIsInserterOpen } ) { [ settingsBlockPatternCategories, restBlockPatternCategories ] ); - const fetchPagesEntities = async ( options = {} ) => - resolveSelect( coreStore ).getEntityRecords( - 'postType', - 'page', - options - ); - // const { fetchPagesEntities } = useSelect( ( select ) => { - // const { getEntityRecords } = select( coreStore ); + const { fetchPagesEntities } = useSelect( ( select ) => { + const { getEntityRecords } = select( coreStore ); - // return { - // fetchPagesEntities: ( options = {} ) => { - // return getEntityRecords( 'postType', 'page', { - // orderby: 'menu_order', - // order: 'asc', - // _fields: [ 'id', 'link', 'parent', 'title', 'menu_order' ], - // per_page: -1, - // context: 'view', - // } ); - // }, - // }; - // } ); + return { + fetchPagesEntities: ( options = {} ) => { + return getEntityRecords( 'postType', 'page', options ); + }, + }; + }, [] ); const settings = useMemo( () => { const { From 865b4faf7c9fe562b90b6ae50ac4f28fdbb9d979 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Wed, 16 Nov 2022 15:40:41 +0000 Subject: [PATCH 08/25] Revert additional of core-data dependency --- package-lock.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 7b188da5250a6..adb96b28da921 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17493,7 +17493,6 @@ "@wordpress/blocks": "file:packages/blocks", "@wordpress/components": "file:packages/components", "@wordpress/compose": "file:packages/compose", - "@wordpress/core-data": "file:packages/core-data", "@wordpress/data": "file:packages/data", "@wordpress/date": "file:packages/date", "@wordpress/deprecated": "file:packages/deprecated", From 076e9e7976b90b310868a39cf2adfb98c1fd0cc2 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Wed, 16 Nov 2022 15:41:31 +0000 Subject: [PATCH 09/25] Revert core data dep in block editor package --- packages/block-editor/package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/block-editor/package.json b/packages/block-editor/package.json index b34862516cb9d..e90f7aaf4619f 100644 --- a/packages/block-editor/package.json +++ b/packages/block-editor/package.json @@ -39,7 +39,6 @@ "@wordpress/blocks": "file:../blocks", "@wordpress/components": "file:../components", "@wordpress/compose": "file:../compose", - "@wordpress/core-data": "file:../core-data", "@wordpress/data": "file:../data", "@wordpress/date": "file:../date", "@wordpress/deprecated": "file:../deprecated", From 47d738117c4cb26479f56d1cc88f9e2113ff7afe Mon Sep 17 00:00:00 2001 From: George Hotelling Date: Tue, 22 Nov 2022 11:21:11 -0500 Subject: [PATCH 10/25] Update Convert Modal --- .../off-canvas-editor/block-edit-button.js | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/packages/block-editor/src/components/off-canvas-editor/block-edit-button.js b/packages/block-editor/src/components/off-canvas-editor/block-edit-button.js index 4d44bc658c74d..5e34c0a83c773 100644 --- a/packages/block-editor/src/components/off-canvas-editor/block-edit-button.js +++ b/packages/block-editor/src/components/off-canvas-editor/block-edit-button.js @@ -15,8 +15,6 @@ import { store as blockEditorStore } from '../../store'; /** * External dependencies */ -// import InspectorControls from '../../components/inspector-controls'; - // copied from packages/block-library/src/page-list/edit.js // We only show the edit option when page count is <= MAX_PAGE_COUNT @@ -69,10 +67,6 @@ const usePageData = () => { }; // copied from convert-to-links-modal.js -/** - * WordPress dependencies - */ - const convertSelectedBlockToNavigationLinks = ( { pages, clientId, replaceBlock, createBlock } ) => () => { @@ -141,18 +135,13 @@ const ConvertToLinksModal = ( { onClose, clientId, pages } ) => {

{ __( - 'To edit this navigation menu, convert it to single page links. This allows you to add, re-order, remove items, or edit their labels.' - ) } -

-

- { __( - "Note: if you add new pages to your site, you'll need to add them to your navigation menu." + 'This menu is automatically kept in sync with pages on your site. You can manage the menu yourself by clicking customize below.' ) }

@@ -169,7 +158,7 @@ const ConvertToLinksModal = ( { onClose, clientId, pages } ) => { createBlock: create, } ) } > - { __( 'Convert' ) } + { __( 'Customize' ) }
From 23f61bed2039043396752f61839d19750357237f Mon Sep 17 00:00:00 2001 From: George Hotelling Date: Wed, 9 Nov 2022 11:25:55 -0700 Subject: [PATCH 11/25] Rebased: Initial work on nav edit button It was easier to nuke the commit history than to manually sync a bunch of commits, so this is all the commits in the branch squashed --- packages/block-editor/package.json | 2 ++ .../navigation-item-editor/index.js | 36 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 packages/edit-site/src/components/sidebar-edit-mode/navigation-item-editor/index.js diff --git a/packages/block-editor/package.json b/packages/block-editor/package.json index e90f7aaf4619f..e029304922902 100644 --- a/packages/block-editor/package.json +++ b/packages/block-editor/package.json @@ -39,6 +39,7 @@ "@wordpress/blocks": "file:../blocks", "@wordpress/components": "file:../components", "@wordpress/compose": "file:../compose", + "@wordpress/core-data": "file:../core-data", "@wordpress/data": "file:../data", "@wordpress/date": "file:../date", "@wordpress/deprecated": "file:../deprecated", @@ -48,6 +49,7 @@ "@wordpress/html-entities": "file:../html-entities", "@wordpress/i18n": "file:../i18n", "@wordpress/icons": "file:../icons", + "@wordpress/interface": "file:../interface", "@wordpress/is-shallow-equal": "file:../is-shallow-equal", "@wordpress/keyboard-shortcuts": "file:../keyboard-shortcuts", "@wordpress/keycodes": "file:../keycodes", diff --git a/packages/edit-site/src/components/sidebar-edit-mode/navigation-item-editor/index.js b/packages/edit-site/src/components/sidebar-edit-mode/navigation-item-editor/index.js new file mode 100644 index 0000000000000..bb289e7b31983 --- /dev/null +++ b/packages/edit-site/src/components/sidebar-edit-mode/navigation-item-editor/index.js @@ -0,0 +1,36 @@ +/** + * WordPress dependencies + */ +import { FlexBlock, Flex } from '@wordpress/components'; +import { __ } from '@wordpress/i18n'; +import { navigation } from '@wordpress/icons'; + +/** + * Internal dependencies + */ +import DefaultSidebar from '../default-sidebar'; + +export default function NavigationItemSidebar() { + return ( + + + { __( 'Navigation Menus' ) } + + { __( 'Beta' ) } + + + + } + > +

Hello, world

+
+ ); +} From 3061b4377c86cdd7e23907134428fb230dfe05d0 Mon Sep 17 00:00:00 2001 From: George Hotelling Date: Wed, 9 Nov 2022 14:21:55 -0700 Subject: [PATCH 12/25] Lint --- package-lock.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/package-lock.json b/package-lock.json index adb96b28da921..0841e48e22103 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17493,6 +17493,7 @@ "@wordpress/blocks": "file:packages/blocks", "@wordpress/components": "file:packages/components", "@wordpress/compose": "file:packages/compose", + "@wordpress/core-data": "file:packages/core-data", "@wordpress/data": "file:packages/data", "@wordpress/date": "file:packages/date", "@wordpress/deprecated": "file:packages/deprecated", @@ -17502,6 +17503,7 @@ "@wordpress/html-entities": "file:packages/html-entities", "@wordpress/i18n": "file:packages/i18n", "@wordpress/icons": "file:packages/icons", + "@wordpress/interface": "file:packages/interface", "@wordpress/is-shallow-equal": "file:packages/is-shallow-equal", "@wordpress/keyboard-shortcuts": "file:packages/keyboard-shortcuts", "@wordpress/keycodes": "file:packages/keycodes", From a8e93cc0b794c82fbabf784026f59ea720dd847a Mon Sep 17 00:00:00 2001 From: George Hotelling Date: Thu, 10 Nov 2022 09:31:32 -0700 Subject: [PATCH 13/25] Remove extra dependency --- packages/block-editor/package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/block-editor/package.json b/packages/block-editor/package.json index e029304922902..b34862516cb9d 100644 --- a/packages/block-editor/package.json +++ b/packages/block-editor/package.json @@ -49,7 +49,6 @@ "@wordpress/html-entities": "file:../html-entities", "@wordpress/i18n": "file:../i18n", "@wordpress/icons": "file:../icons", - "@wordpress/interface": "file:../interface", "@wordpress/is-shallow-equal": "file:../is-shallow-equal", "@wordpress/keyboard-shortcuts": "file:../keyboard-shortcuts", "@wordpress/keycodes": "file:../keycodes", From 6aebd4c13fcc7539e9023200230b463aac1ae3be Mon Sep 17 00:00:00 2001 From: George Hotelling Date: Thu, 10 Nov 2022 10:26:17 -0700 Subject: [PATCH 14/25] Hide edit button from non-automenus --- .../off-canvas-editor/block-edit-button.js | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/packages/block-editor/src/components/off-canvas-editor/block-edit-button.js b/packages/block-editor/src/components/off-canvas-editor/block-edit-button.js index 15ae423ad5ddb..4ed5bed44bbd5 100644 --- a/packages/block-editor/src/components/off-canvas-editor/block-edit-button.js +++ b/packages/block-editor/src/components/off-canvas-editor/block-edit-button.js @@ -11,13 +11,39 @@ import { useDispatch } from '@wordpress/data'; import { store as blockEditorStore } from '../../store'; const BlockEditButton = ( { label, clientId } ) => { - const { selectBlock } = useDispatch( blockEditorStore ); + const { toggleBlockHighlight } = useDispatch( blockEditorStore ); + const [ convertModalOpen, setConvertModalOpen ] = useState( false ); + const { totalPages } = usePageData(); + const MAX_PAGE_COUNT = 100; + + const block = useSelect( + ( select ) => { + return select( blockEditorStore ).getBlock( clientId ); + }, + [ clientId ] + ); const onClick = () => { - selectBlock( clientId ); + toggleBlockHighlight( clientId, true ); + setConvertModalOpen( ! convertModalOpen ); }; - return + + + + ); +}; const BlockEditButton = ( { label, clientId } ) => { const { toggleBlockHighlight } = useDispatch( blockEditorStore ); const [ convertModalOpen, setConvertModalOpen ] = useState( false ); - const { totalPages } = usePageData(); - const MAX_PAGE_COUNT = 100; + const { pages, totalPages } = usePageData(); const block = useSelect( ( select ) => { @@ -37,6 +222,7 @@ const BlockEditButton = ( { label, clientId } ) => { setConvertModalOpen( false ) } clientId={ clientId } + pages={ pages } /> ) } { allowConvertToLinks && ( diff --git a/packages/edit-site/src/components/block-editor/index.js b/packages/edit-site/src/components/block-editor/index.js index 0f42214b45442..4e5c9d094bd57 100644 --- a/packages/edit-site/src/components/block-editor/index.js +++ b/packages/edit-site/src/components/block-editor/index.js @@ -6,7 +6,7 @@ import classnames from 'classnames'; /** * WordPress dependencies */ -import { useSelect, useDispatch } from '@wordpress/data'; +import { useSelect, useDispatch, resolveSelect } from '@wordpress/data'; import { useCallback, useMemo, useRef, Fragment } from '@wordpress/element'; import { useEntityBlockEditor, store as coreStore } from '@wordpress/core-data'; import { @@ -122,6 +122,28 @@ export default function BlockEditor( { setIsInserterOpen } ) { [ settingsBlockPatternCategories, restBlockPatternCategories ] ); + const fetchPagesEntities = async ( options = {} ) => + resolveSelect( coreStore ).getEntityRecords( + 'postType', + 'page', + options + ); + // const { fetchPagesEntities } = useSelect( ( select ) => { + // const { getEntityRecords } = select( coreStore ); + + // return { + // fetchPagesEntities: ( options = {} ) => { + // return getEntityRecords( 'postType', 'page', { + // orderby: 'menu_order', + // order: 'asc', + // _fields: [ 'id', 'link', 'parent', 'title', 'menu_order' ], + // per_page: -1, + // context: 'view', + // } ); + // }, + // }; + // } ); + const settings = useMemo( () => { const { __experimentalAdditionalBlockPatterns, @@ -133,6 +155,7 @@ export default function BlockEditor( { setIsInserterOpen } ) { ...restStoredSettings, __experimentalBlockPatterns: blockPatterns, __experimentalBlockPatternCategories: blockPatternCategories, + __experimentalFetchPageEntities: fetchPagesEntities, }; }, [ storedSettings, blockPatterns, blockPatternCategories ] ); From 1c60ea0b81ae211ad173ed2659d134e32d0d58af Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Wed, 16 Nov 2022 15:35:22 +0000 Subject: [PATCH 17/25] Fetch pages via block editor settings --- .../off-canvas-editor/block-edit-button.js | 42 +++++-------------- .../src/components/block-editor/index.js | 30 ++++--------- 2 files changed, 20 insertions(+), 52 deletions(-) diff --git a/packages/block-editor/src/components/off-canvas-editor/block-edit-button.js b/packages/block-editor/src/components/off-canvas-editor/block-edit-button.js index 5b3956c8d7ac6..4d44bc658c74d 100644 --- a/packages/block-editor/src/components/off-canvas-editor/block-edit-button.js +++ b/packages/block-editor/src/components/off-canvas-editor/block-edit-button.js @@ -3,7 +3,7 @@ */ import { edit } from '@wordpress/icons'; import { __ } from '@wordpress/i18n'; -import { useRef, useMemo, useState, useEffect } from '@wordpress/element'; +import { useMemo, useState } from '@wordpress/element'; import { Button, Modal } from '@wordpress/components'; import { useSelect, useDispatch } from '@wordpress/data'; import { createBlock as create } from '@wordpress/blocks'; @@ -24,40 +24,21 @@ import { store as blockEditorStore } from '../../store'; const MAX_PAGE_COUNT = 100; const usePageData = () => { - const isMounted = useRef(); - const [ pages, setPages ] = useState(); - - useEffect( () => { - isMounted.current = true; - - return () => ( isMounted.current = false ); - }, [] ); - // 1. Grab editor settings // 2. Call the selector when we need it - const { fetchPages } = useSelect( ( select ) => { + const { pages } = useSelect( ( select ) => { const { getSettings } = select( blockEditorStore ); return { - fetchPages: getSettings().__experimentalFetchPageEntities, + pages: getSettings().__experimentalFetchPageEntities( { + orderby: 'menu_order', + order: 'asc', + _fields: [ 'id', 'link', 'parent', 'title', 'menu_order' ], + per_page: -1, + context: 'view', + } ), }; - }, [] ); // empty array is required to avoid invalidating fetchPages - - useEffect( () => { - ( async () => { - // If `__experimentalFetchPageEntities` is not defined in block editor settings, - // do not attempt to fetch Pages. - if ( ! fetchPages || ! isMounted.current ) { - return; - } - - debugger; - - const pagesResult = await fetchPages(); - setPages( pagesResult ); - // Todo: handle errors with catch - } )(); - }, [ fetchPages ] ); + }, [] ); return useMemo( () => { // TODO: Once the REST API supports passing multiple values to @@ -91,12 +72,11 @@ const usePageData = () => { /** * WordPress dependencies */ -const PAGE_FIELDS = [ 'id', 'title', 'link', 'type', 'parent' ]; const convertSelectedBlockToNavigationLinks = ( { pages, clientId, replaceBlock, createBlock } ) => () => { - if ( ! pages ) { + if ( ! pages?.length ) { return; } diff --git a/packages/edit-site/src/components/block-editor/index.js b/packages/edit-site/src/components/block-editor/index.js index 4e5c9d094bd57..62e79ac14cefa 100644 --- a/packages/edit-site/src/components/block-editor/index.js +++ b/packages/edit-site/src/components/block-editor/index.js @@ -6,7 +6,7 @@ import classnames from 'classnames'; /** * WordPress dependencies */ -import { useSelect, useDispatch, resolveSelect } from '@wordpress/data'; +import { useSelect, useDispatch } from '@wordpress/data'; import { useCallback, useMemo, useRef, Fragment } from '@wordpress/element'; import { useEntityBlockEditor, store as coreStore } from '@wordpress/core-data'; import { @@ -122,27 +122,15 @@ export default function BlockEditor( { setIsInserterOpen } ) { [ settingsBlockPatternCategories, restBlockPatternCategories ] ); - const fetchPagesEntities = async ( options = {} ) => - resolveSelect( coreStore ).getEntityRecords( - 'postType', - 'page', - options - ); - // const { fetchPagesEntities } = useSelect( ( select ) => { - // const { getEntityRecords } = select( coreStore ); + const { fetchPagesEntities } = useSelect( ( select ) => { + const { getEntityRecords } = select( coreStore ); - // return { - // fetchPagesEntities: ( options = {} ) => { - // return getEntityRecords( 'postType', 'page', { - // orderby: 'menu_order', - // order: 'asc', - // _fields: [ 'id', 'link', 'parent', 'title', 'menu_order' ], - // per_page: -1, - // context: 'view', - // } ); - // }, - // }; - // } ); + return { + fetchPagesEntities: ( options = {} ) => { + return getEntityRecords( 'postType', 'page', options ); + }, + }; + }, [] ); const settings = useMemo( () => { const { From 0136c51c6b89ddbb8d9a9f52551ad33901b7cccf Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Wed, 16 Nov 2022 15:40:41 +0000 Subject: [PATCH 18/25] Revert additional of core-data dependency --- package-lock.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 7b188da5250a6..adb96b28da921 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17493,7 +17493,6 @@ "@wordpress/blocks": "file:packages/blocks", "@wordpress/components": "file:packages/components", "@wordpress/compose": "file:packages/compose", - "@wordpress/core-data": "file:packages/core-data", "@wordpress/data": "file:packages/data", "@wordpress/date": "file:packages/date", "@wordpress/deprecated": "file:packages/deprecated", From c8efdb339a3a83977ff8872cc2cf84f031e3ed09 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Wed, 16 Nov 2022 15:41:31 +0000 Subject: [PATCH 19/25] Revert core data dep in block editor package --- packages/block-editor/package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/block-editor/package.json b/packages/block-editor/package.json index b34862516cb9d..e90f7aaf4619f 100644 --- a/packages/block-editor/package.json +++ b/packages/block-editor/package.json @@ -39,7 +39,6 @@ "@wordpress/blocks": "file:../blocks", "@wordpress/components": "file:../components", "@wordpress/compose": "file:../compose", - "@wordpress/core-data": "file:../core-data", "@wordpress/data": "file:../data", "@wordpress/date": "file:../date", "@wordpress/deprecated": "file:../deprecated", From 5bd0cfc45a7837d85712b43dfb82f3fe615fc7f9 Mon Sep 17 00:00:00 2001 From: George Hotelling Date: Tue, 22 Nov 2022 11:21:11 -0500 Subject: [PATCH 20/25] Update Convert Modal --- .../off-canvas-editor/block-edit-button.js | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/packages/block-editor/src/components/off-canvas-editor/block-edit-button.js b/packages/block-editor/src/components/off-canvas-editor/block-edit-button.js index 4d44bc658c74d..5e34c0a83c773 100644 --- a/packages/block-editor/src/components/off-canvas-editor/block-edit-button.js +++ b/packages/block-editor/src/components/off-canvas-editor/block-edit-button.js @@ -15,8 +15,6 @@ import { store as blockEditorStore } from '../../store'; /** * External dependencies */ -// import InspectorControls from '../../components/inspector-controls'; - // copied from packages/block-library/src/page-list/edit.js // We only show the edit option when page count is <= MAX_PAGE_COUNT @@ -69,10 +67,6 @@ const usePageData = () => { }; // copied from convert-to-links-modal.js -/** - * WordPress dependencies - */ - const convertSelectedBlockToNavigationLinks = ( { pages, clientId, replaceBlock, createBlock } ) => () => { @@ -141,18 +135,13 @@ const ConvertToLinksModal = ( { onClose, clientId, pages } ) => {

{ __( - 'To edit this navigation menu, convert it to single page links. This allows you to add, re-order, remove items, or edit their labels.' - ) } -

-

- { __( - "Note: if you add new pages to your site, you'll need to add them to your navigation menu." + 'This menu is automatically kept in sync with pages on your site. You can manage the menu yourself by clicking customize below.' ) }

@@ -169,7 +158,7 @@ const ConvertToLinksModal = ( { onClose, clientId, pages } ) => { createBlock: create, } ) } > - { __( 'Convert' ) } + { __( 'Customize' ) }
From 411a9619efa9759facd631ab86b8fd3a0c8d081b Mon Sep 17 00:00:00 2001 From: George Hotelling Date: Wed, 23 Nov 2022 14:01:46 -0500 Subject: [PATCH 21/25] Partial fix for post-convert edit button --- .../off-canvas-editor/block-edit-button.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/block-editor/src/components/off-canvas-editor/block-edit-button.js b/packages/block-editor/src/components/off-canvas-editor/block-edit-button.js index 5e34c0a83c773..d4d4e1dfbb5f0 100644 --- a/packages/block-editor/src/components/off-canvas-editor/block-edit-button.js +++ b/packages/block-editor/src/components/off-canvas-editor/block-edit-button.js @@ -177,14 +177,14 @@ const BlockEditButton = ( { label, clientId } ) => { [ clientId ] ); + const allowConvertToLinks = + 'core/page-list' === block.name && totalPages <= MAX_PAGE_COUNT; + const onClick = () => { toggleBlockHighlight( clientId, true ); - setConvertModalOpen( ! convertModalOpen ); + if ( allowConvertToLinks ) setConvertModalOpen( ! convertModalOpen ); }; - const allowConvertToLinks = - 'core/page-list' === block.name && totalPages <= MAX_PAGE_COUNT; - return ( <> { convertModalOpen && ( @@ -194,9 +194,7 @@ const BlockEditButton = ( { label, clientId } ) => { pages={ pages } /> ) } - { allowConvertToLinks && ( -