-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Added masonry grid and columns components #25464
Conversation
Hi @sivaschenko. Thank you for your contribution
For more details, please, review the Magento Contributor Guide documentation. |
app/code/Magento/Ui/view/base/web/js/grid/columns/image-preview.js
Outdated
Show resolved
Hide resolved
setTimeout(function () { | ||
handler(); | ||
running = false; | ||
}, 66); |
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.
Why 66?
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.
That is the optimal number for the timeout :) Any suggestions?
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.
1000 / 60 to achieve 60fps ;)
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.
^^you missed this comment
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.
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
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 completely forgot that we have this.
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.
@DrewML @omiroshnichenko can you please clarify what would you like to see here
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.
Added raf
/** | ||
* Set layout styles when container element is loaded. | ||
*/ | ||
setLayoutStylesWhenLoaded: function () { |
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 don't see place where this function has been called. Should it be removed?
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 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
app/code/Magento/Ui/view/base/web/templates/grid/columns/image-preview.html
Outdated
Show resolved
Hide resolved
app/code/Magento/Ui/view/base/web/templates/grid/columns/image-preview.html
Outdated
Show resolved
Hide resolved
<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(); }"> |
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.
Replace data-bind
with click
attribute
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.
Fixed
* Set min ratio for images in layout | ||
*/ | ||
setMinRatio: function () { | ||
if (this.containerWidth <= 640) { |
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.
Better to move these values as a part of the component configuration in 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.
Moved
/** | ||
* Wait for container to initialize | ||
*/ | ||
waitForContainer: function (callback) { |
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.
Related to comment below
app/code/Magento/Ui/view/base/web/js/grid/columns/image-preview.js
Outdated
Show resolved
Hide resolved
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 = [], |
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 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
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 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; |
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.
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
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 variable is needed for the condition in the bottom:
this.minRatio = minRatio ? minRatio : this.defaultMinRatio;
see updated code
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? |
@DrewML we were not able to find a responsible and flexible solution in plain CSS |
Thanks for the reviews @omiroshnichenko and @DrewML . The suggested improvements have been applied. Please review. |
Hi @VladimirZaets, thank you for the review. |
Hi @sivaschenko, thank you for your contribution! |
These components use by Adobe Stock project and covered by functional tests. |
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:
Contribution checklist (*)