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

How to get X-WP-TotalPages from getRawEntityRecords? #39411

Closed
zeeene opened this issue Mar 13, 2022 · 5 comments
Closed

How to get X-WP-TotalPages from getRawEntityRecords? #39411

zeeene opened this issue Mar 13, 2022 · 5 comments
Labels
Developer Experience Ideas about improving block and theme developer experience Needs Dev Ready for, and needs developer efforts [Package] Core data /packages/core-data [Type] New API New API to be used by plugin developers or package users.

Comments

@zeeene
Copy link

zeeene commented Mar 13, 2022

Description

Hi there, I'm new to Gutenberg, my apologies for the off-topic.

I found the core-data package is handy for accessing data from the backend, So I'm trying to use getRawEntityRecords for fetching posts and it works out of the box. I checked the documentation but looks like it doesn't provide all the data as REST API. I would really appreciate it if someone can help me to find out these mentioned points below:

  • How can I access Response Header? ( I need X-WP-TotalPages to display pagination )
  • Is there any option to invalidate the cache of getRawEntityRecords manually?

Step-by-step reproduction instructions

Screenshots, screen recording, code snippet

No response

Environment info

No response

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

@Mamaduka Mamaduka added the [Type] Help Request Help with setup, implementation, or "How do I?" questions. label Mar 14, 2022
@gziolo gziolo added the [Package] Core data /packages/core-data label Mar 22, 2022
@gziolo
Copy link
Member

gziolo commented Mar 22, 2022

Hello, there is no high-level API to use at the moment that I would be aware of, but I can share an example in the codebase where a workaround exists:

apiFetch( {
path: addQueryArgs( '/wp/v2/comments', {
...queryArgs,
post: postId,
per_page: perPage,
_fields: 'id',
} ),
method: 'HEAD',
parse: false,
} ).then( ( res ) => {
setDefaultPages( {
...defaultPages,
[ key ]: parseInt( res.headers.get( 'X-WP-TotalPages' ) ),
} );
} );

@adamziel, it's something that would be great to integrate in the @wordpress/core-data package.

@gziolo gziolo added [Type] New API New API to be used by plugin developers or package users. Needs Dev Ready for, and needs developer efforts and removed [Type] Help Request Help with setup, implementation, or "How do I?" questions. labels Apr 1, 2022
@gziolo gziolo added [Priority] High Used to indicate top priority items that need quick attention Developer Experience Ideas about improving block and theme developer experience labels Sep 1, 2022
@Mamaduka
Copy link
Member

I think this was resolved via #55164.

@gziolo
Copy link
Member

gziolo commented Dec 19, 2023

@youknowriad, can you confirm?

@annezazu annezazu removed the [Priority] High Used to indicate top priority items that need quick attention label Dec 19, 2023
@annezazu
Copy link
Contributor

👋🏼 doing a sweep of high priority issues to keep the label relevant and actionable. I've removed this label as it's not clear if this is still actionable and it's stalled for quite some time. If the label needs to be added back in, go for it but please add context as to why it's still relevant and relevant to the degree of needing quick mobilization across the project to address.

@youknowriad
Copy link
Contributor

Yes, this is addressed with the getEntityRecordsTotalPages selector.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Developer Experience Ideas about improving block and theme developer experience Needs Dev Ready for, and needs developer efforts [Package] Core data /packages/core-data [Type] New API New API to be used by plugin developers or package users.
Projects
None yet
Development

No branches or pull requests

5 participants