Skip to content
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

Adds suggestions for categories and formats to LinkControl #22600

Merged
merged 24 commits into from
Aug 25, 2020

Conversation

draganescu
Copy link
Contributor

@draganescu draganescu commented May 25, 2020

Description

Closes #20924 and closes #20165

How has this been tested?

Tested locally by:

  1. Make sure you are:
    a) having some categories setup
    b) on a theme that supports post formats (twentyfourteen)
    c) some posts saved as a post formats other than standard
  2. Add a new post
  3. Add a navigation block in that post
  4. Add a new navigation link
  5. Search for something that is included in a category's or a post format's name
  6. Observe the category and/or post format is included in suggestions

Types of changes

  • adds a format search handler
  • adds a category search handler
  • hooks the new handlers in the search endpoint
  • updates LinkControl's fetchLinkSuggestions to handle formats and categories as well

PS
I don't know if this is the best way to implement this feature. However, because we need the link to the format index page, I can't see a better way to get it than from an API call. We could output formats in the bulk data which is rendered on load, but categories could be too many for this option.

cc @getdave - this updates indirectly LinkControl to show more types of suggestions. Suggestions welcome! :)

@draganescu draganescu requested a review from getdave May 25, 2020 15:04
@draganescu draganescu added [Block] Navigation Affects the Navigation Block [Feature] Link Editing Link components (LinkControl, URLInput) and integrations (RichText link formatting) REST API Interaction Related to REST API Needs Design Feedback Needs general design feedback. labels May 25, 2020
@github-actions
Copy link

github-actions bot commented May 25, 2020

Size Change: +2.32 kB (0%)

Total Size: 1.16 MB

Filename Size Change
build/api-fetch/index.js 3.44 kB -3 B (0%)
build/block-directory/index.js 7.97 kB +5 B (0%)
build/block-editor/index.js 126 kB +213 B (0%)
build/block-editor/style-rtl.css 10.7 kB +43 B (0%)
build/block-editor/style.css 10.7 kB +46 B (0%)
build/block-library/editor-rtl.css 8.5 kB +140 B (1%)
build/block-library/editor.css 8.5 kB +140 B (1%)
build/block-library/index.js 133 kB +596 B (0%)
build/block-library/style-rtl.css 7.42 kB -23 B (0%)
build/block-library/style.css 7.43 kB -21 B (0%)
build/block-serialization-default-parser/index.js 1.88 kB +1 B
build/blocks/index.js 47.7 kB +21 B (0%)
build/components/index.js 200 kB +17 B (0%)
build/components/style-rtl.css 15.7 kB -1 B
build/components/style.css 15.7 kB -1 B
build/compose/index.js 9.67 kB -3 B (0%)
build/core-data/index.js 12.3 kB +474 B (3%)
build/data/index.js 8.55 kB -1 B
build/edit-navigation/index.js 11.6 kB +598 B (5%) 🔍
build/edit-navigation/style-rtl.css 1.16 kB +45 B (3%)
build/edit-navigation/style.css 1.16 kB +46 B (3%)
build/edit-post/index.js 304 kB -6 B (0%)
build/edit-site/index.js 17 kB +20 B (0%)
build/edit-widgets/index.js 11.7 kB -1 B
build/editor/index.js 45.3 kB -1 B
build/element/index.js 4.65 kB -2 B (0%)
build/format-library/index.js 7.71 kB -7 B (0%)
build/keycodes/index.js 1.94 kB +2 B (0%)
build/list-reusable-blocks/index.js 3.12 kB +5 B (0%)
build/media-utils/index.js 5.32 kB -10 B (0%)
build/primitives/index.js 1.41 kB -7 B (0%)
build/rich-text/index.js 13.9 kB -2 B (0%)
build/token-list/index.js 1.27 kB -2 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.14 kB 0 B
build/annotations/index.js 3.67 kB 0 B
build/autop/index.js 2.82 kB 0 B
build/blob/index.js 620 B 0 B
build/block-directory/style-rtl.css 953 B 0 B
build/block-directory/style.css 952 B 0 B
build/block-library/theme-rtl.css 729 B 0 B
build/block-library/theme.css 730 B 0 B
build/block-serialization-spec-parser/index.js 3.1 kB 0 B
build/data-controls/index.js 1.29 kB 0 B
build/date/index.js 5.38 kB 0 B
build/deprecated/index.js 772 B 0 B
build/dom-ready/index.js 568 B 0 B
build/dom/index.js 4.47 kB 0 B
build/edit-post/style-rtl.css 5.61 kB 0 B
build/edit-post/style.css 5.61 kB 0 B
build/edit-site/style-rtl.css 3.06 kB 0 B
build/edit-site/style.css 3.06 kB 0 B
build/edit-widgets/style-rtl.css 2.45 kB 0 B
build/edit-widgets/style.css 2.45 kB 0 B
build/editor/editor-styles-rtl.css 537 B 0 B
build/editor/editor-styles.css 539 B 0 B
build/editor/style-rtl.css 3.8 kB 0 B
build/editor/style.css 3.79 kB 0 B
build/escape-html/index.js 733 B 0 B
build/format-library/style-rtl.css 547 B 0 B
build/format-library/style.css 548 B 0 B
build/hooks/index.js 2.13 kB 0 B
build/html-entities/index.js 621 B 0 B
build/i18n/index.js 3.56 kB 0 B
build/is-shallow-equal/index.js 711 B 0 B
build/keyboard-shortcuts/index.js 2.52 kB 0 B
build/list-reusable-blocks/style-rtl.css 476 B 0 B
build/list-reusable-blocks/style.css 476 B 0 B
build/notices/index.js 1.79 kB 0 B
build/nux/index.js 3.4 kB 0 B
build/nux/style-rtl.css 671 B 0 B
build/nux/style.css 668 B 0 B
build/plugins/index.js 2.56 kB 0 B
build/priority-queue/index.js 789 B 0 B
build/redux-routine/index.js 2.85 kB 0 B
build/server-side-render/index.js 2.77 kB 0 B
build/shortcode/index.js 1.7 kB 0 B
build/url/index.js 4.06 kB 0 B
build/viewport/index.js 1.85 kB 0 B
build/warning/index.js 1.14 kB 0 B
build/wordcount/index.js 1.17 kB 0 B

compressed-size-action

Copy link
Contributor

@adamziel adamziel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@draganescu I left a few minor notes but nothing big. You'll need to run this through a linter too to make travis happy. What worked for me in the past was npm run lint-php. Overall this looks good and works so 👍

@TimothyBJacobs
Copy link
Member

I think implementing this handling as a search handler makes a lot of sense, but I think the categories handler should be generic to any taxonomy, the same way WP_REST_Post_Search_Handler does. I think the post formats can stay the way that it is.

We'll also want to implement links the same way the posts handler does but to the individual terms.

@spacedmonkey
Copy link
Member

Unit tests would be good here

What about tags?

@rickalee
Copy link

rickalee commented Jun 2, 2020

Should this include all taxonomies and terms with show_in_rest = true as well as Authors/Users?

@draganescu
Copy link
Contributor Author

Yes @rickalee I'm working on making the new endpoint generic for all terms :)

@goaround
Copy link

I would suggest adding a Type chooser to the LinkControl that you can explicitly search for a Post (preselected), Term (Category, Tags or public Custom Post Types) and that developer can register their own Search Handler, and they will be shown in the LinkControl UI.

You can get all types from /wp-json/ --> /wp/v2/search --> endpoints --> args --> type and even subtype

I created a little Plugin as a Gist: https://gist.github.com/goaround/3a91ed216453bb19b9da69a9643468fa which registers a WP_REST_Taxonomy_Search_Handler and intercepts the search request if the query starts with -ter for Term e.g. -ter WordPress. More information (in german) on my blog: https://go-around.de/blog/interne-link-suche-wordpress-block-editor/

@draganescu
Copy link
Contributor Author

I've changed the Category search handler into a Terms search handler that now looks for search in all the public taxonomies.

I still need to add tests to this PR.

@TimothyBJacobs
Copy link
Member

We'll also need to add links to prepare_links for each item returned. You can take a look at the post handler for an example.

@draganescu draganescu force-pushed the add/formats-categories-suggestions branch from 68ba601 to 029c768 Compare June 18, 2020 11:30
@draganescu draganescu force-pushed the add/formats-categories-suggestions branch from ed2a159 to 6d2cb57 Compare July 10, 2020 13:23
adds a format search handler
adds a category search handler
hooks the new handlers in the search endpoint
updates LinkControl's fetchLinkSuggestions to handle formats and categories as well
@noisysocks
Copy link
Member

I've addressed all the feedback here and added unit tests.

@TimothyBJacobs: Would you mind giving this another look?

@draganescu
Copy link
Contributor Author

Thank you @noisysocks for taking this over, looks pretty good. Not merging before the OK from @TimothyBJacobs :)

Copy link
Member

@TimothyBJacobs TimothyBJacobs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making those changes! I've left some more comments.

lib/class-wp-rest-term-search-handler.php Outdated Show resolved Hide resolved
lib/class-wp-rest-term-search-handler.php Outdated Show resolved Hide resolved
lib/class-wp-rest-term-search-handler.php Outdated Show resolved Hide resolved
lib/class-wp-rest-term-search-handler.php Outdated Show resolved Hide resolved
lib/class-wp-rest-term-search-handler.php Outdated Show resolved Hide resolved
lib/rest-api.php Outdated Show resolved Hide resolved
phpunit/class-wp-rest-post-format-search-handler-test.php Outdated Show resolved Hide resolved
phpunit/class-wp-rest-post-format-search-handler-test.php Outdated Show resolved Hide resolved
@rickalee
Copy link

Possible to add author archives while building this?

@noisysocks
Copy link
Member

Possible to add author archives while building this?

Right now I'm focused on only building out what's necessary for the new Navigation screen in Gutenberg. You're welcome to create a ticket in Trac for adding a new author archives search handler. You could copy and paste the code that's in this PR to get a head start on it.

@noisysocks
Copy link
Member

noisysocks commented Aug 25, 2020

@TimothyBJacobs: Thanks for the great feedback! I addressed or responded to everything.

@TimothyBJacobs TimothyBJacobs self-requested a review August 25, 2020 02:38
Copy link
Member

@TimothyBJacobs TimothyBJacobs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REST API wise everything looks good to me!

@noisysocks noisysocks merged commit a0f36df into master Aug 25, 2020
@noisysocks noisysocks deleted the add/formats-categories-suggestions branch August 25, 2020 03:41
@github-actions github-actions bot added this to the Gutenberg 8.9 milestone Aug 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Navigation Affects the Navigation Block [Feature] Link Editing Link components (LinkControl, URLInput) and integrations (RichText link formatting) Needs Design Feedback Needs general design feedback. REST API Interaction Related to REST API
Projects
None yet
8 participants