Skip to content

Commit 31b25a7

Browse files
authored
ENGCOM-7776: Fix Images in grid is not correctly aligned after clear filters #28366
2 parents 24e74cc + 90183a4 commit 31b25a7

File tree

4 files changed

+106
-5
lines changed

4 files changed

+106
-5
lines changed

app/code/Magento/Ui/view/base/web/js/grid/columns/image.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ define([
1111
defaults: {
1212
bodyTmpl: 'ui/grid/columns/image',
1313
modules: {
14+
masonry: '${ $.parentName }',
1415
previewComponent: '${ $.parentName }.preview'
1516
},
1617
previewRowId: null,
@@ -35,6 +36,15 @@ define([
3536
return this;
3637
},
3738

39+
/**
40+
* Updates styles when image loaded.
41+
*
42+
* @param {Object} record
43+
*/
44+
updateStyles: function (record) {
45+
!record.lastInRow || this.masonry().updateStyles();
46+
},
47+
3848
/**
3949
* Returns url to given record.
4050
*

app/code/Magento/Ui/view/base/web/js/grid/masonry.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,20 @@ define([
112112
*/
113113
setEventListener: function () {
114114
window.addEventListener('resize', function () {
115-
raf(function () {
116-
this.containerWidth = window.innerWidth;
117-
this.setLayoutStyles();
118-
}.bind(this), this.refreshFPS);
115+
this.updateStyles();
119116
}.bind(this));
120117
},
121118

119+
/**
120+
* Updates styles for component.
121+
*/
122+
updateStyles: function () {
123+
raf(function () {
124+
this.containerWidth = window.innerWidth;
125+
this.setLayoutStyles();
126+
}.bind(this), this.refreshFPS);
127+
},
128+
122129
/**
123130
* Set layout styles inside the container
124131
*/

app/code/Magento/Ui/view/base/web/templates/grid/columns/image.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
*/
66
-->
77
<div class="masonry-image-block" ko-style="$col.getStyles($row())" css="{'active': $col.getIsActive($row())}" attr="'data-id': $col.getId($row())">
8-
<img attr="src: $col.getUrl($row())" css="$col.getClasses($row())" click="function(){ expandPreview($row()) }" data-role="thumbnail"/>
8+
<img data-bind="event: { load: updateStyles($row()) }" attr="src: $col.getUrl($row())" css="$col.getClasses($row())" click="function(){ expandPreview($row()) }" data-role="thumbnail"/>
99
</div>
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
/*eslint max-nested-callbacks: 0*/
7+
define([
8+
'jquery',
9+
'ko',
10+
'Magento_Ui/js/grid/masonry'
11+
], function ($, ko, Masonry) {
12+
'use strict';
13+
14+
var Component,
15+
rows,
16+
container = '<div data-id="masonry_grid" id="masonry_grid"><div class="masonry-image-column"></div></div>';
17+
18+
beforeEach(function () {
19+
rows = [
20+
{
21+
_rowIndex: 0,
22+
category: {},
23+
'category_id': 695,
24+
'category_name': 'People',
25+
'comp_url': 'https://stock.adobe.com/Rest/Libraries/Watermarked/Download/327515738/2',
26+
'content_type': 'image/jpeg',
27+
'country_name': 'Malaysia',
28+
'creation_date': '2020-03-02 10:41:51',
29+
'creator_id': 208217780,
30+
'creator_name': 'NajmiArif',
31+
height: 3264,
32+
id: 327515738,
33+
'id_field_name': 'id',
34+
'is_downloaded': 0,
35+
'is_licensed_locally': 0,
36+
keywords: [],
37+
'media_type_id': 1,
38+
overlay: '',
39+
path: '',
40+
'premium_level_id': 0,
41+
'thumbnail_240_url': 'https://t4.ftcdn.net/jpg/03/27/51/57/240_F_327515738_n.jpg',
42+
'thumbnail_500_ur': 'https://as2.ftcdn.net/jpg/03/27/51/57/500_F_327515738_n.jpg',
43+
title: 'Neon effect picture of man wearing medical mask for viral or pandemic disease',
44+
width: 4896
45+
}
46+
47+
];
48+
49+
$(container).appendTo('body');
50+
51+
Component = new Masonry({
52+
defaults: {
53+
rows: ko.observable()
54+
}
55+
});
56+
57+
});
58+
59+
afterEach(function () {
60+
$('#masonry_grid').remove();
61+
});
62+
63+
describe('check initComponent', function () {
64+
it('verify setLayoutstyles called and grid iniztilized', function () {
65+
var setlayoutStyles = spyOn(Component, 'setLayoutStyles');
66+
67+
expect(Component).toBeDefined();
68+
Component.containerId = 'masonry_grid';
69+
Component.initComponent(rows);
70+
Component.rows().forEach(function (image) {
71+
expect(image.styles).toBeDefined();
72+
expect(image.css).toBeDefined();
73+
});
74+
expect(setlayoutStyles).toHaveBeenCalled();
75+
});
76+
it('verify events triggered', function () {
77+
var setLayoutStyles = spyOn(Component, 'setLayoutStyles');
78+
79+
Component.initComponent(rows);
80+
window.dispatchEvent(new Event('resize'));
81+
expect(setLayoutStyles).toHaveBeenCalled();
82+
});
83+
});
84+
});

0 commit comments

Comments
 (0)