Skip to content

Commit

Permalink
Remove unused parameters from useOnBlockDrop (#57527)
Browse files Browse the repository at this point in the history
* Remove unused parameters from useOnBlockDrop

* Fix unit test
  • Loading branch information
t-hamano committed Jan 4, 2024
1 parent 81b8e05 commit 228344b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 35 deletions.
17 changes: 2 additions & 15 deletions packages/block-editor/src/components/use-on-block-drop/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ export function onBlockDrop(
* A function that returns an event handler function for block-related file drop events.
*
* @param {string} targetRootClientId The root client id where the block(s) will be inserted.
* @param {number} targetBlockIndex The index where the block(s) will be inserted.
* @param {Function} getSettings A function that gets the block editor settings.
* @param {Function} updateBlockAttributes A function that updates a block's attributes.
* @param {Function} canInsertBlockType A function that returns checks whether a block type can be inserted.
Expand All @@ -143,7 +142,6 @@ export function onBlockDrop(
*/
export function onFilesDrop(
targetRootClientId,
targetBlockIndex,
getSettings,
updateBlockAttributes,
canInsertBlockType,
Expand Down Expand Up @@ -175,17 +173,11 @@ export function onFilesDrop(
/**
* A function that returns an event handler function for block-related HTML drop events.
*
* @param {string} targetRootClientId The root client id where the block(s) will be inserted.
* @param {number} targetBlockIndex The index where the block(s) will be inserted.
* @param {Function} insertOrReplaceBlocks A function that inserts or replaces blocks.
*
* @return {Function} The event handler for a block-related HTML drop event.
*/
export function onHTMLDrop(
targetRootClientId,
targetBlockIndex,
insertOrReplaceBlocks
) {
export function onHTMLDrop( insertOrReplaceBlocks ) {
return ( HTML ) => {
const blocks = pasteHandler( { HTML, mode: 'BLOCKS' } );

Expand Down Expand Up @@ -309,17 +301,12 @@ export default function useOnBlockDrop(
);
const _onFilesDrop = onFilesDrop(
targetRootClientId,
targetBlockIndex,
getSettings,
updateBlockAttributes,
canInsertBlockType,
insertOrReplaceBlocks
);
const _onHTMLDrop = onHTMLDrop(
targetRootClientId,
targetBlockIndex,
insertOrReplaceBlocks
);
const _onHTMLDrop = onHTMLDrop( insertOrReplaceBlocks );

return ( event ) => {
const files = getFilesFromDataTransfer( event.dataTransfer );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,12 +306,10 @@ describe( 'onFilesDrop', () => {
const canInsertBlockType = noop;
const insertOrReplaceBlocks = jest.fn();
const targetRootClientId = '1';
const targetBlockIndex = 0;
const getSettings = jest.fn( () => ( {} ) );

const onFileDropHandler = onFilesDrop(
targetRootClientId,
targetBlockIndex,
getSettings,
updateBlockAttributes,
canInsertBlockType,
Expand All @@ -331,14 +329,12 @@ describe( 'onFilesDrop', () => {
const insertOrReplaceBlocks = jest.fn();
const canInsertBlockType = noop;
const targetRootClientId = '1';
const targetBlockIndex = 0;
const getSettings = jest.fn( () => ( {
mediaUpload: true,
} ) );

const onFileDropHandler = onFilesDrop(
targetRootClientId,
targetBlockIndex,
getSettings,
updateBlockAttributes,
canInsertBlockType,
Expand All @@ -361,14 +357,12 @@ describe( 'onFilesDrop', () => {
const canInsertBlockType = noop;
const insertOrReplaceBlocks = jest.fn();
const targetRootClientId = '1';
const targetBlockIndex = 0;
const getSettings = jest.fn( () => ( {
mediaUpload: true,
} ) );

const onFileDropHandler = onFilesDrop(
targetRootClientId,
targetBlockIndex,
getSettings,
updateBlockAttributes,
canInsertBlockType,
Expand All @@ -389,15 +383,9 @@ describe( 'onFilesDrop', () => {
describe( 'onHTMLDrop', () => {
it( 'does nothing if the HTML cannot be converted into blocks', () => {
pasteHandler.mockImplementation( () => [] );
const targetRootClientId = '1';
const targetBlockIndex = 0;
const insertOrReplaceBlocks = jest.fn();

const eventHandler = onHTMLDrop(
targetRootClientId,
targetBlockIndex,
insertOrReplaceBlocks
);
const eventHandler = onHTMLDrop( insertOrReplaceBlocks );
eventHandler();

expect( insertOrReplaceBlocks ).not.toHaveBeenCalled();
Expand All @@ -406,15 +394,9 @@ describe( 'onHTMLDrop', () => {
it( 'inserts blocks if the HTML can be converted into blocks', () => {
const blocks = [ 'blocks' ];
pasteHandler.mockImplementation( () => blocks );
const targetRootClientId = '1';
const targetBlockIndex = 0;
const insertOrReplaceBlocks = jest.fn();

const eventHandler = onHTMLDrop(
targetRootClientId,
targetBlockIndex,
insertOrReplaceBlocks
);
const eventHandler = onHTMLDrop( insertOrReplaceBlocks );
eventHandler();

expect( insertOrReplaceBlocks ).toHaveBeenCalledWith( blocks );
Expand Down

0 comments on commit 228344b

Please sign in to comment.