Skip to content

Commit

Permalink
Make getLastInsertedBlocksClientIds selector private (#47638)
Browse files Browse the repository at this point in the history
* Make selector private and update docs

* Unlock selector at point of usage
  • Loading branch information
getdave authored Feb 1, 2023
1 parent 473bb9f commit 6675463
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 48 deletions.
12 changes: 0 additions & 12 deletions docs/reference-guides/data/data-core-block-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -52,7 +53,7 @@ const ListViewBlockContents = forwardRef(
hasBlockMovingClientId,
getSelectedBlockClientId,
getLastInsertedBlocksClientIds,
} = select( blockEditorStore );
} = unlock( select( blockEditorStore ) );
const lastInsertedBlocksClientIds =
getLastInsertedBlocksClientIds();
return {
Expand Down
10 changes: 10 additions & 0 deletions packages/block-editor/src/store/private-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
10 changes: 0 additions & 10 deletions packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
30 changes: 29 additions & 1 deletion packages/block-editor/src/store/test/private-selectors.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/**
* Internal dependencies
*/
import { isBlockInterfaceHidden } from '../private-selectors';
import {
isBlockInterfaceHidden,
getLastInsertedBlocksClientIds,
} from '../private-selectors';

describe( 'private selectors', () => {
describe( 'isBlockInterfaceHidden', () => {
Expand All @@ -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',
] );
} );
} );
} );
24 changes: 0 additions & 24 deletions packages/block-editor/src/store/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ const {
__experimentalGetPatternTransformItems,
wasBlockJustInserted,
__experimentalGetGlobalBlocksByName,
getLastInsertedBlocksClientIds,
} = selectors;

describe( 'selectors', () => {
Expand Down Expand Up @@ -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',
] );
} );
} );

1 comment on commit 6675463

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 6675463.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4063339003
📝 Reported issues:

Please sign in to comment.