Skip to content
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

Merged
merged 17 commits into from
Aug 11, 2017
Merged

Add media upload button to Galleries #2294

merged 17 commits into from
Aug 11, 2017

Conversation

mkaz
Copy link
Member

@mkaz mkaz commented Aug 8, 2017

Abstract the media upload button being used for images to utility function and add the same upload button for Gallery block.

Closes #2131

@mkaz mkaz self-assigned this Aug 8, 2017
@mkaz mkaz added the [Status] In Progress Tracking issues with work in progress label Aug 8, 2017
@mkaz
Copy link
Member Author

mkaz commented Aug 8, 2017

@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.

@mkaz
Copy link
Member Author

mkaz commented Aug 9, 2017

[ redacted ]

See below.

@mkaz mkaz force-pushed the add/gallery-upload-button branch from 21033eb to 4388396 Compare August 10, 2017 00:02
@mkaz
Copy link
Member Author

mkaz commented Aug 10, 2017

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 value={ ids } when multiple is set, so edit works without needing all that data. Whew!
@joemcgill there shouldn't be any changes required for core for this.

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

@WordPress WordPress deleted a comment from codecov bot Aug 10, 2017
Copy link
Contributor

@youknowriad youknowriad left a 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

@@ -0,0 +1,83 @@

export function fileUpload( files, setAttributes ) {
Copy link
Contributor

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

type="image"
multiple="true"
gallery="true"
value={ images.map( ( img ) => img.id ) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍

onSelect={ onSelectImages }
type="image"
multiple="true"
gallery="true"
Copy link
Contributor

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?

Copy link
Member Author

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"
Copy link
Contributor

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

Copy link
Member Author

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 -->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome 👍

] } );
} );
} );
}
Copy link
Contributor

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.

Copy link
Member Author

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

@mkaz mkaz force-pushed the add/gallery-upload-button branch from 9c1902a to 0e2c54b Compare August 10, 2017 15:36
@mkaz mkaz removed the [Status] In Progress Tracking issues with work in progress label Aug 10, 2017
@mtias mtias added [Feature] Blocks Overall functionality of blocks [Feature] Media Anything that impacts the experience of managing media labels Aug 11, 2017
@mkaz mkaz force-pushed the add/gallery-upload-button branch from 95daed0 to 2d88d13 Compare August 11, 2017 13:47
@mkaz mkaz merged commit 6d3637f into master Aug 11, 2017
@mkaz mkaz deleted the add/gallery-upload-button branch August 11, 2017 14:12
@codecov
Copy link

codecov bot commented Aug 11, 2017

Codecov Report

Merging #2294 into master will increase coverage by 0.08%.
The diff coverage is 25.8%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
blocks/library/image/index.js 15.38% <0%> (+3.13%) ⬆️
blocks/library/gallery/gallery-image.js 50% <100%> (ø) ⬆️
utils/mediaupload.js 21.73% <21.73%> (ø)
blocks/library/gallery/index.js 33.33% <33.33%> (+8.33%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a86b79d...2d88d13. Read the comment docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Blocks Overall functionality of blocks [Feature] Media Anything that impacts the experience of managing media
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants