Skip to content

Commit

Permalink
adds icons and removes blank title items
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Draganescu committed Feb 18, 2022
1 parent 319c0bc commit dac258c
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions packages/block-editor/src/autocompleters/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -18,22 +19,34 @@ 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,
type: 'post',
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 (
<>
<Icon
key="icon"
icon={ item.subtype === 'page' ? page : post }
/>
{ item.title }
</>
);
},
getOptionCompletion( item ) {
return <a href={ item.url }>{ item.title }</a>;
Expand Down

0 comments on commit dac258c

Please sign in to comment.