Skip to content

Commit be428f7

Browse files
author
Gabriel Galvao da Gama
committed
Added url filter applier
1 parent ba25897 commit be428f7

File tree

8 files changed

+123
-0
lines changed

8 files changed

+123
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Ui\Component;
9+
10+
/**
11+
* UrlFilterApplier component
12+
*/
13+
class UrlFilterApplier extends AbstractComponent
14+
{
15+
const NAME = 'urlFilterApplier';
16+
17+
/**
18+
* @inheritdoc
19+
*/
20+
public function prepare(): void
21+
{
22+
parent::prepare();
23+
$filters = is_array($this->getContext()->getRequestParam('filters')) ?
24+
$this->getContext()->getRequestParam('filters') : null;
25+
26+
$this->setData(
27+
'config',
28+
array_replace_recursive(
29+
(array)$this->getData('config'),
30+
[
31+
'filters' => $filters,
32+
]
33+
)
34+
);
35+
}
36+
37+
/**
38+
* @inheritdoc
39+
*/
40+
public function getComponentName()
41+
{
42+
return static::NAME;
43+
}
44+
}

app/code/Magento/Ui/etc/ui_components.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,5 @@
6262
<xs:include schemaLocation="urn:magento:module:Magento_Ui:view/base/ui_component/etc/definition/exportButton.xsd"/>
6363
<xs:include schemaLocation="urn:magento:module:Magento_Ui:view/base/ui_component/etc/definition/listingToolbar.xsd"/>
6464
<xs:include schemaLocation="urn:magento:module:Magento_Ui:view/base/ui_component/etc/definition/dataProvider.xsd"/>
65+
<xs:include schemaLocation="urn:magento:module:Magento_Ui:view/base/ui_component/etc/definition/urlFilterApplier.xsd"/>
6566
</xs:schema>

app/code/Magento/Ui/etc/ui_configuration.xsd

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
<xs:element ref="text" maxOccurs="unbounded"/>
108108
<xs:element ref="textarea" maxOccurs="unbounded"/>
109109
<xs:element ref="wysiwyg" maxOccurs="unbounded"/>
110+
<xs:element ref="urlFilterApplier" maxOccurs="unbounded" />
110111
</xs:choice>
111112
</xs:group>
112113
<xs:group name="fieldsetElements">
@@ -206,6 +207,7 @@
206207
<xs:element ref="text" maxOccurs="unbounded"/>
207208
<xs:element ref="textarea" maxOccurs="unbounded"/>
208209
<xs:element ref="wysiwyg" maxOccurs="unbounded"/>
210+
<xs:element ref="urlFilterApplier" maxOccurs="unbounded" />
209211
</xs:choice>
210212
</xs:group>
211213

@@ -824,4 +826,12 @@
824826
</xs:documentation>
825827
</xs:annotation>
826828
</xs:element>
829+
<xs:element name="urlFilterApplier" type="componentUrlFilterApplier">
830+
<xs:annotation>
831+
<xs:documentation>
832+
The Url Filter Applier component retrieves the values from the "filters" GET parameter and applies it
833+
to the grid.
834+
</xs:documentation>
835+
</xs:annotation>
836+
</xs:element>
827837
</xs:schema>

app/code/Magento/Ui/etc/ui_definition.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
<xs:element name="wysiwyg" type="componentWysiwyg"/>
7878
<xs:element name="inlineEditing" type="componentInlineEditing"/>
7979
<xs:element name="urlInput" type="componentUrlInput"/>
80+
<xs:element name="urlFilterApplier" type="componentUrlFilterApplier" />
8081
</xs:choice>
8182
</xs:complexType>
8283
</xs:schema>

app/code/Magento/Ui/view/base/ui_component/etc/definition.map.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@
499499
</argument>
500500
</schema>
501501
</component>
502+
<component name="urlFilterApplier" include="uiElementSettings"/>
502503
<component name="filterSearch" include="uiElementSettings">
503504
<schema name="current">
504505
<argument name="data" xsi:type="array">

app/code/Magento/Ui/view/base/ui_component/etc/definition.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,4 +284,5 @@
284284
</dynamicRows>
285285
<htmlContent class="Magento\Ui\Component\HtmlContent" component="Magento_Ui/js/form/components/html"/>
286286
<button class="Magento\Ui\Component\Container" component="Magento_Ui/js/form/components/button"/>
287+
<urlFilterApplier class="Magento\Ui\Component\UrlFilterApplier" component="Magento_Ui/js/grid/url-filter-applier" />
287288
</components>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
9+
<!-- Include section -->
10+
<xs:include schemaLocation="urn:magento:module:Magento_Ui:view/base/ui_component/etc/definition/ui_component.xsd"/>
11+
12+
<xs:complexType name="componentUrlFilterApplier">
13+
<xs:sequence>
14+
<xs:group ref="configurable" minOccurs="0" maxOccurs="unbounded"/>
15+
</xs:sequence>
16+
<xs:attributeGroup ref="ui_element_attributes"/>
17+
</xs:complexType>
18+
</xs:schema>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define([
7+
'uiComponent',
8+
'underscore',
9+
], function (Component, _) {
10+
'use strict';
11+
12+
return Component.extend({
13+
defaults: {
14+
filterProvider: 'componentType = filters, ns = ${ $.ns }',
15+
filters: null,
16+
modules: {
17+
filterComponent: '${ $.filterProvider }',
18+
}
19+
},
20+
21+
/**
22+
* Init component
23+
*
24+
* @return {exports}
25+
*/
26+
initialize: function () {
27+
this._super();
28+
this.apply();
29+
30+
return this;
31+
},
32+
33+
/**
34+
* Apply filter
35+
*/
36+
apply: function () {
37+
if (_.isUndefined(this.filterComponent())) {
38+
setTimeout(function () {this.apply()}.bind(this), 100);
39+
} else {
40+
if (!_.isNull(this.filters)) {
41+
this.filterComponent().setData(this.filters, false);
42+
this.filterComponent().apply();
43+
}
44+
}
45+
}
46+
});
47+
});

0 commit comments

Comments
 (0)