-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Try migrate link suggestions to use Core Data #57582
base: trunk
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -623,6 +623,18 @@ export function defaultTemplates( state = {}, action ) { | |
return state; | ||
} | ||
|
||
export function linkSuggestions( state = {}, action ) { | ||
switch ( action.type ) { | ||
case 'RECEIVE_LINK_SUGGESTIONS': | ||
return { | ||
...state, | ||
[ action.search ]: action.suggestions, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this indexing strategy is good enough. A search is a simple string but the API allows for searching by different entities such as |
||
}; | ||
} | ||
|
||
return state; | ||
} | ||
|
||
export default combineReducers( { | ||
terms, | ||
users, | ||
|
@@ -644,4 +656,5 @@ export default combineReducers( { | |
userPatternCategories, | ||
navigationFallbackId, | ||
defaultTemplates, | ||
linkSuggestions, | ||
} ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1491,3 +1491,21 @@ export const getRevision = createSelector( | |
]; | ||
} | ||
); | ||
|
||
/** | ||
* Fetch link suggestions for a given search term. | ||
* | ||
* @param state Data state. | ||
* @param search Search term. | ||
* @param searchOptions | ||
* @param settings | ||
* @return Link suggestions. | ||
*/ | ||
export function getLinkSuggestions( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be a private API. |
||
state, | ||
search = '', | ||
searchOptions, | ||
settings | ||
) { | ||
return state.linkSuggestions[ search ]; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,9 @@ | |
* WordPress dependencies | ||
*/ | ||
import { Platform, useMemo, useCallback } from '@wordpress/element'; | ||
import { useDispatch, useSelect } from '@wordpress/data'; | ||
import { useDispatch, useSelect, resolveSelect } from '@wordpress/data'; | ||
import { | ||
store as coreStore, | ||
__experimentalFetchLinkSuggestions as fetchLinkSuggestions, | ||
__experimentalFetchUrlData as fetchUrlData, | ||
} from '@wordpress/core-data'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
@@ -215,6 +214,10 @@ function useBlockEditorSettings( settings, postType, postId ) { | |
[ saveEntityRecord, userCanCreatePages ] | ||
); | ||
|
||
const syncGetLinkSuggestions = useCallback( async ( ...args ) => { | ||
return await resolveSelect( coreStore ).getLinkSuggestions( ...args ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we make this private how do we There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not use a normal select call in a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we did this then we'd effectively pass something like I think I tried doing this and found it didn't work. I could be wrong - would you expect it to? |
||
}, [] ); | ||
|
||
const forceDisableFocusMode = settings.focusMode === false; | ||
|
||
return useMemo( | ||
|
@@ -232,8 +235,7 @@ function useBlockEditorSettings( settings, postType, postId ) { | |
__experimentalBlockPatterns: blockPatterns, | ||
__experimentalBlockPatternCategories: blockPatternCategories, | ||
__experimentalUserPatternCategories: userPatternCategories, | ||
__experimentalFetchLinkSuggestions: ( search, searchOptions ) => | ||
fetchLinkSuggestions( search, searchOptions, settings ), | ||
__experimentalFetchLinkSuggestions: syncGetLinkSuggestions, | ||
inserterMediaCategories, | ||
__experimentalFetchRichUrlData: fetchUrlData, | ||
// Todo: This only checks the top level post, not the post within a template or any other entity that can be edited. | ||
|
@@ -279,6 +281,7 @@ function useBlockEditorSettings( settings, postType, postId ) { | |
postType, | ||
setIsInserterOpened, | ||
getPostLinkProps, | ||
syncGetLinkSuggestions, | ||
] | ||
); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should make this private. But I wasn't sure how to
unlock
aresolveSelect
.