WordPress.org

Make WordPress Core

Opened 8 weeks ago

Last modified 2 weeks ago

#42239 new defect (bug)

Delete Selected button stays active even all selected images in media library are deselected

Reported by: subrataemfluence Owned by:
Milestone: 5.0 Priority: normal
Severity: normal Version:
Component: Media Keywords: has-patch
Focuses: javascript, administration Cc:

Description

There is an issue with "Delete Selected" button in media library. The button stays active even when all media items are deselected.

Steps to reproduce:

  1. Go to Media (grid view)
  2. Click on "Bulk Select" button
  3. Select one or more media files. "Delete Selected" button gets enabled.
  4. To deselect the selected media item(s) click on the tick marks available on upper right corner of each selected media item(s).
  5. Even all item are deselected "Delete Selected" button still stays enabled.

Attachments (3)

cd03e466-660b-4c90-ybad-3f9216d6c4ec.webm (2.6 MB) - added by subrataemfluence 8 weeks ago.
Screencast
42239.diff (941 bytes) - added by subrataemfluence 8 weeks ago.
Proposed patch
42239.2.diff (922 bytes) - added by adamsilverstein 8 weeks ago.

Change History (13)

#1 @subrataemfluence
8 weeks ago

In case attached webm does not somehow work on some systems, please visit https://youtu.be/flhD6AS_YJQ.

#2 @subrataemfluence
8 weeks ago

  • Keywords needs-patch added

Working on patch.

#3 follow-up: @adamsilverstein
8 weeks ago

@subrataemfluence

Thanks for the bug report and for working on a patch!

I think this worked correctly in the past so it may be worth testing back on previous versions and seeing when exactly this broke (maybe you can find the exact commit with git bisect). In addition, the version dropdown on the ticket should ideally be set to the version that first included the bug.

@subrataemfluence
8 weeks ago

Proposed patch

#4 in reply to: ↑ 3 @subrataemfluence
8 weeks ago

  • Keywords has-patch added; needs-patch removed
  • Version 4.8.2 deleted

Thanks a lot for telling me. Please let me know how do I know which earlier version had this bug
report. Trying to become a better contributor!

For now I have removed the version info.

I have however, attached a proposed patch. Please let me know if this works.

[7:42]
I am still a learner and do not know all such little but important things.

Replying to adamsilverstein:

@subrataemfluence

Thanks for the bug report and for working on a patch!

I think this worked correctly in the past so it may be worth testing back on previous versions and seeing when exactly this broke (maybe you can find the exact commit with git bisect). In addition, the version dropdown on the ticket should ideally be set to the version that first included the bug.

#5 @adamsilverstein
8 weeks ago

@subrataemfluence Thanks for the patch, I will review...

Please let me know how do I know which earlier version had this bug

Easiest is probably to install copies of each version locally and try to reproduce, eg does the bug happen in 4.7? in 4.6? sometimes the bug goes back to when a feature was introduced. You don't have to do this, however sometimes its helpful when hunting for a solution.

#6 @adamsilverstein
8 weeks ago

Nice work! I tested your patch and verified it resolves the issue, however it feels like a brute force approach and I want to dig a bit further to see if I can determine why/when this broke. Also, before your patch, how is the button enabled when you select your first item? Shouldn't that code logic also handle disabling the button?

#7 @adamsilverstein
8 weeks ago

In 42239.2.diff

  • Trigger the controller selection:toggle event when clicking the 'check' box in the media bulk selection mode.

The DeleteSelected button (wp-includes/js/media/views/button/delete-selected.js) listens for this event on the controller and calls toggleDisabled which properly enables or disables the model, triggering a button rerender in the correct state. Before this patch this worked only when clicking on the images themselves to toggle, this extends that to the check box in the upper right corner of each image.

@subrataemfluence can you give this patch a test and verify it resolves the issue you were seeing?

#8 @subrataemfluence
7 weeks ago

@adamsilverstein I have tested the patch and now everything is working nicely.

I understand that my approach was not the right one. Thank you for showing me the right way of doing this :)

#9 @joemcgill
4 weeks ago

  • Milestone changed from Awaiting Review to 4.9.1

#10 @johnbillion
2 weeks ago

  • Milestone changed from 4.9.1 to 5.0
Note: See TracTickets for help on using tickets.