Skip to content

Commit 42bbe58

Browse files
committed
IMprove url filter applier to catch multiselect filters options
1 parent 5a717c7 commit 42bbe58

File tree

6 files changed

+56
-9
lines changed

6 files changed

+56
-9
lines changed

app/code/Magento/Catalog/view/adminhtml/templates/product/grid/url_filter_applier.phtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
{
1111
"*": {
1212
"Magento_Ui/js/grid/url-filter-applier": {
13-
"listingNamespace": "product_listing"
13+
"listingNamespace": "product_listing",
14+
"selectComponentName": "asset_id"
1415
}
1516
}
1617
}

app/code/Magento/Cms/view/adminhtml/templates/url_filter_applier.phtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
{
1212
"*": {
1313
"Magento_Ui/js/grid/url-filter-applier": {
14-
"listingNamespace": "<?= $escaper->escapeJs($block->getListingNamespace()) ?>"
14+
"listingNamespace": "<?= $escaper->escapeJs($block->getListingNamespace()) ?>",
15+
"selectComponentName": "asset_id"
1516
}
1617
}
1718
}

app/code/Magento/MediaGalleryCmsUi/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"php": "~7.3.0||~7.4.0",
66
"magento/framework": "*",
77
"magento/module-cms": "*",
8-
"magento/module-backend": "*"
8+
"magento/module-backend": "*",
9+
"magento/module-ui": "*"
910
},
1011
"type": "magento2-module",
1112
"license": [

app/code/Magento/MediaGalleryUi/view/adminhtml/web/css/source/_module.less

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
}
3030
}
3131

32-
.media-gallery-asset-ui-select-filter, .edit-image-details {
32+
.media-gallery-asset-ui-select-filter,
33+
.edit-image-details {
3334

3435
.admin__action-multiselect-crumb {
3536
max-width: 70%;
@@ -49,7 +50,8 @@
4950
}
5051
}
5152

52-
.media-gallery-asset-ui-select-filter, .edit-image-details {
53+
.media-gallery-asset-ui-select-filter,
54+
.edit-image-details {
5355
.admin__action-multiselect-item-path {
5456
float: right;
5557
max-height: 70px;
@@ -418,11 +420,13 @@
418420
}
419421

420422
.value {
423+
margin-left: 1px;
421424
display: inline;
422425
float: right;
423426
}
424427

425428
.title {
429+
height: 100px
426430
color: @color-very-dark-gray;
427431
}
428432
}

app/code/Magento/MediaGalleryUi/view/adminhtml/web/js/image/image-details.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,10 @@ define([
161161
* @param {String} link
162162
*/
163163
getFilterUrl: function (link) {
164-
return link + '?filters[asset_id]=[' + this.image().id + ']';
164+
return link + '?filters[asset_id]=[' + this.image().id + ']' +
165+
'&value=' + this.image().id +
166+
'&label=' + this.image().title +
167+
'&src=' + this.image()['image_url'];
165168
},
166169

167170
/**

app/code/Magento/Ui/view/base/web/js/grid/url-filter-applier.js

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@ define([
1212
return Component.extend({
1313
defaults: {
1414
listingNamespace: null,
15+
selectComponentName: null,
16+
selectProvider: 'index = ${ $.selectComponentName }, ns = ${ $.listingNamespace }',
1517
filterProvider: 'componentType = filters, ns = ${ $.listingNamespace }',
1618
filterKey: 'filters',
19+
optionsKey: 'options',
1720
searchString: location.search,
1821
modules: {
19-
filterComponent: '${ $.filterProvider }'
22+
filterComponent: '${ $.filterProvider }',
23+
selectComponent: '${ $.selectProvider }'
2024
}
2125
},
2226

@@ -36,16 +40,23 @@ define([
3640
* Apply filter
3741
*/
3842
apply: function () {
39-
var urlFilter = this.getFilterParam(this.searchString);
43+
var urlFilter = this.getFilterParam(this.searchString),
44+
options = this.getOptionsParam(this.searchString);
4045

41-
if (_.isUndefined(this.filterComponent())) {
46+
if (_.isUndefined(this.filterComponent()) ||
47+
!_.isNull(this.selectComponentName) && _.isUndefined(this.selectComponent())) {
4248
setTimeout(function () {
4349
this.apply();
4450
}.bind(this), 100);
4551

4652
return;
4753
}
4854

55+
if (Object.keys(options).length) {
56+
this.selectComponent().options(options);
57+
this.selectComponent().cacheOptions.plain = [options];
58+
}
59+
4960
if (Object.keys(urlFilter).length) {
5061
this.filterComponent().setData(urlFilter, false);
5162
this.filterComponent().apply();
@@ -63,12 +74,14 @@ define([
6374

6475
return _.chain(searchString.slice(1).split('&'))
6576
.map(function (item) {
77+
6678
if (item && item.search(this.filterKey) !== -1) {
6779
itemArray = item.split('=');
6880

6981
if (itemArray[1].search('\\[') === 0) {
7082
itemArray[1] = itemArray[1].replace(/[\[\]]/g, '').split(',');
7183
}
84+
7285
itemArray[0] = itemArray[0].replace(this.filterKey, '')
7386
.replace(/[\[\]]/g, '');
7487

@@ -78,6 +91,30 @@ define([
7891
.compact()
7992
.object()
8093
.value();
94+
},
95+
96+
/**
97+
* Get Filter options
98+
*
99+
* @param {String} url
100+
*/
101+
getOptionsParam: function (url) {
102+
var searchString = decodeURI(url),
103+
options;
104+
options = Object.fromEntries(new URLSearchParams(searchString));
105+
delete options['filters[asset_id]'];
106+
107+
return options;
108+
},
109+
110+
/**
111+
* Set select component options
112+
*
113+
* @param {Array} options
114+
*/
115+
setOptions: function (options) {
116+
this.selectComponent().options(options);
117+
81118
}
82119
});
83120
});

0 commit comments

Comments
 (0)