Skip to content

Commit 6675463

Browse files
authored
Make getLastInsertedBlocksClientIds selector private (#47638)
* Make selector private and update docs * Unlock selector at point of usage
1 parent 473bb9f commit 6675463

File tree

6 files changed

+41
-48
lines changed

6 files changed

+41
-48
lines changed

docs/reference-guides/data/data-core-block-editor.md

-12
Original file line numberDiff line numberDiff line change
@@ -583,18 +583,6 @@ _Properties_
583583
- _isDisabled_ `boolean`: Whether or not the user should be prevented from inserting this item.
584584
- _frecency_ `number`: Heuristic that combines frequency and recency.
585585

586-
### getLastInsertedBlocksClientIds
587-
588-
Gets the client ids of the last inserted blocks.
589-
590-
_Parameters_
591-
592-
- _state_ `Object`: Global application state.
593-
594-
_Returns_
595-
596-
- `Array|undefined`: Client Ids of the last inserted block(s).
597-
598586
### getLastMultiSelectedBlockClientId
599587

600588
Returns the client ID of the last block in the multi-selection set, or null

packages/block-editor/src/components/off-canvas-editor/block-contents.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { forwardRef, useEffect, useState } from '@wordpress/element';
1212
/**
1313
* Internal dependencies
1414
*/
15+
import { unlock } from '../../experiments';
1516
import ListViewBlockSelectButton from './block-select-button';
1617
import BlockDraggable from '../block-draggable';
1718
import { store as blockEditorStore } from '../../store';
@@ -52,7 +53,7 @@ const ListViewBlockContents = forwardRef(
5253
hasBlockMovingClientId,
5354
getSelectedBlockClientId,
5455
getLastInsertedBlocksClientIds,
55-
} = select( blockEditorStore );
56+
} = unlock( select( blockEditorStore ) );
5657
const lastInsertedBlocksClientIds =
5758
getLastInsertedBlocksClientIds();
5859
return {

packages/block-editor/src/store/private-selectors.js

+10
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,13 @@
88
export function isBlockInterfaceHidden( state ) {
99
return state.isBlockInterfaceHidden;
1010
}
11+
12+
/**
13+
* Gets the client ids of the last inserted blocks.
14+
*
15+
* @param {Object} state Global application state.
16+
* @return {Array|undefined} Client Ids of the last inserted block(s).
17+
*/
18+
export function getLastInsertedBlocksClientIds( state ) {
19+
return state?.lastBlockInserted?.clientIds;
20+
}

packages/block-editor/src/store/selectors.js

-10
Original file line numberDiff line numberDiff line change
@@ -2703,16 +2703,6 @@ export function wasBlockJustInserted( state, clientId, source ) {
27032703
);
27042704
}
27052705

2706-
/**
2707-
* Gets the client ids of the last inserted blocks.
2708-
*
2709-
* @param {Object} state Global application state.
2710-
* @return {Array|undefined} Client Ids of the last inserted block(s).
2711-
*/
2712-
export function getLastInsertedBlocksClientIds( state ) {
2713-
return state?.lastBlockInserted?.clientIds;
2714-
}
2715-
27162706
/**
27172707
* Tells if the block is visible on the canvas or not.
27182708
*

packages/block-editor/src/store/test/private-selectors.js

+29-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
/**
22
* Internal dependencies
33
*/
4-
import { isBlockInterfaceHidden } from '../private-selectors';
4+
import {
5+
isBlockInterfaceHidden,
6+
getLastInsertedBlocksClientIds,
7+
} from '../private-selectors';
58

69
describe( 'private selectors', () => {
710
describe( 'isBlockInterfaceHidden', () => {
@@ -21,4 +24,29 @@ describe( 'private selectors', () => {
2124
expect( isBlockInterfaceHidden( state ) ).toBe( false );
2225
} );
2326
} );
27+
28+
describe( 'getLastInsertedBlocksClientIds', () => {
29+
it( 'should return undefined if no blocks have been inserted', () => {
30+
const state = {
31+
lastBlockInserted: {},
32+
};
33+
34+
expect( getLastInsertedBlocksClientIds( state ) ).toEqual(
35+
undefined
36+
);
37+
} );
38+
39+
it( 'should return clientIds if blocks have been inserted', () => {
40+
const state = {
41+
lastBlockInserted: {
42+
clientIds: [ '123456', '78910' ],
43+
},
44+
};
45+
46+
expect( getLastInsertedBlocksClientIds( state ) ).toEqual( [
47+
'123456',
48+
'78910',
49+
] );
50+
} );
51+
} );
2452
} );

packages/block-editor/src/store/test/selectors.js

-24
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ const {
7272
__experimentalGetPatternTransformItems,
7373
wasBlockJustInserted,
7474
__experimentalGetGlobalBlocksByName,
75-
getLastInsertedBlocksClientIds,
7675
} = selectors;
7776

7877
describe( 'selectors', () => {
@@ -4688,26 +4687,3 @@ describe( '__unstableGetClientIdsTree', () => {
46884687
] );
46894688
} );
46904689
} );
4691-
4692-
describe( 'getLastInsertedBlocksClientIds', () => {
4693-
it( 'should return undefined if no blocks have been inserted', () => {
4694-
const state = {
4695-
lastBlockInserted: {},
4696-
};
4697-
4698-
expect( getLastInsertedBlocksClientIds( state ) ).toEqual( undefined );
4699-
} );
4700-
4701-
it( 'should return clientIds if blocks have been inserted', () => {
4702-
const state = {
4703-
lastBlockInserted: {
4704-
clientIds: [ '123456', '78910' ],
4705-
},
4706-
};
4707-
4708-
expect( getLastInsertedBlocksClientIds( state ) ).toEqual( [
4709-
'123456',
4710-
'78910',
4711-
] );
4712-
} );
4713-
} );

0 commit comments

Comments
 (0)