Skip to content

magento/community-features#238: Don't trigger reload of ui listing at page load. #32090

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: 2.4-develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
* See COPYING.txt for license details.
*/
-->
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="AdminMassUpdateProductStatusStoreViewScopeTest">
<annotations>
<features value="Catalog"/>
Expand Down Expand Up @@ -140,5 +139,5 @@
</actionGroup>
<actionGroup ref="StorefrontCheckAdvancedSearchResultActionGroup" stepKey="StorefrontCheckAdvancedSearchResultDefault2"/>
<see userInput="We can't find any items matching these search criteria." selector="{{StorefrontCatalogSearchAdvancedResultMainSection.message}}" stepKey="seeInDefault2"/>
</test>
</test>
</tests>
4 changes: 2 additions & 2 deletions app/code/Magento/Customer/etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Customer\Model\Customer" type="Magento\Customer\Model\Backend\Customer" />
<preference for="Magento\Customer\Model\Customer" type="Magento\Customer\Model\Backend\Customer"/>
<type name="Magento\Customer\Model\ResourceModel\Customer\Collection">
<arguments>
<argument name="modelName" xsi:type="string">Magento\Customer\Model\Backend\Customer</argument>
</arguments>
</type>
<preference for="Magento\Framework\Session\SessionManagerInterface" type="Magento\Backend\Model\Session" />
<preference for="Magento\Framework\Session\SessionManagerInterface" type="Magento\Backend\Model\Session"/>
<type name="Magento\Ui\Model\Export\MetadataProvider">
<arguments>
<argument name="data" xsi:type="array">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,9 @@
<listingToolbar name="listing_top">
<bookmark name="bookmarks"/>
<columnsControls name="columns_controls"/>
<filterSearch name="fulltext"/>
<filterSearch name="fulltext" component="Magento_Customer/js/grid/search/search"/>
<filters name="listing_filters" component="Magento_Customer/js/grid/filters/filters">
<settings>
<storageConfig>
<param name="provider" xsi:type="string">customer_address_listing.customer_address_listing.listing_top.bookmarks</param>
<param name="namespace" xsi:type="string">current.filters</param>
</storageConfig>
<childDefaults>
<param name="provider" xsi:type="string">customer_address_listing.customer_address_listing.listing_top.listing_filters</param>
<param name="imports" xsi:type="array">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* See COPYING.txt for license details.
*/

/**
* @deprecated Unused file. Filters don't store and share between customers
*/
define([
'Magento_Ui/js/grid/filters/chips'
], function (Chips) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ define([

return Filters.extend({
defaults: {
chipsConfig: {
name: '${ $.name }_chips',
provider: '${ $.chipsConfig.name }',
component: 'Magento_Customer/js/grid/filters/chips'
statefull: {
applied: false
}
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

define([
'Magento_Ui/js/grid/search/search'
], function (Search) {
'use strict';

return Search.extend({
defaults: {
statefull: {
value: false
}
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -522,10 +522,10 @@
<dataScope>customer_address_listing</dataScope>
<ns>customer_address_listing</ns>
<exports>
<link name="parent_id">${ $.externalProvider }:params.parent_id</link>
<link name="params.parent_id">${ $.externalProvider }:params.parent_id</link>
</exports>
<imports>
<link name="parent_id">${ $.provider }:data.customer.entity_id</link>
<link name="params.parent_id">${ $.provider }:data.customer.entity_id</link>
<link name="onAction">ns = ${ $.ns }, index = actions:action</link>
<link name="onMassAction">ns = ${ $.ns }, index = listing_massaction:massaction</link>
</imports>
Expand Down
41 changes: 29 additions & 12 deletions app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,74 +3,89 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Ui\Component\Filters\Type;

use Magento\Framework\App\ObjectManager;
use Magento\Ui\Component\AbstractComponent;
use Magento\Framework\View\Element\UiComponentFactory;
use Magento\Framework\View\Element\UiComponent\ContextInterface;
use Magento\Framework\Api\FilterBuilder;
use Magento\Ui\Component\Filters\FilterModifier;
use Magento\Ui\View\Element\BookmarkContextInterface;
use Magento\Ui\View\Element\BookmarkContextProviderInterface;

/**
* Abstract class AbstractFilter
* @api
* @api phpcs:ignore Magento2.Classes.AbstractApi.AbstractApi -- Legacy declaration for abstract class
* @since 100.0.2
* phpcs:disable Magento2.Classes.AbstractApi
*/
abstract class AbstractFilter extends AbstractComponent
{
/**
* Component name
*/
const NAME = 'filter';
public const NAME = 'filter';

/**
* Filter variable name
*
* @deprecated Use ContextInterface for retrieve filters
* @see ContextInterface
*/
const FILTER_VAR = 'filters';
public const FILTER_VAR = 'filters';

/**
* Filter data
*
* @var array
*/
protected $filterData;
protected array $filterData;

/**
* @var UiComponentFactory
*/
protected $uiComponentFactory;
protected UiComponentFactory $uiComponentFactory;

/**
* @var FilterBuilder
*/
protected $filterBuilder;
protected FilterBuilder $filterBuilder;

/**
* @var FilterModifier
*/
protected $filterModifier;
protected FilterModifier $filterModifier;

/**
* AbstractFilter constructor
*
* @param ContextInterface $context
* @param UiComponentFactory $uiComponentFactory
* @param FilterBuilder $filterBuilder
* @param FilterModifier $filterModifier
* @param array $components
* @param array $data
* @param BookmarkContextProviderInterface|null $bookmarkContextProvider
*/
public function __construct(
ContextInterface $context,
UiComponentFactory $uiComponentFactory,
FilterBuilder $filterBuilder,
FilterModifier $filterModifier,
array $components = [],
array $data = []
array $data = [],
BookmarkContextProviderInterface $bookmarkContextProvider = null
) {
$this->uiComponentFactory = $uiComponentFactory;
$this->filterBuilder = $filterBuilder;
parent::__construct($context, $components, $data);
$this->filterData = $this->getContext()->getFiltersParams();
$this->filterModifier = $filterModifier;

$bookmarkContextProvider = $bookmarkContextProvider ?: ObjectManager::getInstance()
->get(BookmarkContextProviderInterface::class);
$bookmarkContext = $bookmarkContextProvider->getByUiContext($context);
$this->filterData = $bookmarkContext->getFilterData();
}

/**
Expand All @@ -84,7 +99,9 @@ public function getComponentName()
}

/**
* {@inheritdoc}
* Prepare filter component
*
* @inheridoc
*/
public function prepare()
{
Expand Down
23 changes: 19 additions & 4 deletions app/code/Magento/Ui/Component/Filters/Type/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Ui\Component\Filters\Type;

use Magento\Framework\Api\FilterBuilder;
use Magento\Framework\Data\OptionSourceInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\View\Element\UiComponentFactory;
use Magento\Framework\View\Element\UiComponent\ContextInterface;
use Magento\Ui\Component\Form\Element\Select as ElementSelect;
use Magento\Ui\Component\Filters\FilterModifier;
use Magento\Ui\View\Element\BookmarkContextProviderInterface;

/**
* @api
Expand All @@ -36,29 +40,40 @@ class Select extends AbstractFilter
/**
* @param ContextInterface $context
* @param UiComponentFactory $uiComponentFactory
* @param \Magento\Framework\Api\FilterBuilder $filterBuilder
* @param FilterBuilder $filterBuilder
* @param FilterModifier $filterModifier
* @param OptionSourceInterface|null $optionsProvider
* @param array $components
* @param array $data
* @param BookmarkContextProviderInterface|null $bookmarkContextProvider
*/
public function __construct(
ContextInterface $context,
UiComponentFactory $uiComponentFactory,
\Magento\Framework\Api\FilterBuilder $filterBuilder,
FilterBuilder $filterBuilder,
FilterModifier $filterModifier,
OptionSourceInterface $optionsProvider = null,
array $components = [],
array $data = []
array $data = [],
BookmarkContextProviderInterface $bookmarkContextProvider = null
) {
$this->optionsProvider = $optionsProvider;
parent::__construct($context, $uiComponentFactory, $filterBuilder, $filterModifier, $components, $data);
parent::__construct(
$context,
$uiComponentFactory,
$filterBuilder,
$filterModifier,
$components,
$data,
$bookmarkContextProvider
);
}

/**
* Prepare component configuration
*
* @return void
* @throws LocalizedException
*/
public function prepare()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Ui\Component\Plugin\Filters;

use Magento\Framework\View\Element\UiComponent\DataProvider\Sanitizer;
use Magento\Ui\Component\Filters\Type\AbstractFilter;
use Magento\Ui\View\Element\BookmarkContextProviderInterface;
use Psr\Log\LoggerInterface;
use Throwable;

class PrepareErrorHandler
{
/**
* @var LoggerInterface
*/
private LoggerInterface $logger;

/**
* @var Sanitizer
*/
private Sanitizer $sanitizer;

/**
* @var BookmarkContextProviderInterface
*/
private BookmarkContextProviderInterface $bookmarkContextProvider;

/**
* PrepareErrorHandler constructor.
*
* @param BookmarkContextProviderInterface $bookmarkContextProvider
* @param Sanitizer $sanitizer
* @param LoggerInterface $logger
*/
public function __construct(
BookmarkContextProviderInterface $bookmarkContextProvider,
Sanitizer $sanitizer,
LoggerInterface $logger
) {
$this->bookmarkContextProvider = $bookmarkContextProvider;
$this->sanitizer = $sanitizer;
$this->logger = $logger;
}

/**
* Add error config if filter prepare throw exception
*
* @param AbstractFilter $subject
* @param callable $proceed
*/
public function aroundPrepare(AbstractFilter $subject, callable $proceed)
{
try {
$proceed();
} catch (Throwable $e) {
$this->logger->critical($e->getMessage());

$dataProvider = $subject->getContext()->getDataProvider();
$config = array_replace(
$dataProvider->getConfigData(),
[
'lastError' => true
]
);
$dataProvider->setConfigData($this->sanitizer->sanitize($config));
}
}
}
Loading