-
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
[ New Block ] Add Query Total block for displaying total query results or ranges #67629
[ New Block ] Add Query Total block for displaying total query results or ranges #67629
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. |
I’m relatively new to contributing, but I’ve taken a bold step with this PR. I apologize in advance if I’ve made any mistakes along the way! |
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.
Having this in core is going to be super helpful! :) Added some initial notes 👍
@fabiankaegy I’ve implemented the requested changes. Could you please help me with the failing test? I’m currently working on the |
I think all the JS ones are due to the missing fixture. The PHP ones are because the two functions you added are missing an |
It looks like there is also an experimental block Comments Count that would be very similar. I don't know why it is still experimental, but it was raised by @carolinan recently on WordPress Slack: https://wordpress.slack.com/archives/C02QB2JS7/p1733463619396909. In case we decide to add this Query related block, we should mirror the handling with the one related to Comments. |
@gziolo here, by handling do you mean the appearance?? |
Co-authored-by: Greg Ziółkowski <[email protected]>
I meant that it would be great to follow up next and improve Comments Count block once these changes are done. By the way, on the technical level this PR is close to ready. I will defer decisions to @fabiankaegy regarding how the user experience looks like. |
From my perspective this also is pretty much ready to go from the editorial experience. I would love to get @jameskoster / @jasmussen to take a look a the block icon as I think that is not an ideal fit yet 🤔 Also as a follow up I would love to have a way to customize the label / omit the label entirely :) |
Yes, as previously discussed, I will be addressing this in a separate pull request. |
// Render output based on the selected display type. | ||
const renderDisplay = () => { | ||
if ( displayType === 'total-results' ) { | ||
return <div>{ __( '12 results found' ) }</div>; |
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.
My last question is where the number 12 comes from. I'm not sure how much these display elements need to represent real data, but in some cases, it would be possible to show the actual number of results and the current settings for items per page.
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.
@gziolo We have a precedence for this in core. The query pagination also doesn't show the real pagination but has a good default value that showcases the block in action 🤔
I think it makes sense here also as 1 - 1 out of 1
doesn't really make sense
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 think it makes sense here also as 1 - 1 out of 1 doesn't really make sense
Now that you shared it. What should happen for edge cases?
1 -1 out of 1
- should it simply display1
or an empty string?1-5 out of 5
- should it display1-5
?
Thank you for the explanation about the number 12
. It's now documented and we can proceed further 😄
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 see that it's mostly covered already in PHP 😄
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 think the proper answer would still be:
1 - 1 out of 1
The format should be:
index of first item on this page
- index of last item on this page
out of total number of results
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.
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.
Looking at the logic, it will show Displaying 1 of 1
which is perfectly fine.
@sarthaknagoshe2002 Actually, regarding the settings sidebar. Right now you are adding an empty panel in the sidebar. We should change that to maybe move the dropdown of options from the block toolbar into the sidebar here. |
Tricky one. In fact I think all pagination, including this smmary which is related to pagination, need a visual refresh. One instinct for making them related, is putting them in a box. For now, I drew a perhaps nicer summary icon, it's not a bad metaphor:
If there's a better metaphor, let's go for it, but perhaps for now this can allow the feature to ship. And as noted, if we like it, let's follow up with better designs for the other pagination icons. |
For this I have tried to maintain consistency with the search block.
|
The main thing here if we want to keep the control in the toolbar (which I'm fine with) is that we then should remove everything in the Inspector 🤔 Right now the inspector has some text in it but no controls |
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.
As shared earlier, I'll approve the code aspects of the new block. It's looking solid from my perspective. Excellent collaboration @sarthaknagoshe2002. That was a fast and efficient feedback loop 🙇🏻
Let's finalize the design decisions before proceeding with merging.
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 works well and the experience in the editor is as expected :)
Great job here! This is ready to go :)
@fabiankaegy @gziolo Thank you so much for your invaluable support with this PR. Honestly, this feels like a significant milestone in my journey as a contributor. I truly appreciate you guiding me and making me feel at ease as a rookie. Thanks again for carrying me through and creating such a welcoming and supportive environment! |
Closes: #62423
What?
This PR adds a core/query-total block to display query-related information, such as the total number of results or the range of results currently displayed.
Why?
Currently, there is no block that displays the total number of query results or the range of displayed results, limiting users' ability to convey query information effectively. This block enhances usability and customization options in the block editor.
How?
displayType
to toggle between "Total Results" and "Range Display."query context
(queryId, query).Testing Instructions
displayType
attribute to "Total Results" or "Range Display" via block controls.Screenshots or screencast
query-total.block.mov