From 33c5293516eaf82e7f5011811099f09407e238d5 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Mon, 15 Nov 2021 16:41:30 +0000 Subject: [PATCH 1/8] Expose page on front id in editor settings --- .../provider/use-block-editor-settings.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/editor/src/components/provider/use-block-editor-settings.js b/packages/editor/src/components/provider/use-block-editor-settings.js index 3432caccd72d3..f262e64e27145 100644 --- a/packages/editor/src/components/provider/use-block-editor-settings.js +++ b/packages/editor/src/components/provider/use-block-editor-settings.js @@ -35,12 +35,18 @@ function useBlockEditorSettings( settings, hasTemplate ) { hasUploadPermissions, canUseUnfilteredHTML, userCanCreatePages, + pageOnFront, } = useSelect( ( select ) => { const { canUserUseUnfilteredHTML } = select( editorStore ); const isWeb = Platform.OS === 'web'; - const { canUser, getUnstableBase, hasFinishedResolution } = select( - coreStore - ); + const { + canUser, + getUnstableBase, + hasFinishedResolution, + getEntityRecord, + } = select( coreStore ); + + const siteSettings = getEntityRecord( 'root', 'site' ); const siteData = getUnstableBase(); @@ -64,6 +70,7 @@ function useBlockEditorSettings( settings, hasTemplate ) { hasResolvedLocalSiteData: hasFinishedResolvingSiteData, baseUrl: siteData?.url || '', userCanCreatePages: canUser( 'create', 'pages' ), + pageOnFront: siteSettings?.page_on_front, }; }, [] ); @@ -139,6 +146,7 @@ function useBlockEditorSettings( settings, hasTemplate ) { outlineMode: hasTemplate, __experimentalCreatePageEntity: createPageEntity, __experimentalUserCanCreatePages: userCanCreatePages, + pageOnFront, } ), [ settings, @@ -148,6 +156,7 @@ function useBlockEditorSettings( settings, hasTemplate ) { undo, hasTemplate, userCanCreatePages, + pageOnFront, ] ); } From 537b8b3fb4a823ae288f8825511ea3bae8aec0cc Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Mon, 15 Nov 2021 16:41:55 +0000 Subject: [PATCH 2/8] Mark front page in results if found and omit URL suggestion --- .../link-control/use-search-handler.js | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/packages/block-editor/src/components/link-control/use-search-handler.js b/packages/block-editor/src/components/link-control/use-search-handler.js index 37fc89951b941..2ec8b36576d9f 100644 --- a/packages/block-editor/src/components/link-control/use-search-handler.js +++ b/packages/block-editor/src/components/link-control/use-search-handler.js @@ -52,21 +52,39 @@ const handleEntitySearch = async ( fetchSearchSuggestions, directEntryHandler, withCreateSuggestion, - withURLSuggestion + withURLSuggestion, + pageOnFront ) => { const { isInitialSuggestions } = suggestionsQuery; + let resultsIncludeFrontPage = false; let results = await Promise.all( [ fetchSearchSuggestions( val, suggestionsQuery ), directEntryHandler( val ), ] ); + // Identify front page and update type to match. + results[ 0 ] = results[ 0 ].map( ( result ) => { + if ( Number( result.id ) === pageOnFront ) { + resultsIncludeFrontPage = true; + result.isFrontPage = true; + return result; + } + + return result; + } ); + const couldBeURL = ! val.includes( ' ' ); // If it's potentially a URL search then concat on a URL search suggestion // just for good measure. That way once the actual results run out we always // have a URL option to fallback on. - if ( couldBeURL && withURLSuggestion && ! isInitialSuggestions ) { + if ( + ! resultsIncludeFrontPage && + couldBeURL && + withURLSuggestion && + ! isInitialSuggestions + ) { results = results[ 0 ].concat( results[ 1 ] ); } else { results = results[ 0 ]; @@ -109,9 +127,11 @@ export default function useSearchHandler( withCreateSuggestion, withURLSuggestion ) { - const { fetchSearchSuggestions } = useSelect( ( select ) => { + const { fetchSearchSuggestions, pageOnFront } = useSelect( ( select ) => { const { getSettings } = select( blockEditorStore ); + return { + pageOnFront: getSettings().pageOnFront, fetchSearchSuggestions: getSettings() .__experimentalFetchLinkSuggestions, }; @@ -131,7 +151,8 @@ export default function useSearchHandler( fetchSearchSuggestions, directEntryHandler, withCreateSuggestion, - withURLSuggestion + withURLSuggestion, + pageOnFront ); }, [ directEntryHandler, fetchSearchSuggestions, withCreateSuggestion ] From 4f7845a05f1635b23e1fc1e4048b2b42d501c250 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Mon, 15 Nov 2021 16:42:11 +0000 Subject: [PATCH 3/8] Visually mark front page in search results --- .../components/link-control/search-item.js | 22 ++++++++++++++++--- .../components/link-control/search-results.js | 1 + 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/packages/block-editor/src/components/link-control/search-item.js b/packages/block-editor/src/components/link-control/search-item.js index 804e5c95f05af..3d1c006d70f37 100644 --- a/packages/block-editor/src/components/link-control/search-item.js +++ b/packages/block-editor/src/components/link-control/search-item.js @@ -9,7 +9,7 @@ import classnames from 'classnames'; import { safeDecodeURI, filterURLForDisplay } from '@wordpress/url'; import { __ } from '@wordpress/i18n'; import { Button, TextHighlight } from '@wordpress/components'; -import { Icon, globe } from '@wordpress/icons'; +import { Icon, globe, home } from '@wordpress/icons'; export const LinkControlSearchItem = ( { itemProps, @@ -19,6 +19,7 @@ export const LinkControlSearchItem = ( { isURL = false, searchTerm = '', shouldShowType = false, + isFrontPage = false, } ) => { return ( ); }; +function getVisualTypeName( suggestion ) { + if ( suggestion.isFrontPage ) { + return 'Front Page'; + } + + // Rename 'post_tag' to 'tag'. Ideally, the API would return the localised CPT or taxonomy label. + return suggestion.type === 'post_tag' ? 'tag' : suggestion.type; +} + export default LinkControlSearchItem; diff --git a/packages/block-editor/src/components/link-control/search-results.js b/packages/block-editor/src/components/link-control/search-results.js index cc24b81f18b17..871e84a756a4f 100644 --- a/packages/block-editor/src/components/link-control/search-results.js +++ b/packages/block-editor/src/components/link-control/search-results.js @@ -132,6 +132,7 @@ export default function LinkControlSearchResults( { ) } searchTerm={ currentInputValue } shouldShowType={ shouldShowSuggestionsTypes } + isFrontPage={ suggestion?.isFrontPage } /> ); } ) } From b2c19c3640e494d008c9c254b1fe613dd25edeaf Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Mon, 15 Nov 2021 17:01:42 +0000 Subject: [PATCH 4/8] Remove from memo deps --- .../editor/src/components/provider/use-block-editor-settings.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/editor/src/components/provider/use-block-editor-settings.js b/packages/editor/src/components/provider/use-block-editor-settings.js index f262e64e27145..08b35c1e4a939 100644 --- a/packages/editor/src/components/provider/use-block-editor-settings.js +++ b/packages/editor/src/components/provider/use-block-editor-settings.js @@ -156,7 +156,6 @@ function useBlockEditorSettings( settings, hasTemplate ) { undo, hasTemplate, userCanCreatePages, - pageOnFront, ] ); } From e0a90bc8a7df6e58d8959dd7a62ddc162390492f Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Tue, 16 Nov 2021 15:56:32 +0000 Subject: [PATCH 5/8] Don't allow Front page tag to wrap --- packages/block-editor/src/components/link-control/style.scss | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/block-editor/src/components/link-control/style.scss b/packages/block-editor/src/components/link-control/style.scss index 29b1028d489a8..cd1174e430d73 100644 --- a/packages/block-editor/src/components/link-control/style.scss +++ b/packages/block-editor/src/components/link-control/style.scss @@ -287,6 +287,7 @@ $preview-image-height: 140px; font-size: 0.9em; background-color: $gray-100; border-radius: 2px; + white-space: nowrap; // tags shouldn't go over two lines. } .block-editor-link-control__search-item-description { From 50b8c0be96582f2610a4d59d15fbbb2459b97dee Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Tue, 16 Nov 2021 15:56:49 +0000 Subject: [PATCH 6/8] Ensure editor gets id of pageonfront when it arrives from network --- .../editor/src/components/provider/use-block-editor-settings.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/editor/src/components/provider/use-block-editor-settings.js b/packages/editor/src/components/provider/use-block-editor-settings.js index 08b35c1e4a939..f262e64e27145 100644 --- a/packages/editor/src/components/provider/use-block-editor-settings.js +++ b/packages/editor/src/components/provider/use-block-editor-settings.js @@ -156,6 +156,7 @@ function useBlockEditorSettings( settings, hasTemplate ) { undo, hasTemplate, userCanCreatePages, + pageOnFront, ] ); } From 9f7c6daaf1b494581c8c83f846ac422ccb32156c Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 6 Jan 2022 16:55:25 +0000 Subject: [PATCH 7/8] Remove icon --- .../src/components/link-control/search-item.js | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/packages/block-editor/src/components/link-control/search-item.js b/packages/block-editor/src/components/link-control/search-item.js index 3d1c006d70f37..90b0ce0592110 100644 --- a/packages/block-editor/src/components/link-control/search-item.js +++ b/packages/block-editor/src/components/link-control/search-item.js @@ -9,7 +9,7 @@ import classnames from 'classnames'; import { safeDecodeURI, filterURLForDisplay } from '@wordpress/url'; import { __ } from '@wordpress/i18n'; import { Button, TextHighlight } from '@wordpress/components'; -import { Icon, globe, home } from '@wordpress/icons'; +import { Icon, globe } from '@wordpress/icons'; export const LinkControlSearchItem = ( { itemProps, @@ -19,7 +19,6 @@ export const LinkControlSearchItem = ( { isURL = false, searchTerm = '', shouldShowType = false, - isFrontPage = false, } ) => { return (