-
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
Get the page count as derived data #55316
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,11 +14,7 @@ import deprecated from '@wordpress/deprecated'; | |
* Internal dependencies | ||
*/ | ||
import { STORE_NAME } from './name'; | ||
import { | ||
getQueriedItems, | ||
getQueriedTotalItems, | ||
getQueriedTotalPages, | ||
} from './queried-data'; | ||
import { getQueriedItems, getQueriedTotalItems } from './queried-data'; | ||
import { DEFAULT_ENTITY_KEY } from './entities'; | ||
import { | ||
getNormalizedCommaSeparable, | ||
|
@@ -578,7 +574,10 @@ export const getEntityRecordsTotalPages = ( | |
if ( ! queriedState ) { | ||
return null; | ||
} | ||
return getQueriedTotalPages( queriedState, query ); | ||
if ( query.per_page === -1 ) return 1; | ||
const totalItems = getQueriedTotalItems( queriedState, query ); | ||
if ( ! totalItems ) return totalItems; | ||
return Math.ceil( totalItems / query.per_page ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can result in We can try using default I was debugging the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch! I guess if the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you, @ntsekouras! |
||
}; | ||
|
||
type DirtyEntityRecord = { | ||
|
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 wonder if there's a way to store this in the reducer with the "perPage" as a sub key in order to retrieve the right value in the selector instead of computing it.
I wonder which is best
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'm not super confident that I could make that change.. I checked about the sub keys, but haven't touched that part of the code at all before.
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 can make the change myself, I'm just wondering which is better. Should we rely on the server side value or the computed one.
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.
It's a simple calculation and it seems core does that too:
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.
Ok, let's keep it that way for now then, we can always change anytime :)