Skip to content

Added masonry grid and columns components #25464

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

Merged
merged 12 commits into from
Nov 8, 2019
Merged

Added masonry grid and columns components #25464

merged 12 commits into from
Nov 8, 2019

Conversation

sivaschenko
Copy link
Member

Added masonry grid and columns components developed in the scope of Adobe Stock Integation project

Description (*)

Masonry grid and columns components allow creating images listings:

image

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

@m2-assistant
Copy link

m2-assistant bot commented Nov 4, 2019

Hi @sivaschenko. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.3-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Guide documentation.

@sivaschenko sivaschenko added the Auto-Tests: Not Required Changes in Pull Request does not require coverage by auto-tests label Nov 4, 2019
setTimeout(function () {
handler();
running = false;
}, 66);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why 66?

Copy link
Member Author

Choose a reason for hiding this comment

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

That is the optimal number for the timeout :) Any suggestions?

Copy link
Contributor

@omiroshnichenko omiroshnichenko Nov 4, 2019

Choose a reason for hiding this comment

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

1000 / 60 to achieve 60fps ;)

Copy link
Contributor

Choose a reason for hiding this comment

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

^^you missed this comment

Copy link

Choose a reason for hiding this comment

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

Might make more sense to just use the polyfill/fallback we have in place here. At least that way we're not inlining these fallbacks everytime we need to use rAF

Copy link
Contributor

Choose a reason for hiding this comment

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

I completely forgot that we have this.

Copy link
Member Author

Choose a reason for hiding this comment

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

@DrewML @omiroshnichenko can you please clarify what would you like to see here

Copy link
Member Author

Choose a reason for hiding this comment

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

Added raf

/**
* Set layout styles when container element is loaded.
*/
setLayoutStylesWhenLoaded: function () {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see place where this function has been called. Should it be removed?

Copy link
Member Author

Choose a reason for hiding this comment

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

This function can be used when loading the masonry grid on a slide panel. For example: https://github.com/magento/adobe-stock-integration/blob/develop/AdobeStockImageAdminUi/view/adminhtml/web/panel.js

<button class="action-next" type="button" data-bind="click: function () { $col.next($row()); }">
<span translate="'Next'"/>
</button>
<button class="action-close" type="button" data-bind="click: function () { $col.hide(); }">
Copy link
Contributor

Choose a reason for hiding this comment

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

Replace data-bind with click attribute

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

* Set min ratio for images in layout
*/
setMinRatio: function () {
if (this.containerWidth <= 640) {
Copy link
Contributor

@omiroshnichenko omiroshnichenko Nov 4, 2019

Choose a reason for hiding this comment

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

Better to move these values as a part of the component configuration in defaults

Copy link
Member Author

Choose a reason for hiding this comment

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

Moved

/**
* Wait for container to initialize
*/
waitForContainer: function (callback) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Related to comment below

@sivaschenko
Copy link
Member Author

Hi @omiroshnichenko thank you for the review! I have applied all the required fixes and/or responded to the comments. Can you please very the code review changes

*/
setLayoutStyles: function () {
var containerWidth = parseInt(this.container.clientWidth, 10),
rowImages = [],
Copy link

@DrewML DrewML Nov 5, 2019

Choose a reason for hiding this comment

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

The combination of an empty array above (rowImages) and a forEach below can be a good indication that map is better suited for the job. Would recommend switching over

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 don't think map can be used for this algorithm, rowImages is a temporary array containing images that should be in a single visual row on the screen. This array is flushed and recreated several times (= number of images rows) during the foreach execution. this.rows().foreach iterating over each data row (each image in this case)

* Set min ratio for images in layout
*/
setMinRatio: function () {
var minRatio = null;
Copy link

Choose a reason for hiding this comment

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

Seems like this placeholder var isn't needed, if we're just going to assign to this.minRatio anyway in the bottom of the function

Copy link
Member Author

Choose a reason for hiding this comment

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

This variable is needed for the condition in the bottom:
this.minRatio = minRatio ? minRatio : this.defaultMinRatio;
see updated code

@DrewML
Copy link

DrewML commented Nov 5, 2019

General question about the technical design of this feature: what's the reasoning for doing all the calculations in JavaScript and resizing, rather than using a mostly CSS approach? Were there constraints due to browser support, or something else?

@sivaschenko
Copy link
Member Author

@DrewML we were not able to find a responsible and flexible solution in plain CSS

@sivaschenko
Copy link
Member Author

Thanks for the reviews @omiroshnichenko and @DrewML .

The suggested improvements have been applied. Please review.

@magento-engcom-team
Copy link
Contributor

Hi @VladimirZaets, thank you for the review.
ENGCOM-6244 has been created to process this Pull Request

@magento-engcom-team magento-engcom-team merged commit 6023ac7 into magento:2.3-develop Nov 8, 2019
@m2-assistant
Copy link

m2-assistant bot commented Nov 8, 2019

Hi @sivaschenko, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

@VladimirZaets
Copy link
Contributor

These components use by Adobe Stock project and covered by functional tests.

@VladimirZaets VladimirZaets added Auto-Tests: Covered All changes in Pull Request is covered by auto-tests and removed Auto-Tests: Not Required Changes in Pull Request does not require coverage by auto-tests labels Nov 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants