#40188 closed defect (bug) (fixed)
Filter button should not appear when no comments are available in list
Reported by: | swissspidy | Owned by: | Jim_Panse |
---|---|---|---|
Milestone: | 5.5 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Comments | Keywords: | has-patch has-unit-tests |
Focuses: | ui, administration | Cc: |
Description
Previously: #37407. See also: #38341. Both tickets contain some screenshots that demonstrate the issue.
It doesn't make sense to be able to filter the comments list table when there are are no (trashed/spam) comments available.
Maybe there are other list tables that might need to be checked as well.
Attachments (14)
Change History (49)
#1
@
8 years ago
Not quite sure if i did it the right way. My first patch, so have some patience with me, please. And guide me into the right direction, if i forgot something.
#2
@
8 years ago
@Jim_Panse Thanks for your patch.
Please note that it also hides the filter button after applying a filter. For example, when I have 1 regular comment on my blog and I change the filter from "All comment types" to "Pings", the filter button now is hidden and I can't change the filter again.
#3
@
8 years ago
- Keywords has-patch added; needs-patch removed
@swissspidy Attached a new patch file and added a helper function. Please have a look, thank you!
#4
@
8 years ago
@Jim_Panse It looks like your patch is reversed (what is red should be green).
A helper method shouldn't be needed though. Why not simply use get_comments( array( 'number' => 1 ) )
in the condition?
#5
@
8 years ago
Ups, new Patch attached.
I think it makes for a much cleaner code, if i add the helper function instead of calling get_comments directly in the if statement.
#6
@
8 years ago
It's really not needed though.
$comments = get_comments( array( 'number' => 1, ) ); if( $comments ) { return true; } else { return false; }
is a worse version of
return get_comments( array( 'number' => 1, ) );
This means you can just as well use
if ( 'top' === $which && get_comments( array( 'number' => 1 ) ) ) { … }
which is way cleaner.
#8
@
7 years ago
A thought, though I haven't deep dived into the code to find its feasibility:
Maybe there are other list tables that might need to be checked as well.
@swissspidy concern is valid. This is a feature common to all list tables (WP_List_Table) i.e, all lists should display the Filter option if and only if there is at least one list item.
In fact, in the comments list table, this functionality should reflect in all sub lists - All, Pending, Approved, Spam and Trash. Likewise, in other lists like posts, categories, tags and so on.
With this in mind, a solution at the WP_List_Table class level would be better.
#9
@
7 years ago
- Owner set to Jim_Panse
- Status changed from new to assigned
Assigning ownership to mark the good-first-bug
as "claimed".
This ticket was mentioned in Slack in #core by akbarhusen. View the logs.
7 years ago
#11
@
7 years ago
- Keywords needs-patch added; has-patch removed
@akbarhusen429 Have you tested this? Because there's no has_comments()
method in WP_Comments_List_Table()
. That means your code doesn't work.
There was such a method in 40188.2.patch, but as per prior comments it was not really needed.
Also see another comment above:
This is a feature common to all list tables (WP_List_Table) i.e, all lists should display the Filter option if and only if there is at least one list item.
With this in mind, a solution at the WP_List_Table class level would be better.
#12
@
7 years ago
- Keywords has-patch added; needs-patch removed
I think we really encounter the problem with Comment type ( Comment and Ping) as @swissspidy said before
Please note that it also hides the filter button after applying a filter. For example, when I have 1 regular comment on my blog and I change the filter from "All comment types" to "Pings", the filter button now is hidden and I can't change the filter again.
Why a user need to see a "Ping" option when there isn't any pingback or trackback. We should check the number of comment or ping before display the filter option for it respectively.
Others like post, user, plugin doesn't have this problem.
From here, we can hide the extra_tablenav
which contains Filter dropdown when there isn't any item.
This ticket was mentioned in Slack in #core by dinhtungdu. View the logs.
7 years ago
#14
@
7 years ago
- Keywords has-unit-tests added
- we introduce a new
comment_status_dropdown()
method ofWP_Comments_List_Table
, to make it more readable, in a similar way as thecategories_dropdown()
method was introduced inWP_Posts_List_Table
.
- the select option's content is escaped, just as in the
walker_pagedropdown()
.
- we test if the filter
admin_comment_types_dropdown
returns an empty array, to make sure that no empty<select>
dropdown is displayed.
- only display a status in the dropdown with a
get_comments( array( 'number' => 1, 'type' => $type )
check, as previously suggested.
I like the idea to remove the table nav for no comments in WP_List_Table
, like:
protected function display_tablenav( $which ) { if( ! $this->has_items() ) { return; } ...
but it sounded out of scope according to the current ticket title, so I did a smaller step instead, in WP_Comments_List_Table
only, similar to the approach in #37407
Added a test, based on the ones in #38341
test_filter_button_should_not_be_shown_if_there_are_no_comments()
and then two more:
test_filter_button_should_be_shown_if_there_are_comments()
test_filter_comment_status_dropdown_should_be_shown_if_there_are_comments()
It was a real headache to make the last two work as expected, because after lot of digging I found out that other tests where modifying the $_REQUEST
global and that was being picket up here by our WP_Comments_List_Table
instance. That meant the offset ended up as 120 and no comments where returned ;-)
So I will create a new ticket to fix these older tests, so currently our tests are blocked by that.
Update: See ticket #42044 addressing that.
This ticket was mentioned in Slack in #core by sergey. View the logs.
4 years ago
#17
@
4 years ago
- Keywords needs-refresh needs-dev-note added
The latest patch no longer applies cleanly to trunk
, so marking this for a refresh. Also, with the new function, this deserves a call-out on the Misc Dev Note.
This ticket was mentioned in Slack in #core by david.baumwald. View the logs.
4 years ago
#20
@
4 years ago
There is a pretty big forehead on the page if the filter buttons are missing. Should we add some CSS to make it look a little nicer?
I might be over thinking this.
#22
@
4 years ago
Missed pressing submit on the comment, but 40188.3.diff is adding a check to prevent the top actions nav from being shown. This gets rid of the big forehead on the page.
#23
@
4 years ago
if ( ! empty( $output ) && $this->has_items() )
It's not quite clear why this check doesn't use the $has_items
static variable declared above, while the next check does use the variable:
if ( ( 'spam' === $comment_status || 'trash' === $comment_status ) && current_user_can( 'moderate_comments' ) && $has_items ) {
If that's intentional, it should be documented.
It's also worth noting that class-wp-posts-list-table.php
and class-wp-ms-sites-list-table.php
don't check $this->has_items()
, just ! empty( $output )
. Would be nice to bring some consistency here.
#24
@
4 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
Reopening this to discuss/address the points raised in comment:23.
#25
@
4 years ago
- Keywords needs-dev-note removed
I'm also going to exclude this from the miscellaneous developer note. Even though there is a new method being introduced, there is not much here for developers to be aware of.
#26
@
4 years ago
@SergeyBiryukov 40188.4.diff attached should make the conditionals the same.
It's also worth noting that
class-wp-posts-list-table.php
andclass-wp-ms-sites-list-table.php
don't check$this->has_items()
, just! empty( $output )
. Would be nice to bring some consistency here.
Moving this over to #50815 so that it isn't blocked against the 5.5 milestone.
#27
@
4 years ago
- Keywords commit dev-feedback added; good-first-bug removed
If we can get a review here, we can address this little bit of cleanup in 5.5 RC2 today.
This ticket was mentioned in Slack in #core by whyisjake. View the logs.
4 years ago
#30
follow-up:
↓ 34
@
4 years ago
- Keywords dev-reviewed added; dev-feedback removed
- Resolution fixed deleted
- Status changed from closed to reopened
Reopening for the 5.5 branch.
#31
@
4 years ago
[48722] caused unit test failures:
There were 2 failures: 1) Tests_Admin_includesListTable::test_filter_button_should_be_shown_if_there_are_comments Failed asserting that '<div class="alignleft actions"></div>' contains "id="post-query-submit"". /var/www/tests/phpunit/tests/admin/includesListTable.php:316 2) Tests_Admin_includesListTable::test_filter_comment_status_dropdown_should_be_shown_if_there_are_comments Failed asserting that '<div class="alignleft actions"></div>' contains "id="filter-by-comment-type"". /var/www/tests/phpunit/tests/admin/includesListTable.php:338
Reverting for now, let's clean this up in #50815.
Patch for #40188