From 66754631459c59b950dacf887e213b9721a9d411 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Wed, 1 Feb 2023 10:24:36 +0000 Subject: [PATCH] Make getLastInsertedBlocksClientIds selector private (#47638) * Make selector private and update docs * Unlock selector at point of usage --- .../data/data-core-block-editor.md | 12 -------- .../off-canvas-editor/block-contents.js | 3 +- .../src/store/private-selectors.js | 10 +++++++ packages/block-editor/src/store/selectors.js | 10 ------- .../src/store/test/private-selectors.js | 30 ++++++++++++++++++- .../block-editor/src/store/test/selectors.js | 24 --------------- 6 files changed, 41 insertions(+), 48 deletions(-) diff --git a/docs/reference-guides/data/data-core-block-editor.md b/docs/reference-guides/data/data-core-block-editor.md index fdc91bb0cd354c..cfb95389ba0391 100644 --- a/docs/reference-guides/data/data-core-block-editor.md +++ b/docs/reference-guides/data/data-core-block-editor.md @@ -583,18 +583,6 @@ _Properties_ - _isDisabled_ `boolean`: Whether or not the user should be prevented from inserting this item. - _frecency_ `number`: Heuristic that combines frequency and recency. -### getLastInsertedBlocksClientIds - -Gets the client ids of the last inserted blocks. - -_Parameters_ - -- _state_ `Object`: Global application state. - -_Returns_ - -- `Array|undefined`: Client Ids of the last inserted block(s). - ### getLastMultiSelectedBlockClientId Returns the client ID of the last block in the multi-selection set, or null diff --git a/packages/block-editor/src/components/off-canvas-editor/block-contents.js b/packages/block-editor/src/components/off-canvas-editor/block-contents.js index 7dfa98fb60e261..4048f25b49c989 100644 --- a/packages/block-editor/src/components/off-canvas-editor/block-contents.js +++ b/packages/block-editor/src/components/off-canvas-editor/block-contents.js @@ -12,6 +12,7 @@ import { forwardRef, useEffect, useState } from '@wordpress/element'; /** * Internal dependencies */ +import { unlock } from '../../experiments'; import ListViewBlockSelectButton from './block-select-button'; import BlockDraggable from '../block-draggable'; import { store as blockEditorStore } from '../../store'; @@ -52,7 +53,7 @@ const ListViewBlockContents = forwardRef( hasBlockMovingClientId, getSelectedBlockClientId, getLastInsertedBlocksClientIds, - } = select( blockEditorStore ); + } = unlock( select( blockEditorStore ) ); const lastInsertedBlocksClientIds = getLastInsertedBlocksClientIds(); return { diff --git a/packages/block-editor/src/store/private-selectors.js b/packages/block-editor/src/store/private-selectors.js index dede6eccccbe50..60712e6b8eb6e0 100644 --- a/packages/block-editor/src/store/private-selectors.js +++ b/packages/block-editor/src/store/private-selectors.js @@ -8,3 +8,13 @@ export function isBlockInterfaceHidden( state ) { return state.isBlockInterfaceHidden; } + +/** + * Gets the client ids of the last inserted blocks. + * + * @param {Object} state Global application state. + * @return {Array|undefined} Client Ids of the last inserted block(s). + */ +export function getLastInsertedBlocksClientIds( state ) { + return state?.lastBlockInserted?.clientIds; +} diff --git a/packages/block-editor/src/store/selectors.js b/packages/block-editor/src/store/selectors.js index 9d4a053be7332a..5b70183acccf2a 100644 --- a/packages/block-editor/src/store/selectors.js +++ b/packages/block-editor/src/store/selectors.js @@ -2703,16 +2703,6 @@ export function wasBlockJustInserted( state, clientId, source ) { ); } -/** - * Gets the client ids of the last inserted blocks. - * - * @param {Object} state Global application state. - * @return {Array|undefined} Client Ids of the last inserted block(s). - */ -export function getLastInsertedBlocksClientIds( state ) { - return state?.lastBlockInserted?.clientIds; -} - /** * Tells if the block is visible on the canvas or not. * diff --git a/packages/block-editor/src/store/test/private-selectors.js b/packages/block-editor/src/store/test/private-selectors.js index 2c287ceda0f88f..c5df265f75db35 100644 --- a/packages/block-editor/src/store/test/private-selectors.js +++ b/packages/block-editor/src/store/test/private-selectors.js @@ -1,7 +1,10 @@ /** * Internal dependencies */ -import { isBlockInterfaceHidden } from '../private-selectors'; +import { + isBlockInterfaceHidden, + getLastInsertedBlocksClientIds, +} from '../private-selectors'; describe( 'private selectors', () => { describe( 'isBlockInterfaceHidden', () => { @@ -21,4 +24,29 @@ describe( 'private selectors', () => { expect( isBlockInterfaceHidden( state ) ).toBe( false ); } ); } ); + + describe( 'getLastInsertedBlocksClientIds', () => { + it( 'should return undefined if no blocks have been inserted', () => { + const state = { + lastBlockInserted: {}, + }; + + expect( getLastInsertedBlocksClientIds( state ) ).toEqual( + undefined + ); + } ); + + it( 'should return clientIds if blocks have been inserted', () => { + const state = { + lastBlockInserted: { + clientIds: [ '123456', '78910' ], + }, + }; + + expect( getLastInsertedBlocksClientIds( state ) ).toEqual( [ + '123456', + '78910', + ] ); + } ); + } ); } ); diff --git a/packages/block-editor/src/store/test/selectors.js b/packages/block-editor/src/store/test/selectors.js index 08763c74efcb64..60d90d80b9d41e 100644 --- a/packages/block-editor/src/store/test/selectors.js +++ b/packages/block-editor/src/store/test/selectors.js @@ -72,7 +72,6 @@ const { __experimentalGetPatternTransformItems, wasBlockJustInserted, __experimentalGetGlobalBlocksByName, - getLastInsertedBlocksClientIds, } = selectors; describe( 'selectors', () => { @@ -4688,26 +4687,3 @@ describe( '__unstableGetClientIdsTree', () => { ] ); } ); } ); - -describe( 'getLastInsertedBlocksClientIds', () => { - it( 'should return undefined if no blocks have been inserted', () => { - const state = { - lastBlockInserted: {}, - }; - - expect( getLastInsertedBlocksClientIds( state ) ).toEqual( undefined ); - } ); - - it( 'should return clientIds if blocks have been inserted', () => { - const state = { - lastBlockInserted: { - clientIds: [ '123456', '78910' ], - }, - }; - - expect( getLastInsertedBlocksClientIds( state ) ).toEqual( [ - '123456', - '78910', - ] ); - } ); -} );