diff --git a/packages/e2e-test-utils/src/click-menu-item.js b/packages/e2e-test-utils/src/click-menu-item.js
index b43629217c1c5..f0a5f0d325867 100644
--- a/packages/e2e-test-utils/src/click-menu-item.js
+++ b/packages/e2e-test-utils/src/click-menu-item.js
@@ -4,8 +4,8 @@
* @param {string} label The label to search the menu item for.
*/
export async function clickMenuItem( label ) {
- const menuItems = await page.$x(
+ const menuItem = await page.waitForXPath(
`//*[@role="menu"]//*[text()="${ label }"]`
);
- await menuItems[ 0 ].click();
+ await menuItem.click();
}
diff --git a/packages/patterns/src/components/index.js b/packages/patterns/src/components/index.js
index 35639602978c3..755b5f3556ee5 100644
--- a/packages/patterns/src/components/index.js
+++ b/packages/patterns/src/components/index.js
@@ -1,8 +1,7 @@
/**
* WordPress dependencies
*/
-import { useSelect } from '@wordpress/data';
-import { store as blockEditorStore } from '@wordpress/block-editor';
+import { BlockSettingsMenuControls } from '@wordpress/block-editor';
/**
* Internal dependencies
@@ -11,20 +10,22 @@ import PatternConvertButton from './pattern-convert-button';
import PatternsManageButton from './patterns-manage-button';
export default function PatternsMenuItems( { rootClientId } ) {
- const clientIds = useSelect(
- ( select ) => select( blockEditorStore ).getSelectedBlockClientIds(),
- []
- );
-
return (
- <>
-
- { clientIds.length === 1 && (
-
+
+ { ( { onClose, selectedClientIds } ) => (
+ <>
+
+ { selectedClientIds.length === 1 && (
+
+ ) }
+ >
) }
- >
+
);
}
diff --git a/packages/patterns/src/components/pattern-convert-button.js b/packages/patterns/src/components/pattern-convert-button.js
index 65bd5131deeef..6c29e81203b5e 100644
--- a/packages/patterns/src/components/pattern-convert-button.js
+++ b/packages/patterns/src/components/pattern-convert-button.js
@@ -2,10 +2,7 @@
* WordPress dependencies
*/
import { hasBlockSupport, isReusableBlock } from '@wordpress/blocks';
-import {
- BlockSettingsMenuControls,
- store as blockEditorStore,
-} from '@wordpress/block-editor';
+import { store as blockEditorStore } from '@wordpress/block-editor';
import { useState } from '@wordpress/element';
import { MenuItem } from '@wordpress/components';
import { symbol } from '@wordpress/icons';
@@ -24,9 +21,14 @@ import CreatePatternModal from './create-pattern-modal';
* @param {Object} props Component props.
* @param {string[]} props.clientIds Client ids of selected blocks.
* @param {string} props.rootClientId ID of the currently selected top-level block.
+ * @param {()=>void} props.onClose Callback to close the menu.
* @return {import('@wordpress/element').WPComponent} The menu control or null.
*/
-export default function PatternConvertButton( { clientIds, rootClientId } ) {
+export default function PatternConvertButton( {
+ clientIds,
+ rootClientId,
+ onClose,
+} ) {
const { createSuccessNotice } = useDispatch( noticesStore );
const [ isModalOpen, setIsModalOpen ] = useState( false );
const canConvert = useSelect(
@@ -103,34 +105,27 @@ export default function PatternConvertButton( { clientIds, rootClientId } ) {
setIsModalOpen( false );
};
return (
-
- { ( { onClose } ) => (
- <>
-
- { isModalOpen && (
- {
- handleSuccess( pattern );
- onClose();
- } }
- onError={ () => {
- setIsModalOpen( false );
- onClose();
- } }
- onClose={ () => {
- setIsModalOpen( false );
- onClose();
- } }
- />
- ) }
- >
+ <>
+
+ { isModalOpen && (
+ {
+ handleSuccess( pattern );
+ onClose();
+ } }
+ onError={ () => {
+ setIsModalOpen( false );
+ onClose();
+ } }
+ onClose={ () => {
+ setIsModalOpen( false );
+ onClose();
+ } }
+ />
) }
-
+ >
);
}
diff --git a/packages/patterns/src/components/patterns-manage-button.js b/packages/patterns/src/components/patterns-manage-button.js
index ab3107a215180..bfa36521a28c1 100644
--- a/packages/patterns/src/components/patterns-manage-button.js
+++ b/packages/patterns/src/components/patterns-manage-button.js
@@ -5,10 +5,7 @@ import { MenuItem } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { isReusableBlock } from '@wordpress/blocks';
import { useSelect, useDispatch } from '@wordpress/data';
-import {
- BlockSettingsMenuControls,
- store as blockEditorStore,
-} from '@wordpress/block-editor';
+import { store as blockEditorStore } from '@wordpress/block-editor';
import { addQueryArgs } from '@wordpress/url';
import { store as coreStore } from '@wordpress/core-data';
@@ -62,7 +59,7 @@ function PatternsManageButton( { clientId } ) {
}
return (
-
+ <>
@@ -73,7 +70,7 @@ function PatternsManageButton( { clientId } ) {
: __( 'Detach pattern' ) }
) }
-
+ >
);
}
diff --git a/packages/patterns/src/index.native.js b/packages/patterns/src/index.native.js
new file mode 100644
index 0000000000000..2a9451884c69f
--- /dev/null
+++ b/packages/patterns/src/index.native.js
@@ -0,0 +1,11 @@
+/**
+ * Internal dependencies
+ */
+import './store';
+import { lock } from './lock-unlock';
+
+export const privateApis = {};
+lock( privateApis, {
+ CreatePatternModal: () => null,
+ PatternsMenuItems: () => null,
+} );
diff --git a/packages/reusable-blocks/src/components/reusable-blocks-menu-items/index.js b/packages/reusable-blocks/src/components/reusable-blocks-menu-items/index.js
index 6affb00479b30..e0a7c5df4782c 100644
--- a/packages/reusable-blocks/src/components/reusable-blocks-menu-items/index.js
+++ b/packages/reusable-blocks/src/components/reusable-blocks-menu-items/index.js
@@ -1,8 +1,7 @@
/**
* WordPress dependencies
*/
-import { useSelect } from '@wordpress/data';
-import { store as blockEditorStore } from '@wordpress/block-editor';
+import { BlockSettingsMenuControls } from '@wordpress/block-editor';
/**
* Internal dependencies
@@ -11,20 +10,22 @@ import ReusableBlockConvertButton from './reusable-block-convert-button';
import ReusableBlocksManageButton from './reusable-blocks-manage-button';
export default function ReusableBlocksMenuItems( { rootClientId } ) {
- const clientIds = useSelect(
- ( select ) => select( blockEditorStore ).getSelectedBlockClientIds(),
- []
- );
-
return (
- <>
-
- { clientIds.length === 1 && (
-
+
+ { ( { onClose, selectedClientIds } ) => (
+ <>
+
+ { selectedClientIds.length === 1 && (
+
+ ) }
+ >
) }
- >
+
);
}
diff --git a/packages/reusable-blocks/src/components/reusable-blocks-menu-items/reusable-block-convert-button.js b/packages/reusable-blocks/src/components/reusable-blocks-menu-items/reusable-block-convert-button.js
index 7f7ab7e50e66e..de29a930e89f1 100644
--- a/packages/reusable-blocks/src/components/reusable-blocks-menu-items/reusable-block-convert-button.js
+++ b/packages/reusable-blocks/src/components/reusable-blocks-menu-items/reusable-block-convert-button.js
@@ -3,7 +3,6 @@
*/
import { hasBlockSupport, isReusableBlock } from '@wordpress/blocks';
import {
- BlockSettingsMenuControls,
store as blockEditorStore,
privateApis as blockEditorPrivateApis,
} from '@wordpress/block-editor';
@@ -35,11 +34,13 @@ import { unlock } from '../../lock-unlock';
* @param {Object} props Component props.
* @param {string[]} props.clientIds Client ids of selected blocks.
* @param {string} props.rootClientId ID of the currently selected top-level block.
+ * @param {()=>void} props.onClose Callback to close the menu.
* @return {import('@wordpress/element').WPComponent} The menu control or null.
*/
export default function ReusableBlockConvertButton( {
clientIds,
rootClientId,
+ onClose,
} ) {
const { useReusableBlocksRenameHint, ReusableBlocksRenameHint } = unlock(
blockEditorPrivateApis
@@ -148,80 +149,71 @@ export default function ReusableBlockConvertButton( {
}
return (
-
- { ( { onClose } ) => (
- <>
-
- { isModalOpen && (
- {
- setIsModalOpen( false );
- setTitle( '' );
- } }
- overlayClassName="reusable-blocks-menu-items__convert-modal"
- >
-
-
- ) }
- >
+
+
+
+
+
) }
-
+ >
);
}
diff --git a/packages/reusable-blocks/src/components/reusable-blocks-menu-items/reusable-blocks-manage-button.js b/packages/reusable-blocks/src/components/reusable-blocks-menu-items/reusable-blocks-manage-button.js
index b69dbc5e97719..6ca19269d40f6 100644
--- a/packages/reusable-blocks/src/components/reusable-blocks-menu-items/reusable-blocks-manage-button.js
+++ b/packages/reusable-blocks/src/components/reusable-blocks-menu-items/reusable-blocks-manage-button.js
@@ -5,10 +5,7 @@ import { MenuItem } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { isReusableBlock } from '@wordpress/blocks';
import { useSelect, useDispatch } from '@wordpress/data';
-import {
- BlockSettingsMenuControls,
- store as blockEditorStore,
-} from '@wordpress/block-editor';
+import { store as blockEditorStore } from '@wordpress/block-editor';
import { addQueryArgs } from '@wordpress/url';
import { store as coreStore } from '@wordpress/core-data';
@@ -62,7 +59,7 @@ function ReusableBlocksManageButton( { clientId } ) {
}
return (
-
+ <>
{ __( 'Manage patterns' ) }
@@ -73,7 +70,7 @@ function ReusableBlocksManageButton( { clientId } ) {
: __( 'Detach pattern' ) }
) }
-
+ >
);
}