-
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
Allow media library in gallery mode to be reset #20675
Merged
talldan
merged 1 commit into
master
from
fix/allow-media-library-in-gallery-mode-to-be-reset
Mar 20, 2020
Merged
Allow media library in gallery mode to be reset #20675
talldan
merged 1 commit into
master
from
fix/allow-media-library-in-gallery-mode-to-be-reset
Mar 20, 2020
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
talldan
added
[Feature] Media
Anything that impacts the experience of managing media
[Type] Bug
An existing feature does not function as intended
labels
Mar 6, 2020
Size Change: +5 B (0%) Total Size: 863 kB
ℹ️ View Unchanged
|
draganescu
approved these changes
Mar 20, 2020
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.
LGTM, tested as described and works. Plus empty array is a better default than "null" for any thing that should contain a list.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
[Feature] Media
Anything that impacts the experience of managing media
[Type] Bug
An existing feature does not function as intended
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Fixes #20627
#20627 describes a situation where passing a falsey value or empty array into the
MediaUpload
component still results in the media library showing the Edit Gallery view with the previous selection of gallery images still selected.The expected behaviour is for the library to be reset to its original Create Gallery mode. This PR upates the MediaUpload component to have that behaviour.
This core problem was that
this.buildAndSetGalleryFrame();
wasn't being called when thevalue
was falsey or an empty array, so the previous edit view was still being recycled:gutenberg/packages/media-utils/src/components/media-upload/index.js
Lines 420 to 426 in 8a94254
In addition to that,
buildAndSetGalleryFrame
had some checks for thevalue
being falsey to determine whether the edit or create view should be displayed. Given a media library is most likely to be used with a gallery, and galleries supply an array of images, it seemed prudent to primarily check for an empty array. The function now does this, but also supportsundefined
as a value.How has this been tested?
A custom block with the following code needs to be registered as none of our core blocks have the ability to reset a gallery.:
Previous Behaviour: The media library displayed the 'Edit Gallery' view even though the gallery is now supposed to contain no images.
Types of changes
Bug fix (non-breaking change which fixes an issue)
Checklist: