-
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 Block: Add Media Library button to the upload new image area #12367
Gallery Block: Add Media Library button to the upload new image area #12367
Conversation
Could this section be its own independent component so that other blocks could re-use it? It would be super useful when building e.g. alternative gallery blocks or slider blocks. The component could even include the |
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.
Hey @jorgefilipecosta - this looks pretty close. Not sure if it's still WIP. I gave it a review anyway 😄
Would be cool to get a designer to have a look over it. I was thinking a bit on how the button styles were different to the other buttons and wondering if they could be brought closer to or based off of other existing styles instead of just the default.
<li className="blocks-gallery-item has-add-item-button"> | ||
<li className={ classnames( | ||
'blocks-gallery-item', | ||
'has-add-item-button', |
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.
has-add-item-button
seems quite similar in intent to block-library-gallery-add-item
. From what I could find has-add-item-button
is in the wrong place (style.scss instead of editor.scss) and is superceded by your new class, so I think it can be removed:
gutenberg/packages/block-library/src/gallery/style.scss
Lines 122 to 128 in f62f336
// Make the "Add new Gallery item" button full-width (so it always appears | |
// below other items). | |
.blocks-gallery-item { | |
&.has-add-item-button { | |
width: 100%; | |
} | |
} |
gallery | ||
value={ images.map( ( img ) => img.id ) } | ||
render={ ( { open } ) => ( | ||
<IconButton |
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.
Did some testing, and the media library seems to fall out of sync quite easily:
- Create a new gallery with two images
- Click on the new media library button in the gallery appender
- Observe that the two images already added are not present in the list of images that can be added
- Close the media library without making any changes
- In the gallery block, use the 'x' icon button in the top right corner of one of the images to remove it.
- Click on the new media library button again
- Observe that the selection of images has not updated.
Also seeing some weird behaviour when clicking the media library button and switching to the 'Edit Gallery' view, it doesn't always seem to match what can be seen when editing the gallery from the edit toolbar button.
I know you have another PR open that seems related - #12435 - do you think that will solve it?
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.
const currentState = value ? 'gallery-edit' : 'gallery'; | ||
let currentState; | ||
if ( galleryOpenInLibrary ) { | ||
currentState = 'gallery-library'; |
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.
Out of interest how did you know about this setting, are there docs somewhere?
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 @talldan I did not find any documentation regarding this :( I checked what states we have by exploring the core code.
} | ||
} | ||
|
||
.block-library-gallery-add-item__upload-button { |
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 noticed that hovering over the upload button causes the media library button to move slightly to the right and the button text moves slightly downwards. Guessing that's caused by the border.
I also wondered if there's an existing button style that might provide a better base, like the 'tertiary' button.
@@ -78,6 +78,7 @@ class MediaUpload extends Component { | |||
allowedTypes, | |||
multiple = false, | |||
gallery = false, | |||
galleryOpenInLibrary = false, |
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'm not convinced the prop name conveys the right meaning. I think renaming it to something like 'addToGallery' could be clearer.
I would love for us to revisit, holistically, the appender overall, to give more options and a better overall design going into phase 2. However that is probably best done separately, and not as part of this bugfix. 👍 👍for this as a good iteration. |
70134dd
to
e4b97f5
Compare
Hi,
I agree, my plan is, for now, merge the enhancements in the gallery get them a little bit tested and then after everything is polished extract and expose a generic component. Hi @talldan, thank you for your review, I think I addressed all your comments. |
Hey @jorgefilipecosta, thanks for reviving this PR. This works well in my testing! A couple small design notes:
|
Thank you for the review @kjellr I will look into fixing these issues. My plan was to after merging this PR extract a component that allows rendering the gallery appender. I noticed that the gallery appender being implemented here is just equivalent to |
Would it make sense if Or perhaps it should be called <MediaContainer>
<Gallery />
</MediaContainer> Where Something like (very much simplified): function MediaContainer(WrappedComponent) {
return class extends Component {
// handle state, file uploads, notices etc
render() {
if ( ! this.state.files.length ) {
return <MediaPlaceholder />
}
return (
<Fragment>
{ this.props.noticeUI }
<DropZone />
<WrappedComponent files={ this.state.files } { ...this.props } />
<MediaPlaceholder title={ false } />
</Fragment>
);
}
};
}
export default withNotices( MediaContainer ); |
a6c7335
to
d8b8f3b
Compare
The code was updated, now instead of custom add item logic MediaPlaceholder handles everything (it got new additions). The gallery code and styles got simplified with this change. @kjellr The design was changed and I think your points were addressed: Hi @simison, |
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 really like the recent changes, the MediaPlaceholder
component becomes much more useful 🙌
|
||
if ( ! hasUploadPermissions && ! onSelectURL ) { | ||
instructions = __( 'To edit this block, you need permission to upload media.' ); | ||
} | ||
|
||
if ( ! instructions || ! title ) { | ||
if ( instructions === undefined || title === undefined ) { |
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 is likely to break backwards compatibility, isn't it? Folks that have been relying on the default labels will no longer get them.
An alternative would be to accept null
for these props so that folks can explicitly opt-out of the default label and instructions. It's much less likely folks are using a falsey value other than undefined
to get the defaults.
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 is likely to break backward compatibility, isn't it? Folks that have been relying on the default labels will no longer get them.
I think folks that relied on the defaults will still get them because in that case instructions or title are undefined.
What this allows is the ability to not render instructions or title by setting a null value or empty string in these fields.
There is minor behavior change previously if title/instructions were null or contained an empty string we applied default value now for this cases we don't. But I don't think someone would set the prop to a null/empty string and expect its value to contain the defaults.
onChange={ this.onUpload } | ||
accept={ accept } | ||
multiple={ multiple } | ||
> | ||
{ __( 'Upload' ) } | ||
</FormFileUpload> | ||
<MediaUpload | ||
addToGallery={ addToGallery } |
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.
Is there a use case when we'd disable addToGallery
? I'd expect folks to always need to opt-in to this behavior when using the MediaPlaceholder
.
It also seems to overlap with isAppender
, although one is for styling and the other behavior.
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.
Is there a use case when we'd disable
addToGallery
? I'd expect folks to always need to opt-in to this behavior when using theMediaPlaceholder
.
When the gallery/value was empty previously we went to the create gallery flow instead of the add to gallery one. If we default to addToGallery we would be applying a behavior change and go by default to the add flow instead of the create flow.
It also seems to overlap with
isAppender
, although one is for styling and the other behavior.
Yes, I preferred to have a flag for behavior and another one for the style. So we allow more customization.
Thank you for the review @sirreal 👍
d3d51b7
to
71db241
Compare
479a80b
to
75d9271
Compare
Hi @simison, I rebased the PR did a new set of test. I reverted the fix to hoover spacing problem -- the fix caused a bug when the gallery is in the placeholder state, and I noticed this problem is already present on master. I would prefer if we address the problem separately. @jasmussen @kjellr any thoughts regarding the current state of this PR? Any task remaining in your opinion? |
This is looking good. Just one remaining item in my opinion: We should set it so that a click anywhere on the drop zone triggers the upload modal. I do feel like we should consider changing the dropzone area as described above #12367 (comment), but that'd come with some tradeoffs, so I think it's fine to punt it for now and revisit later. 👍 |
75d9271
to
ed4859c
Compare
Hi @kjellr, this PR was updated and all the appender area is clickable. |
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.
@jorgefilipecosta This is looking great! I pushed two small changes:
- I added
cursor: pointer
to the hover state, to reinforce that the whole area is now clickable. - I reinstated the gray background to sync up with the other inserters we're adding in
Adds Block Appender as placeholder to empty InnerBlocks #14241. - EDIT: I also added 1fdb53f, which switches the hover state to use a
$white
outline color on dark themes, to align with Adds Block Appender as placeholder to empty InnerBlocks #14241.
This should be ready to go!
…; Media Upload: Allow galleries to open in the library frame.
1fdb53f
to
934a30c
Compare
To reinforce that this area is clickable.
934a30c
to
3eb3261
Compare
Fixes: #8309
Supersedes: #9682
This PR adds a media library button in the upload new image are of the gallery block.
Trying to follow the design 2 proposed in #9682 (comment) by @kjellr and approved by @karmatosed.
A new functionality that allows the gallery to open in library/add frame instead of the edit frame was added to MediaUpload, so when the user pressed the media library button in the add zone the user goes directly to the add to library section when using the edit gallery button on the toolbar the user goes to the edit gallery section.
Description
I added a gallery;
I added some images;
I selected the gallery;
I checked that a new media library button exists in the add to gallery zone.
If I click on it I go directly to a frame that allows the addition of images from the library to the gallery.
How has this been tested?
Screenshot