-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Core Data: Retrieve the pagination totals in the getEntityRecords calls #55164
Conversation
@@ -97,8 +108,35 @@ export default function useEntityRecords< RecordType >( | |||
[ kind, name, queryAsString, options.enabled ] | |||
); | |||
|
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 noticed that this hook is using a special useQuerySelect
. That felt a bit too magic to me, I'd have preferred as simple useSelect I think but it's not that important.
Size Change: +99 B (0%) Total Size: 1.65 MB
ℹ️ View Unchanged
|
if ( entityConfig.supportsPagination && query.per_page !== -1 ) { | ||
const response = await apiFetch( { path, parse: false } ); | ||
records = Object.values( await response.json() ); | ||
meta = { |
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.
Would we need error handling here, like we do inside apiFetch
when we parse the response?
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.
Well, if we had proper error handling (like storing the error in the state and status) probably but right now, I don't think there's anything special happening even in the "parse: true" case. The error is just ignored it seems (the finally is triggered obviously).
Could we consider storing the full response headers in the data store and providing the convenience selectors on top of it? It would be very useful to have access to things like the |
Flaky tests detected in dae8f0b9bd588f6850439047581857ce7e08f8e0. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6457901116
|
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.
Impressive work and so fast Riad! 🚀
This looks good and I agree with @TimothyBJacobs that we could probably store all the headers.
core-data is meant to be an abstraction to retrieve data for users, not just a way to pass through REST API concepts. I'm ok adding more headers but we need to think properly about how to present them to the consumers. We already abstract "allow" headers using I'd like to take a use-case per use-case approach instead of just a pass through approach. |
dae8f0b
to
6881750
Compare
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.
This looks good and tests well for me. Let's get it in, thanks!
This reverts commit f422d50a65a1e71e1d6a69d0a20aa806d3a5f928.
Related to #55083
Follow-up to #55154
What?
This PR adds support for retrieving the total items and total pages from the response of the getEntityRecords calls. It also automatically adds these values to the
useEntityRecords
returned object.Why?
This allows us to avoid the extra apiFetch request we're doing to fetch these headers in the page list in the site editor.
Note
I've noted a couple other places where these headers are directly consumed but I left these untouched for this PR.
Testing Instructions
1- Open the page list in the site editor
2- Play with pagination (totals should be rendered properly)