-
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
Add: Number of templates using a template part and link to see them. #68211
base: trunk
Are you sure you want to change the base?
Add: Number of templates using a template part and link to see them. #68211
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Size Change: +575 B (+0.03%) Total Size: 1.84 MB
ℹ️ View Unchanged
|
Flaky tests detected in 024ba52. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12437493586
|
Part of #60205.
This is the first PR on the tracking of global element usage.
When a template part is open on the editor it shows the number of templates using that template part.
It also includes a link to a view listing the templates using that template part.
Some notes:
Computation of templates using a template part in the client.
The computation of templates using a template part is performed on the client side. I considered extending the API to handle this on the backend, but for templates, that would introduce unnecessary complexity.
The templates endpoint, by default, passes all templates to the client, uses a default per_page setting of -1. Since we are already requesting all the templates in multiple instances, we may as well compute the subset of templates using a template part on the client side.
This computation is done asynchronously to make sure it does not block the render in any way.
The filtering of templates for the ones that use a template part does not rely on dataviews.
Currently, the filters offered by Dataviews do not allow us to filter a template based on the usage of a specific template part. The existing filters only support selecting items whose field has a specific value or does not have a specific value. Unfortunately, the filter we need—"Template uses template part x"—is not applicable, as we don’t even have a field for template parts.
Dataviews filters need to be expanded to accommodate cases where matching depends on a custom condition. This is illustrated in the mockup below:
.
A possible solution could be to implement a field "template parts used". Specifying the set of template parts used in a template, and then have filters that support fields with multiple values ( we will also need that for tags for example).
At present, I filter the set of templates before passing them to Dataviews if the
usingTemplatePart=
parameter is included. While this solution is not ideal, I think, it is acceptable until Dataviews provides filters we can use for this scenario.cc: @ntsekouras, @oandregal — let me know if there is a way to accomplish this using Dataviews that I may have overlooked.
Testing Instructions
Open a template part on the editor for example the sidebar.
Verify the editor shows on the inspector how many templates are using that template part.
Click on the link and verify the list of links using the template part is shown.
Screenshots or screencast