Skip to content

Commit 5c463dc

Browse files
committed
Move fixes for url-filter component to separate PR
1 parent 71275cb commit 5c463dc

File tree

7 files changed

+12
-103
lines changed

7 files changed

+12
-103
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
{
1111
"*": {
1212
"Magento_Ui/js/grid/url-filter-applier": {
13-
"listingNamespace": "product_listing",
14-
"filterComponentName": "asset_id"
13+
"listingNamespace": "product_listing"
1514
}
1615
}
1716
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
{
1212
"*": {
1313
"Magento_Ui/js/grid/url-filter-applier": {
14-
"listingNamespace": "<?= $escaper->escapeJs($block->getListingNamespace()) ?>",
15-
"filterComponentName": "asset_id"
14+
"listingNamespace": "<?= $escaper->escapeJs($block->getListingNamespace()) ?>"
1615
}
1716
}
1817
}

app/code/Magento/MediaGalleryUi/Controller/Adminhtml/Asset/Search.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ public function execute()
137137
if (!empty($assets)) {
138138
foreach ($assets as $asset) {
139139
$responseContent['options'][] = [
140-
'value' => (string) $asset->getId(),
140+
'value' => $asset->getId(),
141141
'label' => $asset->getTitle(),
142-
'src' => $this->storage->getThumbnailUrl($this->images->getStorageRoot() . $asset->getPath())
142+
'path' => $this->storage->getThumbnailUrl($this->images->getStorageRoot() . $asset->getPath())
143143
];
144144
$responseContent['total'] = count($responseContent['options']);
145145
}

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

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

170167
/**

app/code/Magento/MediaGalleryUi/view/adminhtml/web/template/grid/filters/elements/ui-select.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,9 @@
108108
</if>
109109
<label class="admin__action-multiselect-label">
110110
<span text="option.label"></span>
111-
<img class="admin__action-multiselect-item-path"
112-
attr="{ src: option.src }"/>
111+
<img if="$parent.getPath(option)"
112+
class="admin__action-multiselect-item-path"
113+
attr="{ src: option.path }"/>
113114
</label>
114115
</div>
115116
<if args="$data.optgroup">

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

Lines changed: 3 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,11 @@ define([
1212
return Component.extend({
1313
defaults: {
1414
listingNamespace: null,
15-
filterComponentName: null,
16-
selectProvider: 'index = ${ $.filterComponentName }, ns = ${ $.listingNamespace }',
1715
filterProvider: 'componentType = filters, ns = ${ $.listingNamespace }',
1816
filterKey: 'filters',
19-
optionsKey: 'options',
2017
searchString: location.search,
2118
modules: {
22-
filterComponent: '${ $.filterProvider }',
23-
selectComponent: '${ $.selectProvider }'
19+
filterComponent: '${ $.filterProvider }'
2420
}
2521
},
2622

@@ -40,22 +36,16 @@ define([
4036
* Apply filter
4137
*/
4238
apply: function () {
43-
var urlFilter = this.getFilterParam(this.searchString),
44-
options = this.getOptionsParam(this.searchString);
39+
var urlFilter = this.getFilterParam(this.searchString);
4540

46-
if (_.isUndefined(this.filterComponent()) ||
47-
!_.isNull(this.filterComponentName) && _.isUndefined(this.selectComponent())) {
41+
if (_.isUndefined(this.filterComponent())) {
4842
setTimeout(function () {
4943
this.apply();
5044
}.bind(this), 100);
5145

5246
return;
5347
}
5448

55-
if (Object.keys(options).length) {
56-
this.selectComponent().options(options);
57-
}
58-
5949
if (Object.keys(urlFilter).length) {
6050
this.filterComponent().setData(urlFilter, false);
6151
this.filterComponent().apply();
@@ -90,55 +80,6 @@ define([
9080
.compact()
9181
.object()
9282
.value();
93-
},
94-
95-
/**
96-
* Get Filter options
97-
*
98-
* @param {String} url
99-
*/
100-
getOptionsParam: function (url) {
101-
var params = [],
102-
chunks,
103-
values,
104-
i,
105-
options,
106-
searchString = decodeURI(url);
107-
108-
_.chain(searchString.slice(1).split('&'))
109-
.map(function (item, k) {
110-
if (item && item.search(this.optionsKey) !== -1) {
111-
chunks = item.substring(item.indexOf('?') + 1).split('&');
112-
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-
119-
}
120-
params[k - 1] = values;
121-
}
122-
}.bind(this));
123-
124-
return params;
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;
136-
137-
for (j = 0; j < options.length; j++) {
138-
values[options[j].split('=')[0]] = options[j].split('=')[1];
139-
}
140-
141-
return values;
14283
}
14384
});
14485
});

dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/grid/url-filter-applier.test.js

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,11 @@ define([
1414
filterComponentMock = {
1515
setData: jasmine.createSpy(),
1616
apply: jasmine.createSpy()
17-
},
18-
selectComponentMock = {
19-
options: jasmine.createSpy()
2017
};
2118

2219
beforeEach(function () {
2320
urlFilterApplierObj = new UrlFilterApplier({});
2421
urlFilterApplierObj.filterComponent = jasmine.createSpy().and.returnValue(filterComponentMock);
25-
urlFilterApplierObj.selectComponent = jasmine.createSpy().and.returnValue(selectComponentMock);
2622
});
2723

2824
describe('"getFilterParam" method', function () {
@@ -57,21 +53,6 @@ define([
5753
'qty': '1'
5854
});
5955
});
60-
it('return object from url with multiple options for select filters', function () {
61-
var urlSearch = '?filters[name]=[27,23]&options[]=[value=27,' +
62-
'label=Label]&options[]=[value=23,label=Label2]&filters[qty]=1&anotherparam=1';
63-
64-
expect(urlFilterApplierObj.getOptionsParam(urlSearch)).toEqual([
65-
{
66-
value: '27',
67-
label: 'Label'
68-
},
69-
{
70-
value: '23',
71-
label: 'Label2'
72-
}
73-
]);
74-
});
7556
it('return object from url with another parameter', function () {
7657
var urlSearch = '?anotherparam=1';
7758

@@ -81,21 +62,12 @@ define([
8162

8263
describe('"apply" method', function () {
8364
it('applies url filter on filter component', function () {
84-
urlFilterApplierObj.searchString = '?filters[name]=test' +
85-
'&options[]=[value=23,label=Label]&filters[qty]=1';
65+
urlFilterApplierObj.searchString = '?filters[name]=test&filters[qty]=1';
8666
urlFilterApplierObj.apply();
8767
expect(urlFilterApplierObj.filterComponent().setData).toHaveBeenCalledWith({
8868
'name': 'test',
8969
'qty': '1'
9070
}, false);
91-
expect(urlFilterApplierObj.selectComponent().options).toHaveBeenCalledWith(
92-
[
93-
{
94-
value: '23',
95-
label: 'Label'
96-
}
97-
]
98-
);
9971
expect(urlFilterApplierObj.filterComponent().apply).toHaveBeenCalled();
10072
});
10173
});

0 commit comments

Comments
 (0)