-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Gallery: Update media frame state management #2488
Gallery: Update media frame state management #2488
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2488 +/- ##
==========================================
- Coverage 44% 27.11% -16.9%
==========================================
Files 398 159 -239
Lines 9015 4902 -4113
Branches 1596 817 -779
==========================================
- Hits 3967 1329 -2638
+ Misses 4322 3030 -1292
+ Partials 726 543 -183
Continue to review full report at Codecov.
|
blocks/media-upload-button/index.js
Outdated
@@ -121,25 +142,6 @@ class MediaUploadButton extends Component { | |||
onSelect( multiple ? attachment : attachment[ 0 ] ); | |||
} | |||
|
|||
onOpen() { |
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 guess this means we should also set a selection object when we're not in a gallery (Editing an image block is broken with this change).
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.
Ah right. We do need to handle this the same way for images as well.
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.
The problem was fixed with the new commit I added :)
blocks/media-upload-button/index.js
Outdated
@@ -78,11 +92,19 @@ class MediaUploadButton extends Component { | |||
} | |||
|
|||
if ( gallery ) { | |||
const ids = this.props.value || []; | |||
const attachments = getAttachmentsCollection( ids ); | |||
const currentState = ( this.props.value ) ? 'gallery-edit' : 'gallery'; |
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.
Should we do the same for a single media? I mean do we have something like 'edit' and 'select' states for single media selector?
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.
Hi, @youknowriad we have edit states for single media like audio and video, but this states open with a modal to change details like sizes, captions etc of the item that we can now change in the Gutenberg block. So for single media I don't think we should use this states.
blocks/media-upload-button/index.js
Outdated
@@ -78,11 +92,19 @@ class MediaUploadButton extends Component { | |||
} | |||
|
|||
if ( gallery ) { |
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.
Isn't the gallery
prop a duplicate of multiple
prop?
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.
Not exactly, because you could use a media upload button to insert multiple images that are not in a gallery. I would like to see us handle props differently for galleries than passing a gallery
prop (see: #1979) but was going to leave that as a separate issue.
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.
In this case, should we expect the selection
object to be dependent on the multiple
prop instead of the gallery
prop. I'm guessing the selection shape depends on whether the selection is multiple or not, and not whether it's a gallery view or not?
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 what you're getting at. Yeah, we could probably use a similar method in both cases.
Any plans to update this. I'm thinking addressing at least this is important.
-- |
Hi @youknowriad, thanks for checking in. I clearly haven't had the time to circle back to this issue, but I agree that it would be nice to update/finish this off. I should have time in a few weeks to dig back into this issue if you're ok with leaving it open. |
@joemcgill Sure, not urgent at all, just wanted to check in. Let's leave it open. |
…ding of media frame when editing a gallery; Editing a gallery opens media frame in gallery-edit state This sets the editing option based on the values property of our component. Previously, we were replacing the media frame state right before opening the modal, but after views like the menu were created. This caused a few bugs, like the cancel button moving back to the initial "create gallery" state and some labels being incorrect. This creates a selection from any existing IDs and passes it to the frame before it is created to avoid these issues. Additionally, this updates the method for getting a collection of attachments using `wp.media.query` so we can fetch all of the attachment models in one request, rather than relying on seperate requests for each attachment in the gallery. When opening the `wp.media` modal to modify an existing gallery, the frame should be opened in the `gallery-edit` state, rather than the `gallery` state used when selecting images for a new gallery.
…d; Corrected bug where if gallery was empty all media content was loaded.
271fa19
to
4586353
Compare
Hi @joemcgill, @youknowriad, |
}; | ||
if ( !! type ) { | ||
frameConfig.library = { type }; | ||
} | ||
|
||
if ( gallery ) { |
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.
Still having trouble to understand the difference between gallery
and multiple
props. I wonder if we should consolidate these two or if they are useful separately.
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.
Hi @youknowriad, the gallery flag indicates that we want to use the gallery media frame, the multiple still uses the normal select frame but allows us to select multiple files. Imagine a document block that wants to allow to select multiple documents it may use multiple flag but not use gallery flag.
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 👍
Nice changes. Thanks for picking this up, @jorgefilipecosta! |
* Gallery: Properly set editing option for the media frame; Improve loading of media frame when editing a gallery; Editing a gallery opens media frame in gallery-edit state This sets the editing option based on the values property of our component. Previously, we were replacing the media frame state right before opening the modal, but after views like the menu were created. This caused a few bugs, like the cancel button moving back to the initial "create gallery" state and some labels being incorrect. This creates a selection from any existing IDs and passes it to the frame before it is created to avoid these issues. Additionally, this updates the method for getting a collection of attachments using `wp.media.query` so we can fetch all of the attachment models in one request, rather than relying on seperate requests for each attachment in the gallery. When opening the `wp.media` modal to modify an existing gallery, the frame should be opened in the `gallery-edit` state, rather than the `gallery` state used when selecting images for a new gallery. * Corrected bug where single media selection was not working as expected; Corrected bug where if gallery was empty all media content was loaded.
Thanks for finishing this one! |
Following #2294, this updates the Media component so that existing galleries instantiate a media frame in the
gallery-edit
state with the correct attachment models passed in on creation, rather than overriding the state after the frame has been created.This fixes several small bugs, like having text from the gallery state still showing in the toolbar, the cancel menu item not working as expected in the menu, etc.
This also reworks the way attachments are fetched so that we can get the entire collection of attachments in a single HTTP request, rather than separate requests for each attachment.