Skip to content

Commit 8dae211

Browse files
committed
IMprove url-filter-applier
1 parent 5151060 commit 8dae211

File tree

4 files changed

+32
-18
lines changed

4 files changed

+32
-18
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"*": {
1212
"Magento_Ui/js/grid/url-filter-applier": {
1313
"listingNamespace": "product_listing",
14-
"selectComponentName": "asset_id"
14+
"filterComponentName": "asset_id"
1515
}
1616
}
1717
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"*": {
1313
"Magento_Ui/js/grid/url-filter-applier": {
1414
"listingNamespace": "<?= $escaper->escapeJs($block->getListingNamespace()) ?>",
15-
"selectComponentName": "asset_id"
15+
"filterComponentName": "asset_id"
1616
}
1717
}
1818
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ define([
163163
getFilterUrl: function (link) {
164164
return link + '?filters[asset_id]=[' + this.image().id + ']' +
165165
'&options[]=[value=' + this.image().id +
166-
',label=' + this.image().title +
167-
',src=' + this.image()['image_url'] + ']';
166+
',label="' + this.image().title +
167+
'",src=' + this.image()['image_url'] + ']';
168168
},
169169

170170
/**

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

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ define([
1212
return Component.extend({
1313
defaults: {
1414
listingNamespace: null,
15-
selectComponentName: null,
16-
selectProvider: 'index = ${ $.selectComponentName }, ns = ${ $.listingNamespace }',
15+
filterComponentName: null,
16+
selectProvider: 'index = ${ $.filterComponentName }, ns = ${ $.listingNamespace }',
1717
filterProvider: 'componentType = filters, ns = ${ $.listingNamespace }',
1818
filterKey: 'filters',
1919
optionsKey: 'options',
@@ -44,7 +44,7 @@ define([
4444
options = this.getOptionsParam(this.searchString);
4545

4646
if (_.isUndefined(this.filterComponent()) ||
47-
!_.isNull(this.selectComponentName) && _.isUndefined(this.selectComponent())) {
47+
!_.isNull(this.filterComponentName) && _.isUndefined(this.selectComponent())) {
4848
setTimeout(function () {
4949
this.apply();
5050
}.bind(this), 100);
@@ -54,7 +54,6 @@ define([
5454

5555
if (Object.keys(options).length) {
5656
this.selectComponent().options(options);
57-
this.selectComponent().cacheOptions.plain = options;
5857
}
5958

6059
if (Object.keys(urlFilter).length) {
@@ -101,8 +100,8 @@ define([
101100
getOptionsParam: function (url) {
102101
var params = [],
103102
chunks,
104-
chunk,
105-
values = {},
103+
values,
104+
i,
106105
options,
107106
searchString = decodeURI(url);
108107

@@ -111,20 +110,35 @@ define([
111110
if (item && item.search(this.optionsKey) !== -1) {
112111
chunks = item.substring(item.indexOf('?') + 1).split('&');
113112

114-
for (var i = 0; i < chunks.length ; i++) {
115-
options = chunks[i].substring(item.indexOf('[]') + 3).replace(/[\[\]]/g, '').split(',');
116-
options.map(function (item) {
117-
chunk = item.split('=');
118-
values[chunk[0]] = chunk[1];
119-
}.bind(this));
113+
for (i = 0; i < chunks.length; i++) {
114+
options = chunks[i].substring(item.indexOf('[]') + 3)
115+
.replace(/[\[\]]/g, '')
116+
.split(/,(?=(?:(?:[^"]*"){2})*[^"]*$)/);
117+
values = this.getOptionsValues(options);
118+
120119
}
121120
params[k - 1] = values;
122-
values = {};
123121
}
124122
}.bind(this));
125123

126124
return params;
127-
}
125+
},
126+
127+
/**
128+
* Return options values as array
129+
*
130+
* @param {Array} options
131+
* @return {Array}
132+
*/
133+
getOptionsValues: function (options) {
134+
var values = {},
135+
j;
128136

137+
for (j = 0; j < options.length; j++) {
138+
values[options[j].split('=')[0]] = options[j].split('=')[1];
139+
}
140+
141+
return values;
142+
}
129143
});
130144
});

0 commit comments

Comments
 (0)