Skip to content

Commit

Permalink
Navigation: make sure __experimentalFetchLinkSuggestions is invoked i…
Browse files Browse the repository at this point in the history
…n the same way, remove usage of lodash partialRight
  • Loading branch information
gwwar committed Mar 18, 2021
1 parent 1f206f0 commit ea63c67
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,30 @@ import { __ } from '@wordpress/i18n';
/**
* Fetches link suggestions from the API.
*
* @callback ExperimentalFetchLinkSuggestions
* @param {string} search
* @param {Object} [searchArguments]
* @param {Object} [editorSettings]
* @param {number} [searchArguments.isInitialSuggestions]
* @param {number} [searchArguments.type]
* @param {number} [searchArguments.subtype]
* @param {number} [searchArguments.page]
* @param {Object} [editorSettings]
* @param {boolean} [editorSettings.disablePostFormats=false]
* @return {Promise<Object[]>} List of suggestions
*/

const fetchLinkSuggestions = async (
/**
* Returns a function that when invoked, fetches link suggestions from the API.
*
* @param {Object} [editorSettings]
* @param {boolean} [editorSettings.disablePostFormats=false]
*
* @return { ExperimentalFetchLinkSuggestions } Function that fetches link suggestions
*
*/
const createFetchLinkSuggestions = ( {
disablePostFormats = false,
} = {} ) => async (
search,
{ isInitialSuggestions, type, subtype, page, perPage: perPageArg } = {},
{ disablePostFormats = false } = {}
{ isInitialSuggestions, type, subtype, page, perPage: perPageArg } = {}
) => {
const perPage = perPageArg || isInitialSuggestions ? 3 : 20;

Expand Down Expand Up @@ -88,4 +97,4 @@ const fetchLinkSuggestions = async (
} );
};

export default fetchLinkSuggestions;
export default createFetchLinkSuggestions;
9 changes: 4 additions & 5 deletions packages/edit-navigation/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
__experimentalRegisterExperimentalCoreBlocks,
} from '@wordpress/block-library';
import { render } from '@wordpress/element';
import { __experimentalFetchLinkSuggestions as fetchLinkSuggestions } from '@wordpress/block-editor';
import { __experimentalFetchLinkSuggestions as createFetchLinkSuggestions } from '@wordpress/block-editor';

/**
* Internal dependencies
Expand All @@ -27,10 +27,9 @@ export function initialize( id, settings ) {
__experimentalRegisterExperimentalCoreBlocks();
}

settings.__experimentalFetchLinkSuggestions = (
searchText,
searchOptions
) => fetchLinkSuggestions( searchText, searchOptions, settings );
settings.__experimentalFetchLinkSuggestions = createFetchLinkSuggestions(
settings
);

render(
<Layout blockEditorSettings={ settings } />,
Expand Down
9 changes: 4 additions & 5 deletions packages/edit-site/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
__experimentalRegisterExperimentalCoreBlocks,
} from '@wordpress/block-library';
import { render } from '@wordpress/element';
import { __experimentalFetchLinkSuggestions as fetchLinkSuggestions } from '@wordpress/block-editor';
import { __experimentalFetchLinkSuggestions as createFetchLinkSuggestions } from '@wordpress/block-editor';

/**
* Internal dependencies
Expand All @@ -23,10 +23,9 @@ import Editor from './components/editor';
* @param {Object} settings Editor settings.
*/
export function initialize( id, settings ) {
settings.__experimentalFetchLinkSuggestions = (
searchText,
searchOptions
) => fetchLinkSuggestions( searchText, searchOptions, settings );
settings.__experimentalFetchLinkSuggestions = createFetchLinkSuggestions(
settings
);
settings.__experimentalSpotlightEntityBlocks = [ 'core/template-part' ];

registerCoreBlocks();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/**
* External dependencies
*/
import { pick, defaultTo, partialRight } from 'lodash';
import { pick, defaultTo } from 'lodash';

/**
* WordPress dependencies
*/
import { Platform, useMemo } from '@wordpress/element';
import { useDispatch, useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import { __experimentalFetchLinkSuggestions as fetchLinkSuggestions } from '@wordpress/block-editor';
import { __experimentalFetchLinkSuggestions as createFetchLinkSuggestions } from '@wordpress/block-editor';

/**
* Internal dependencies
Expand Down Expand Up @@ -102,8 +102,7 @@ function useBlockEditorSettings( settings, hasTemplate ) {
] ),
mediaUpload: hasUploadPermissions ? mediaUpload : undefined,
__experimentalReusableBlocks: reusableBlocks,
__experimentalFetchLinkSuggestions: partialRight(
fetchLinkSuggestions,
__experimentalFetchLinkSuggestions: createFetchLinkSuggestions(
settings
),
__experimentalCanUserUseUnfilteredHTML: canUseUnfilteredHTML,
Expand Down

0 comments on commit ea63c67

Please sign in to comment.