Skip to content

Commit 0f42e07

Browse files
committed
magento#238: Don't trigger grid reload at first page load
Signed-off-by: Denis Kopylov <[email protected]>
1 parent f26ae80 commit 0f42e07

File tree

32 files changed

+945
-265
lines changed

32 files changed

+945
-265
lines changed

app/code/Magento/Catalog/Test/Mftf/Test/AdminMassUpdateProductStatusStoreViewScopeTest/AdminMassUpdateProductStatusStoreViewScopeTest.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
* See COPYING.txt for license details.
66
*/
77
-->
8-
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9-
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
8+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
109
<test name="AdminMassUpdateProductStatusStoreViewScopeTest">
1110
<annotations>
1211
<features value="Catalog"/>
@@ -140,5 +139,5 @@
140139
</actionGroup>
141140
<actionGroup ref="StorefrontCheckAdvancedSearchResultActionGroup" stepKey="StorefrontCheckAdvancedSearchResultDefault2"/>
142141
<see userInput="We can't find any items matching these search criteria." selector="{{StorefrontCatalogSearchAdvancedResultMainSection.message}}" stepKey="seeInDefault2"/>
143-
</test>
142+
</test>
144143
</tests>

app/code/Magento/Customer/etc/adminhtml/di.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
9-
<preference for="Magento\Customer\Model\Customer" type="Magento\Customer\Model\Backend\Customer" />
9+
<preference for="Magento\Customer\Model\Customer" type="Magento\Customer\Model\Backend\Customer"/>
1010
<type name="Magento\Customer\Model\ResourceModel\Customer\Collection">
1111
<arguments>
1212
<argument name="modelName" xsi:type="string">Magento\Customer\Model\Backend\Customer</argument>
1313
</arguments>
1414
</type>
15-
<preference for="Magento\Framework\Session\SessionManagerInterface" type="Magento\Backend\Model\Session" />
15+
<preference for="Magento\Framework\Session\SessionManagerInterface" type="Magento\Backend\Model\Session"/>
1616
<type name="Magento\Ui\Model\Export\MetadataProvider">
1717
<arguments>
1818
<argument name="data" xsi:type="array">

app/code/Magento/Customer/view/adminhtml/ui_component/customer_address_listing.xml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,9 @@
3838
<listingToolbar name="listing_top">
3939
<bookmark name="bookmarks"/>
4040
<columnsControls name="columns_controls"/>
41-
<filterSearch name="fulltext"/>
41+
<filterSearch name="fulltext" component="Magento_Customer/js/grid/search/search"/>
4242
<filters name="listing_filters" component="Magento_Customer/js/grid/filters/filters">
4343
<settings>
44-
<storageConfig>
45-
<param name="provider" xsi:type="string">customer_address_listing.customer_address_listing.listing_top.bookmarks</param>
46-
<param name="namespace" xsi:type="string">current.filters</param>
47-
</storageConfig>
4844
<childDefaults>
4945
<param name="provider" xsi:type="string">customer_address_listing.customer_address_listing.listing_top.listing_filters</param>
5046
<param name="imports" xsi:type="array">

app/code/Magento/Customer/view/adminhtml/web/js/grid/filters/chips.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
* See COPYING.txt for license details.
44
*/
55

6+
/**
7+
* @deprecated Unused file. Filters don't store and share between customers
8+
*/
69
define([
710
'Magento_Ui/js/grid/filters/chips'
811
], function (Chips) {

app/code/Magento/Customer/view/adminhtml/web/js/grid/filters/filters.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ define([
1010

1111
return Filters.extend({
1212
defaults: {
13-
chipsConfig: {
14-
name: '${ $.name }_chips',
15-
provider: '${ $.chipsConfig.name }',
16-
component: 'Magento_Customer/js/grid/filters/chips'
13+
statefull: {
14+
applied: false
1715
}
1816
}
1917
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define([
7+
'Magento_Ui/js/grid/search/search'
8+
], function (Search) {
9+
'use strict';
10+
11+
return Search.extend({
12+
defaults: {
13+
statefull: {
14+
value: false
15+
}
16+
}
17+
});
18+
});

app/code/Magento/Customer/view/base/ui_component/customer_form.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,10 +522,10 @@
522522
<dataScope>customer_address_listing</dataScope>
523523
<ns>customer_address_listing</ns>
524524
<exports>
525-
<link name="parent_id">${ $.externalProvider }:params.parent_id</link>
525+
<link name="params.parent_id">${ $.externalProvider }:params.parent_id</link>
526526
</exports>
527527
<imports>
528-
<link name="parent_id">${ $.provider }:data.customer.entity_id</link>
528+
<link name="params.parent_id">${ $.provider }:data.customer.entity_id</link>
529529
<link name="onAction">ns = ${ $.ns }, index = actions:action</link>
530530
<link name="onMassAction">ns = ${ $.ns }, index = listing_massaction:massaction</link>
531531
</imports>

app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,74 +3,89 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Ui\Component\Filters\Type;
79

10+
use Magento\Framework\App\ObjectManager;
811
use Magento\Ui\Component\AbstractComponent;
912
use Magento\Framework\View\Element\UiComponentFactory;
1013
use Magento\Framework\View\Element\UiComponent\ContextInterface;
1114
use Magento\Framework\Api\FilterBuilder;
1215
use Magento\Ui\Component\Filters\FilterModifier;
16+
use Magento\Ui\View\Element\BookmarkContextInterface;
17+
use Magento\Ui\View\Element\BookmarkContextProviderInterface;
1318

1419
/**
1520
* Abstract class AbstractFilter
16-
* @api
21+
* @api phpcs:ignore Magento2.Classes.AbstractApi.AbstractApi -- Legacy declaration for abstract class
1722
* @since 100.0.2
23+
* phpcs:disable Magento2.Classes.AbstractApi
1824
*/
1925
abstract class AbstractFilter extends AbstractComponent
2026
{
2127
/**
2228
* Component name
2329
*/
24-
const NAME = 'filter';
30+
public const NAME = 'filter';
2531

2632
/**
2733
* Filter variable name
34+
*
35+
* @deprecated Use ContextInterface for retrieve filters
36+
* @see ContextInterface
2837
*/
29-
const FILTER_VAR = 'filters';
38+
public const FILTER_VAR = 'filters';
3039

3140
/**
32-
* Filter data
33-
*
3441
* @var array
3542
*/
36-
protected $filterData;
43+
protected array $filterData;
3744

3845
/**
3946
* @var UiComponentFactory
4047
*/
41-
protected $uiComponentFactory;
48+
protected UiComponentFactory $uiComponentFactory;
4249

4350
/**
4451
* @var FilterBuilder
4552
*/
46-
protected $filterBuilder;
53+
protected FilterBuilder $filterBuilder;
4754

4855
/**
4956
* @var FilterModifier
5057
*/
51-
protected $filterModifier;
58+
protected FilterModifier $filterModifier;
5259

5360
/**
61+
* AbstractFilter constructor
62+
*
5463
* @param ContextInterface $context
5564
* @param UiComponentFactory $uiComponentFactory
5665
* @param FilterBuilder $filterBuilder
5766
* @param FilterModifier $filterModifier
5867
* @param array $components
5968
* @param array $data
69+
* @param BookmarkContextProviderInterface|null $bookmarkContextProvider
6070
*/
6171
public function __construct(
6272
ContextInterface $context,
6373
UiComponentFactory $uiComponentFactory,
6474
FilterBuilder $filterBuilder,
6575
FilterModifier $filterModifier,
6676
array $components = [],
67-
array $data = []
77+
array $data = [],
78+
BookmarkContextProviderInterface $bookmarkContextProvider = null
6879
) {
6980
$this->uiComponentFactory = $uiComponentFactory;
7081
$this->filterBuilder = $filterBuilder;
7182
parent::__construct($context, $components, $data);
72-
$this->filterData = $this->getContext()->getFiltersParams();
7383
$this->filterModifier = $filterModifier;
84+
85+
$bookmarkContextProvider = $bookmarkContextProvider ?: ObjectManager::getInstance()
86+
->get(BookmarkContextProviderInterface::class);
87+
$bookmarkContext = $bookmarkContextProvider->getByUiContext($context);
88+
$this->filterData = $bookmarkContext->getFilterData();
7489
}
7590

7691
/**
@@ -84,7 +99,9 @@ public function getComponentName()
8499
}
85100

86101
/**
87-
* {@inheritdoc}
102+
* Prepare filter component
103+
*
104+
* @inheridoc
88105
*/
89106
public function prepare()
90107
{

app/code/Magento/Ui/Component/Filters/Type/Select.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Ui\Component\Filters\Type;
78

9+
use Magento\Framework\Api\FilterBuilder;
810
use Magento\Framework\Data\OptionSourceInterface;
11+
use Magento\Framework\Exception\LocalizedException;
912
use Magento\Framework\View\Element\UiComponentFactory;
1013
use Magento\Framework\View\Element\UiComponent\ContextInterface;
1114
use Magento\Ui\Component\Form\Element\Select as ElementSelect;
1215
use Magento\Ui\Component\Filters\FilterModifier;
16+
use Magento\Ui\View\Element\BookmarkContextProviderInterface;
1317

1418
/**
1519
* @api
@@ -36,29 +40,40 @@ class Select extends AbstractFilter
3640
/**
3741
* @param ContextInterface $context
3842
* @param UiComponentFactory $uiComponentFactory
39-
* @param \Magento\Framework\Api\FilterBuilder $filterBuilder
43+
* @param FilterBuilder $filterBuilder
4044
* @param FilterModifier $filterModifier
4145
* @param OptionSourceInterface|null $optionsProvider
4246
* @param array $components
4347
* @param array $data
48+
* @param BookmarkContextProviderInterface|null $bookmarkContextProvider
4449
*/
4550
public function __construct(
4651
ContextInterface $context,
4752
UiComponentFactory $uiComponentFactory,
48-
\Magento\Framework\Api\FilterBuilder $filterBuilder,
53+
FilterBuilder $filterBuilder,
4954
FilterModifier $filterModifier,
5055
OptionSourceInterface $optionsProvider = null,
5156
array $components = [],
52-
array $data = []
57+
array $data = [],
58+
BookmarkContextProviderInterface $bookmarkContextProvider = null
5359
) {
5460
$this->optionsProvider = $optionsProvider;
55-
parent::__construct($context, $uiComponentFactory, $filterBuilder, $filterModifier, $components, $data);
61+
parent::__construct(
62+
$context,
63+
$uiComponentFactory,
64+
$filterBuilder,
65+
$filterModifier,
66+
$components,
67+
$data,
68+
$bookmarkContextProvider
69+
);
5670
}
5771

5872
/**
5973
* Prepare component configuration
6074
*
6175
* @return void
76+
* @throws LocalizedException
6277
*/
6378
public function prepare()
6479
{
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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\Plugin\Filters;
9+
10+
use Magento\Framework\View\Element\UiComponent\DataProvider\Sanitizer;
11+
use Magento\Ui\Component\Filters\Type\AbstractFilter;
12+
use Magento\Ui\View\Element\BookmarkContextProviderInterface;
13+
use Psr\Log\LoggerInterface;
14+
use Throwable;
15+
16+
class PrepareErrorHandler
17+
{
18+
/**
19+
* @var LoggerInterface
20+
*/
21+
private LoggerInterface $logger;
22+
23+
/**
24+
* @var Sanitizer
25+
*/
26+
private Sanitizer $sanitizer;
27+
28+
/**
29+
* @var BookmarkContextProviderInterface
30+
*/
31+
private BookmarkContextProviderInterface $bookmarkContextProvider;
32+
33+
/**
34+
* PrepareErrorHandler constructor.
35+
*
36+
* @param BookmarkContextProviderInterface $bookmarkContextProvider
37+
* @param Sanitizer $sanitizer
38+
* @param LoggerInterface $logger
39+
*/
40+
public function __construct(
41+
BookmarkContextProviderInterface $bookmarkContextProvider,
42+
Sanitizer $sanitizer,
43+
LoggerInterface $logger
44+
) {
45+
$this->bookmarkContextProvider = $bookmarkContextProvider;
46+
$this->sanitizer = $sanitizer;
47+
$this->logger = $logger;
48+
}
49+
50+
/**
51+
* Add error config if filter prepare throw exception
52+
*
53+
* @param AbstractFilter $subject
54+
* @param callable $proceed
55+
*/
56+
public function aroundPrepare(AbstractFilter $subject, callable $proceed)
57+
{
58+
try {
59+
$proceed();
60+
} catch (Throwable $e) {
61+
$this->logger->critical($e->getMessage());
62+
63+
$dataProvider = $subject->getContext()->getDataProvider();
64+
$config = array_replace(
65+
$dataProvider->getConfigData(),
66+
[
67+
'lastError' => true
68+
]
69+
);
70+
$dataProvider->setConfigData($this->sanitizer->sanitize($config));
71+
}
72+
}
73+
}

0 commit comments

Comments
 (0)