Opened 15 months ago
Last modified 5 months ago
#62701 new enhancement
Post controller: support for grouping results by parent-child relationship
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Future Release | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | REST API | Keywords: | has-patch has-unit-tests gutenberg-merge changes-requested |
| Focuses: | performance | Cc: |
Description
The current wp-admin displays hierarchical posts grouped/sorted by hierarchy. To implement the same behaviour in the site editor, we need to the REST API to support the same functionality.
See details in the related issues/PRs:
- Showcase hierarchy in table/list layout https://github.com/WordPress/gutenberg/issues/55957
- Gutenberg PR https://github.com/WordPress/gutenberg/pull/66479
- Backport PR https://github.com/WordPress/wordpress-develop/pull/8014
Change History (16)
This ticket was mentioned in PR #8014 on WordPress/wordpress-develop by @oandregal.
15 months ago
#1
- Keywords has-unit-tests added
This ticket was mentioned in Slack in #core by joemcgill. View the logs.
13 months ago
@oandregal commented on PR #8014:
13 months ago
#3
Why does this need to be another class? Why can't this be part of the WP_REST_Posts_Controller class?
I'm not married to this implementation, it's just an artifact of having been developed in Gutenberg first.
It was backported verbatim from there, where there's no WP_REST_Post_Controller class. I used the existing filters so the changes were isolated. Merging them as part of the controller class could work, having a single function that calculates it all is also an option, etc. — don't have a strong opinion. My only suggestion would be to 1) keep the changes centralized in a single place as opposed to scattered through the controller class and 2) keep them testable. This is an important domain piece that can degrade easily if it's goes unchecked.
@oandregal commented on PR #8014:
13 months ago
#4
Is there a reason this should be implemented as a new request param, rather than extending the existing orderby to handle this use case?
orderby_hierarchy _configures_ how orderby works: either normally or considering hierarchy. I didn't occur to me to overload orderby with this "new mode", and now that I think of it I don't see a clean way to do it either.
@oandregal commented on PR #8014:
13 months ago
#5
Is there a reason why it's important to do the sorting and include the levels property in the return value, rather than doing that sorting in the client based on the returned post IDs and parents? Returning a REST response shape solely for the purpose of mapping to the visual display in the UI seems like code smell to me unless that value is necessary for some other purpose.
Levels need to be calculated absolutely (based on all the data) and not just relative to the page that is sent to the browser. Otherwise, we'll end up with the wrong levels.
For example, if we had the following dataset and each page sent to the client was of 5 items:
1 - 2 -- 3 -- 4 - 5 -- 6 --- 7 --- 8 - 9 - 10
The levels of the items in the first page (1 to 5) would be calculated properly. For calculating the levels of the items in the second page (6 to 10) we wouldn't have any information about their ancestors.
This ticket was mentioned in Slack in #core by audrasjb. View the logs.
12 months ago
#8
@
12 months ago
- Keywords changed from has-patch, has-unit-tests, gutenberg-merge to has-patch has-unit-tests gutenberg-merge
There are several change requests in the PR, so I'd be inclined to punt it to 6.9, but it was actually merge on Gutenberg' side (in version 20.0), so I assume we'll need to merge it in 6.8? Or maybe not?
What do you think @joemcgill @oandregal?
#9
@
12 months ago
- Milestone changed from 6.8 to 6.9
As per today's bug scrub: It appears this ticket still needs some work. As 6.8 beta 1 is very close, I'm moving it to 6.9. Feel free to move it back to 6.8 if it can be committed by Monday.
#10
@
6 months ago
- Focuses performance added
- Keywords changes-requested added
It looks like this had a negative performance impact which should be investigated before it moves into core. Adding the performance focus.
There are also a number of outstanding comments on the PR that need to be addressed.
@TimothyBlynJacobs commented on PR #8014:
6 months ago
#11
Is there any prior art this was drawn from in other REST APIs? Is there prior art we should look at?
@oandregal commented on PR #8014:
6 months ago
#12
Is there any prior art this was drawn from in other REST APIs? Is there prior art we should look at?
I haven't seen this implemented in any of our endpoints, or in other REST APIs. Happy to review alternatives. The goal is to support hierarchical data display in the site editor, like wp-admin does.
I'll probably have time to refresh this for the 6.9 cycle, so any feedback is welcome.
This ticket was mentioned in Slack in #core by welcher. View the logs.
5 months ago
@oandregal commented on PR #8014:
5 months ago
#15
This was reviewed in the bug scrub today for 6.9.
My recommendation would be to move it to 7.0. I've been focused on other things and didn't have time to look at this properly.
Trac ticket https://core.trac.wordpress.org/ticket/62701#ticket
See related Gutenberg issues/PRs:
## What
This PR expands the post controller to allow returning the data by parent-child relationship (sort by hierarchy).
## Why
We want to display data in a hierarchical way in the site editor, similarly to what we do in wp-admin:
## How to test
Added a new test suite to test the logic. Without the related Gutenberg PR this is difficult to test.