From dac258c409ffe535c682251d2244d133f99b2e71 Mon Sep 17 00:00:00 2001 From: Andrei Draganescu Date: Fri, 18 Feb 2022 12:44:28 +0000 Subject: [PATCH] adds icons and removes blank title items --- .../block-editor/src/autocompleters/link.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/block-editor/src/autocompleters/link.js b/packages/block-editor/src/autocompleters/link.js index d03eb49d23567c..8d26aa15941b84 100644 --- a/packages/block-editor/src/autocompleters/link.js +++ b/packages/block-editor/src/autocompleters/link.js @@ -3,6 +3,7 @@ */ import apiFetch from '@wordpress/api-fetch'; import { addQueryArgs } from '@wordpress/url'; +import { Icon, page, customPostType as post } from '@wordpress/icons'; const SHOWN_SUGGESTIONS = 10; @@ -18,8 +19,8 @@ function createLinkCompleter() { name: 'links', className: 'block-editor-autocompleters__link', triggerPrefix: '[[', - options( letters ) { - return apiFetch( { + options: async ( letters ) => { + let options = await apiFetch( { path: addQueryArgs( '/wp/v2/search', { per_page: SHOWN_SUGGESTIONS, search: letters, @@ -27,13 +28,25 @@ function createLinkCompleter() { order_by: 'menu_order', } ), } ); + + options = options.filter( ( option ) => option.title !== '' ); + + return options; }, getOptionKeywords( item ) { const expansionWords = item.title.split( /\s+/ ); return [ ...expansionWords ]; }, getOptionLabel( item ) { - return item.title; + return ( + <> + + { item.title } + + ); }, getOptionCompletion( item ) { return { item.title };