Skip to content

Commit 0e5eaaf

Browse files
committed
#25464: Applied code review suggestions
1 parent c3f8623 commit 0e5eaaf

File tree

3 files changed

+30
-25
lines changed

3 files changed

+30
-25
lines changed

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
* See COPYING.txt for license details.
44
*/
55
define([
6-
'underscore',
76
'jquery',
87
'Magento_Ui/js/grid/columns/column'
9-
], function (_, $, Column) {
8+
], function ($, Column) {
109
'use strict';
1110

1211
return Column.extend({
1312
defaults: {
1413
previewImageSelector: '[data-image-preview]',
15-
visibile: null,
14+
visibleRecord: null,
1615
height: 0,
1716
displayedRecord: {},
1817
lastOpenedImage: null,
@@ -21,7 +20,7 @@ define([
2120
thumbnailComponent: '${ $.parentName }.thumbnail_url'
2221
},
2322
statefull: {
24-
visible: true,
23+
visibleRecord: true,
2524
sorting: true,
2625
lastOpenedImage: true
2726
},
@@ -41,7 +40,7 @@ define([
4140
initObservable: function () {
4241
this._super()
4342
.observe([
44-
'visibile',
43+
'visibleRecord',
4544
'height',
4645
'displayedRecord',
4746
'lastOpenedImage'
@@ -106,7 +105,7 @@ define([
106105
this.hide();
107106
this.displayedRecord(record);
108107
this._selectRow(record.rowNumber || null);
109-
this.visibile(record._rowIndex);
108+
this.visibleRecord(record._rowIndex);
110109

111110
img = $(this.previewImageSelector + ' img');
112111

@@ -135,7 +134,7 @@ define([
135134
*/
136135
hide: function () {
137136
this.lastOpenedImage(null);
138-
this.visibile(null);
137+
this.visibleRecord(null);
139138
this.height(0);
140139
this._selectRow(null);
141140
},
@@ -148,12 +147,12 @@ define([
148147
*/
149148
isVisible: function (record) {
150149
if (this.lastOpenedImage() === record._rowIndex &&
151-
this.visibile() === null
150+
this.visibleRecord() === null
152151
) {
153152
this.show(record);
154153
}
155154

156-
return this.visibile() === record._rowIndex || false;
155+
return this.visibleRecord() === record._rowIndex || false;
157156
},
158157

159158
/**

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

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
define([
66
'Magento_Ui/js/grid/listing',
77
'jquery',
8-
'ko'
9-
], function (Listing, $, ko) {
8+
'ko',
9+
'underscore'
10+
], function (Listing, $, ko, _) {
1011
'use strict';
1112

1213
return Listing.extend({
@@ -88,7 +89,7 @@ define([
8889
* @return {Object}
8990
*/
9091
initComponent: function (rows) {
91-
if (!rows || !rows.length) {
92+
if (!rows.length) {
9293
return;
9394
}
9495
this.imageMargin = parseInt(this.imageMargin, 10);
@@ -199,7 +200,7 @@ define([
199200
this.waitForContainer(callback);
200201
}.bind(this), 500);
201202
} else {
202-
callback();
203+
setTimeout(callback, 0);
203204
}
204205
},
205206

@@ -246,15 +247,20 @@ define([
246247
* Set min ratio for images in layout
247248
*/
248249
setMinRatio: function () {
249-
var minRatio = null;
250-
251-
for (var width in this.containerWidthToMinRatio) {
252-
if (this.containerWidthToMinRatio.hasOwnProperty(width) &&
253-
this.containerWidth <= width
254-
) {
255-
minRatio = this.containerWidthToMinRatio[width]
256-
}
257-
}
250+
var minRatio = _.find(
251+
this.containerWidthToMinRatio,
252+
/**
253+
* Find the minimal ratio for container width in the matrix
254+
*
255+
* @param {Number} ratio
256+
* @param {Number} width
257+
* @returns {Boolean}
258+
*/
259+
function (ratio, width) {
260+
return this.containerWidth <= width;
261+
},
262+
this
263+
);
258264

259265
this.minRatio = minRatio ? minRatio : this.defaultMinRatio;
260266
},

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
<div class="masonry-image-preview" if="$col.isVisible($row())" data-image-preview ko-style="$col.getStyles($row())">
88
<div class="container">
99
<div class="action-buttons">
10-
<button class="action-previous" type="button" click="function () { $col.prev($row()); }">
10+
<button class="action-previous" type="button" click="$col.prev.bind($col, $row())">
1111
<span translate="'Previous'"/>
1212
</button>
13-
<button class="action-next" type="button" click="function () { $col.next($row()); }">
13+
<button class="action-next" type="button" click="$col.next.bind($col, $row())">
1414
<span translate="'Next'"/>
1515
</button>
16-
<button class="action-close" type="button" click="function () { $col.hide(); }">
16+
<button class="action-close" type="button" click="$col.hide.bind($col)">
1717
<span translate="'Close'"/>
1818
</button>
1919
</div>

0 commit comments

Comments
 (0)