Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promote fetchLinkSuggestions to non-experimental API #40052

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions packages/block-editor/src/components/link-control/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ When this suggestion is selected it will call the `createSuggestion` prop afford

### Data sources

By default `LinkControl` utilizes the `__experimentalFetchLinkSuggestions` API from `core/block-editor` in order to retrieve search suggestions for matching post-type entities.
By default `LinkControl` utilizes the `fetchLinkSuggestions` API from `core/block-editor` in order to retrieve search suggestions for matching post-type entities.

By default this provides no functionality and so you must implement and provide this in your own Editor instance ([example](https://github.com/WordPress/gutenberg/blob/65c752816f46a9334b84f4801d80dea00ed76fba/packages/editor/src/components/provider/use-block-editor-settings.js#L114-L115)).

Expand Down Expand Up @@ -69,9 +69,7 @@ An array of settings objects associated with a link (for example: a setting to d
To disable settings, pass in an empty array. for example:

```jsx
<LinkControl
settings={ [] }
/>
<LinkControl settings={ [] } />
```

### onChange
Expand Down Expand Up @@ -192,7 +190,8 @@ A `suggestion` should have the following shape:
)}
/>
```
### renderControlBottom

### renderControlBottom

- Type: `Function`
- Required: No
Expand Down Expand Up @@ -262,9 +261,9 @@ The same as `value` in LinkControl, refer to an earlier section of this README f
- Type: `Function`
- Required: No

Custom search handler for suggestions. If specified, it's passed to `URLInput` as `__experimentalFetchLinkSuggestions`, if not, the default handler is used.
Custom search handler for suggestions. If specified, it's passed to `URLInput` as `fetchLinkSuggestions`, if not, the default handler is used.

Refer to URLInput's README.md for more details about `__experimentalFetchLinkSuggestions` and see the [createSuggestion](#createSuggestion) section of this file to learn more about suggestions.
Refer to URLInput's README.md for more details about `fetchLinkSuggestions` and see the [createSuggestion](#createSuggestion) section of this file to learn more about suggestions.

### onChange

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ import { DEFAULT_LINK_SETTINGS } from './constants';
* @property {boolean=} showSuggestions Whether to present suggestions when typing the URL.
* @property {boolean=} showInitialSuggestions Whether to present initial suggestions immediately.
* @property {boolean=} withCreateSuggestion Whether to allow creation of link value from suggestion.
* @property {Object=} suggestionsQuery Query parameters to pass along to wp.blockEditor.__experimentalFetchLinkSuggestions.
* @property {Object=} suggestionsQuery Query parameters to pass along to wp.blockEditor.fetchLinkSuggestions.
* @property {boolean=} noURLSuggestion Whether to add a fallback suggestion which treats the search query as a URL.
* @property {string|Function|undefined} createSuggestionButtonText The text to use in the button that calls createSuggestion.
* @property {Function} renderControlBottom Optional controls to be rendered at the bottom of the component.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ const LinkControlSearchInput = forwardRef(
__experimentalRenderSuggestions={
showSuggestions ? handleRenderSuggestions : null
}
__experimentalFetchLinkSuggestions={ searchHandler }
fetchLinkSuggestions={ searchHandler }
__experimentalHandleURLSuggestions={ true }
__experimentalShowInitialSuggestions={
showInitialSuggestions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ export default function useSearchHandler(

return {
pageOnFront: getSettings().pageOnFront,
fetchSearchSuggestions: getSettings()
.__experimentalFetchLinkSuggestions,
fetchSearchSuggestions: getSettings().fetchLinkSuggestions,
};
}, [] );

Expand Down
7 changes: 3 additions & 4 deletions packages/block-editor/src/components/url-input/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class URLInput extends Component {

updateSuggestions( value = '' ) {
const {
__experimentalFetchLinkSuggestions: fetchLinkSuggestions,
fetchLinkSuggestions,
__experimentalHandleURLSuggestions: handleURLSuggestions,
} = this.props;

Expand Down Expand Up @@ -580,13 +580,12 @@ export default compose(
withSelect( ( select, props ) => {
// If a link suggestions handler is already provided then
// bail.
if ( isFunction( props.__experimentalFetchLinkSuggestions ) ) {
if ( isFunction( props.fetchLinkSuggestions ) ) {
return;
}
const { getSettings } = select( blockEditorStore );
return {
__experimentalFetchLinkSuggestions: getSettings()
.__experimentalFetchLinkSuggestions,
fetchLinkSuggestions: getSettings().fetchLinkSuggestions,
};
} )
)( URLInput );
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ export default function LinkPickerResults( {
const { getSettings } = select( 'core/block-editor' );
const fetchLinkSuggestions = async ( { search } ) => {
if ( meetsThreshold( search ) ) {
return await getSettings().__experimentalFetchLinkSuggestions(
search,
{ page: nextPage.current, type: 'post', perPage: PER_PAGE }
);
return await getSettings().fetchLinkSuggestions( search, {
page: nextPage.current,
type: 'post',
perPage: PER_PAGE,
} );
}
};
const fetchMore = async ( {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ import { __ } from '@wordpress/i18n';
*
* @example
* ```js
* import { __experimentalFetchLinkSuggestions as fetchLinkSuggestions } from '@wordpress/core-data';
* import { fetchLinkSuggestions } from '@wordpress/core-data';
*
* //...
*
* export function initialize( id, settings ) {
*
* settings.__experimentalFetchLinkSuggestions = (
* settings.fetchLinkSuggestions = (
* search,
* searchOptions
* ) => fetchLinkSuggestions( search, searchOptions, settings );
Expand Down
2 changes: 1 addition & 1 deletion packages/core-data/src/fetch/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { default as __experimentalFetchLinkSuggestions } from './__experimental-fetch-link-suggestions';
export { default as fetchLinkSuggestions } from './__experimental-fetch-link-suggestions';
Copy link
Member

Choose a reason for hiding this comment

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

Let's rename the file name to fetch-link-suggestions.js too :)

Copy link
Member

Choose a reason for hiding this comment

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

Along with the unit test file.

export { default as __experimentalFetchUrlData } from './__experimental-fetch-url-data';
12 changes: 4 additions & 8 deletions packages/edit-navigation/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { dispatch, useDispatch } from '@wordpress/data';
import { render, useMemo } from '@wordpress/element';
import {
__experimentalFetchUrlData,
__experimentalFetchLinkSuggestions as fetchLinkSuggestions,
fetchLinkSuggestions,
store as coreStore,
} from '@wordpress/core-data';
import { __ } from '@wordpress/i18n';
Expand All @@ -31,7 +31,7 @@ function NavEditor( { settings } ) {
const __experimentalSetIsInserterOpened = setIsInserterOpened;

// Provide link suggestions handler to fetch search results for Link UI.
const __experimentalFetchLinkSuggestions = ( search, searchOptions ) => {
const _fetchLinkSuggestions = ( search, searchOptions ) => {
// Bump the default number of suggestions.
// See https://github.com/WordPress/gutenberg/issues/34283.
searchOptions.perPage = 10;
Expand All @@ -41,15 +41,11 @@ function NavEditor( { settings } ) {
const editorSettings = useMemo( () => {
return {
...settings,
__experimentalFetchLinkSuggestions,
fetchLinkSuggestions: _fetchLinkSuggestions,
__experimentalSetIsInserterOpened,
__experimentalFetchRichUrlData: __experimentalFetchUrlData,
};
}, [
settings,
__experimentalFetchLinkSuggestions,
__experimentalSetIsInserterOpened,
] );
}, [ settings, _fetchLinkSuggestions, __experimentalSetIsInserterOpened ] );

return <Layout blockEditorSettings={ editorSettings } />;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/edit-site/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { dispatch, select } from '@wordpress/data';
import { render, unmountComponentAtNode } from '@wordpress/element';
import {
__experimentalFetchLinkSuggestions as fetchLinkSuggestions,
fetchLinkSuggestions,
__experimentalFetchUrlData as fetchUrlData,
} from '@wordpress/core-data';
import { store as editorStore } from '@wordpress/editor';
Expand Down Expand Up @@ -100,7 +100,7 @@ export function reinitializeEditor( target, settings ) {
* @param {Object} settings Editor settings.
*/
export function initializeEditor( id, settings ) {
settings.__experimentalFetchLinkSuggestions = ( search, searchOptions ) =>
settings.fetchLinkSuggestions = ( search, searchOptions ) =>
fetchLinkSuggestions( search, searchOptions, settings );
settings.__experimentalFetchRichUrlData = fetchUrlData;
settings.__experimentalSpotlightEntityBlocks = [ 'core/template-part' ];
Expand Down
4 changes: 2 additions & 2 deletions packages/edit-widgets/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
__experimentalGetCoreBlocks,
__experimentalRegisterExperimentalCoreBlocks,
} from '@wordpress/block-library';
import { __experimentalFetchLinkSuggestions as fetchLinkSuggestions } from '@wordpress/core-data';
import { fetchLinkSuggestions } from '@wordpress/core-data';
import {
registerLegacyWidgetBlock,
registerLegacyWidgetVariations,
Expand Down Expand Up @@ -97,7 +97,7 @@ export function initialize( id, settings ) {
registerBlock( widgetArea );
registerWidgetGroupBlock();

settings.__experimentalFetchLinkSuggestions = ( search, searchOptions ) =>
settings.fetchLinkSuggestions = ( search, searchOptions ) =>
fetchLinkSuggestions( search, searchOptions, settings );

// As we are unregistering `core/freeform` to avoid the Classic block, we must
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Platform, useMemo } from '@wordpress/element';
import { useDispatch, useSelect } from '@wordpress/data';
import {
store as coreStore,
__experimentalFetchLinkSuggestions as fetchLinkSuggestions,
fetchLinkSuggestions,
__experimentalFetchUrlData as fetchUrlData,
} from '@wordpress/core-data';
import { __ } from '@wordpress/i18n';
Expand Down Expand Up @@ -144,7 +144,7 @@ function useBlockEditorSettings( settings, hasTemplate ) {
__experimentalReusableBlocks: reusableBlocks,
__experimentalBlockPatterns: blockPatterns,
__experimentalBlockPatternCategories: blockPatternCategories,
__experimentalFetchLinkSuggestions: ( search, searchOptions ) =>
fetchLinkSuggestions: ( search, searchOptions ) =>
fetchLinkSuggestions( search, searchOptions, settings ),
__experimentalFetchRichUrlData: fetchUrlData,
__experimentalCanUserUseUnfilteredHTML: canUseUnfilteredHTML,
Expand Down