-
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
Add media upload button to Galleries #2294
Conversation
@youknowriad - I committed a checkpoint for the upload button abstracted out to confirm it looks ok. I figured in the utils section made the most sense. I'm working on the multiple upload now. |
See below. |
21033eb
to
4388396
Compare
I think I might of solved a couple of issues with this one now, previous open questions are no longer relevant, sorry for the pings. The latest update switches out the edit to use the MediaUploadButton which was updated to support This PR will also close #1986 The test data needs to be updated which is why the build is failing, I'll update that shortly |
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.
Left some notes, but this PR is huge improvement for the gallery block
utils/fileupload.js
Outdated
@@ -0,0 +1,83 @@ | |||
|
|||
export function fileUpload( files, setAttributes ) { |
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.
Can we add some JSDocs to these two functions?
I wonder if we can test them too, maybe by mocking wp.api.models
, I understand it's not straightforward tough
blocks/library/gallery/index.js
Outdated
type="image" | ||
multiple="true" | ||
gallery="true" | ||
value={ images.map( ( img ) => img.id ) } |
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.
Nice 👍
blocks/library/gallery/index.js
Outdated
onSelect={ onSelectImages } | ||
type="image" | ||
multiple="true" | ||
gallery="true" |
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.
Can't we avoid the ="true"
for these two props: multiple and gallery, seems like boolean props to me?
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.
👍
className="wp-block-image__upload-button" | ||
onChange={ uploadFromFiles } | ||
accept="image/*" | ||
multiple="true" |
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.
same here multiple
should be enough
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.
👍
@@ -1,4 +1,4 @@ | |||
<!-- wp:core/gallery {"images":[{"sizes":{"full":{"url":"https://cldup.com/uuUqE_dXzy.jpg","height":1080,"width":810,"orientation":"portrait"}},"mime":"image/jpeg","type":"image","subtype":"jpeg","id":1,"url":"https://cldup.com/uuUqE_dXzy.jpg","alt":"title"},{"sizes":{"full":{"url":"http://google.com/hi.png","height":1080,"width":1440,"orientation":"landscape"}},"mime":"image/jpeg","type":"image","subtype":"jpeg","id":2,"url":"http://google.com/hi.png","alt":"title"}]} --> | |||
<!-- wp:core/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.
Awesome 👍
utils/fileupload.js
Outdated
] } ); | ||
} ); | ||
} ); | ||
} |
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.
Could we rename these functions and the inner variables mediaUpload
and media
instead of fileUpload
and img
? I'm assuming these are generic functions to upload any media.
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 refactored so image and gallery block use the same function, renamed variables and added some comments so hopefully is a bit cleaner
9c1902a
to
0e2c54b
Compare
95daed0
to
2d88d13
Compare
Codecov Report
@@ Coverage Diff @@
## master #2294 +/- ##
==========================================
+ Coverage 25.74% 25.82% +0.08%
==========================================
Files 155 156 +1
Lines 4821 4829 +8
Branches 812 815 +3
==========================================
+ Hits 1241 1247 +6
Misses 3024 3024
- Partials 556 558 +2
Continue to review full report at Codecov.
|
Abstract the media upload button being used for images to utility function and add the same upload button for Gallery block.
Closes #2131