-
Notifications
You must be signed in to change notification settings - Fork 51
Add extensibility filters to ContentPicker and ContentSearch components #373
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
base: develop
Are you sure you want to change the base?
Add extensibility filters to ContentPicker and ContentSearch components #373
Conversation
… and to filter the search result before it is returned
# Conflicts: # components/content-picker/PickedItem.tsx # components/content-picker/SortableList.tsx # package-lock.json # package.json
|
Merge conflicts were addressed. This is ready for review. |
| "@wordpress/icons": "^10.0.0", | ||
| "array-move": "^4.0.0", | ||
| "clsx": "^2.1.1", | ||
| "dompurify": "^3.2.6", |
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.
Lets use https://github.com/WordPress/gutenberg/tree/de11ef92c9f6478fedb7bd5f56b1612943d5c7a9/packages/dom#safehtml instead to avoid the additional dependency
| * @param {ContentSearchMode} mode - The mode of the content search. | ||
| * @returns {string[]} - The filtered fields. | ||
| */ | ||
| fields = applyFilters('tenup.contentSearch.queryFields', fields, mode) as string[]; |
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.
I'm a little worried about the introduction of all these filters... Unlike in PHP here in JS they just behave oddly and are no longer really recommended by the core team...
Also I am a bit worried that there is no way to figure out the context of which component we are talking about. It just applies to all ContentSearch components on the site.
I would rather see an implementation that has the filters needed within the content connect plugin and then passes its callback function into the component as an optional prop. That feels more "safe" to me here.
Description of the Change
This PR introduces four new JavaScript filters to the
ContentPickerandContentSearchcomponents, enabling developers to extend queried fields and customize UI display to better meet client requirements.This approach:
Problem
Client projects frequently require additional information beyond the default fields (title, URL) when picking or searching content. Common requests include displaying post IDs, parent page titles, or custom metadata to help content editors make informed selections.
Solution
Added filters that allow developers to:
New Filters
ContentPicker
tenup.contentPicker.queryFields- Extends fields queried from core WP REST endpointstenup.contentPicker.pickedItem- Customizes picked item UI displayContentSearch
tenup.contentSearch.queryFields- Extends search query fields (requires PHP companion filter)Additionally in PHP:
tenup.contentSearch.searchResult- Customizes search result displayHow to test the Change
Changelog Entry
Credits
Props @s3rgiosan
Checklist: