Skip to content

[Ui] Don't trigger grid reload at first page load #26984

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

Closed
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
@@ -0,0 +1,101 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Customer\Model\Plugin\Customer\DataProviderWithDefaultAddresses;

use Magento\Backend\Model\UrlInterface;
use Magento\Customer\Model\Customer\DataProviderWithDefaultAddresses;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Stdlib\ArrayManager;
use Magento\Framework\View\Element\UiComponent\ContextInterface;

class AddRequestParamToDataProviderRendererUrl
{
/**
* @var UrlInterface
*/
private $url;

/**
* @var RequestInterface
*/
private $request;

/**
* @var ArrayManager
*/
private $arrayManager;

/**
* AddRequestParamToDataProviderUpdateUrl constructor.
*
* @param UrlInterface $url
* @param ArrayManager $arrayManager
* @param RequestInterface $request
*/
public function __construct(
UrlInterface $url,
ArrayManager $arrayManager,
RequestInterface $request
) {
$this->url = $url;
$this->request = $request;
$this->arrayManager = $arrayManager;
}

/**
* Modify provider configuration and return meta
*
* @param DataProviderWithDefaultAddresses $subject
* @param array $meta
* @return array
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterGetMeta(DataProviderWithDefaultAddresses $subject, array $meta)
{
$meta = $this->modifyProviderRenderUrl($meta);
return $meta;
}

/**
* Add parent id into renderer url request
*
* @param array $meta
* @return array
*/
private function modifyProviderRenderUrl(array $meta)
{
$meta = $this->arrayManager->set(
'address',
$meta,
[
'children' => [
'customer_address_listing' => [
'arguments' => [
'data' => [
'config' => [
'render_url' => $this->url->getUrl(
'mui/index/render',
[
'parent_id' => $this->request->getParam('id'),
/*
* Set empty filters to prevent load filters from bookmark
* and sharing between customers
* */
ContextInterface::FILTER_VAR => 0
]
)
]
]
]
]
]
]
);
return $meta;
}
}
7 changes: 5 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 Expand Up @@ -41,4 +41,7 @@
<argument name="reporting" xsi:type="object">CustomerGridCollectionReporting</argument>
</arguments>
</type>
<type name="Magento\Customer\Model\Customer\DataProviderWithDefaultAddresses">
<plugin name="addRequestParamToDataProviderRendererUrl" type="Magento\Customer\Model\Plugin\Customer\DataProviderWithDefaultAddresses\AddRequestParamToDataProviderRendererUrl"/>
</type>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<item name="provider" xsi:type="string">customer_form.customer_form_data_source</item>
</item>
<item name="label" xsi:type="string" translate="true">Customer Information</item>
<item name="reverseMetadataMerge" xsi:type="boolean">true</item>
</argument>
<settings>
<buttons>
Expand Down
46 changes: 43 additions & 3 deletions app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@
* 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\RequestInterface;
use Magento\Framework\App\ObjectManager;
use Magento\Ui\Api\BookmarkManagementInterface;
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;

//phpcs:disable Magento2.Classes.AbstractApi

/**
* Abstract class AbstractFilter
* @api
Expand Down Expand Up @@ -51,26 +58,57 @@ abstract class AbstractFilter extends AbstractComponent
protected $filterModifier;

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

$bookmarkManagement = $bookmarkManagement ?: ObjectManager::getInstance()
->get(BookmarkManagementInterface::class);
$request = $request ?: ObjectManager::getInstance()->get(RequestInterface::class);

$this->filterData = $this->getContext()->getFiltersParams();
if ($this->filterData !== null) {
return;
}

$bookmark = $bookmarkManagement->getByIdentifierNamespace(
'current',
$context->getNamespace()
);

if ($bookmark !== null) {
$bookmarkConfig = $bookmark->getConfig();
$this->filterData = $bookmarkConfig['current']['filters']['applied'] ?? [];

$request->setParams(
[
'paging' => $bookmarkConfig['current']['paging'] ?? [],
'search' => $bookmarkConfig['current']['search']['value'] ?? ''
]
);
}
}

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

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

namespace Magento\Ui\Component\Filters\Type;

use Magento\Framework\App\RequestInterface;
use Magento\Framework\Data\OptionSourceInterface;
use Magento\Framework\View\Element\UiComponentFactory;
use Magento\Framework\View\Element\UiComponent\ContextInterface;
use Magento\Ui\Api\BookmarkManagementInterface;
use Magento\Ui\Component\Form\Element\Select as ElementSelect;
use Magento\Ui\Component\Filters\FilterModifier;

Expand Down Expand Up @@ -41,6 +44,8 @@ class Select extends AbstractFilter
* @param OptionSourceInterface|null $optionsProvider
* @param array $components
* @param array $data
* @param BookmarkManagementInterface|null $bookmarkManagement
* @param RequestInterface|null $request
*/
public function __construct(
ContextInterface $context,
Expand All @@ -49,10 +54,21 @@ public function __construct(
FilterModifier $filterModifier,
OptionSourceInterface $optionsProvider = null,
array $components = [],
array $data = []
array $data = [],
BookmarkManagementInterface $bookmarkManagement = null,
RequestInterface $request = null
) {
$this->optionsProvider = $optionsProvider;
parent::__construct($context, $uiComponentFactory, $filterBuilder, $filterModifier, $components, $data);
parent::__construct(
$context,
$uiComponentFactory,
$filterBuilder,
$filterModifier,
$components,
$data,
$bookmarkManagement,
$request
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Ui\DataProvider\Plugin;

use Magento\Framework\View\Element\UiComponent\DataProvider\DataProviderInterface;
use Magento\Framework\View\Element\UiComponent\DataProvider\Sanitizer;
use Magento\Ui\Api\BookmarkManagementInterface;

class AddBookmarkAvailabilityFlag
{
/**
* @var BookmarkManagementInterface
*/
private $bookmarkManagement;

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

/**
* AddBookmarkAvailabilityFlag constructor
*
* @param BookmarkManagementInterface $bookmarkManagement
* @param Sanitizer $sanitizer
*/
public function __construct(
BookmarkManagementInterface $bookmarkManagement,
Sanitizer $sanitizer
) {
$this->bookmarkManagement = $bookmarkManagement;
$this->sanitizer = $sanitizer;
}

/**
* Modify provider configuration and return meta
*
* @param DataProviderInterface $subject
* @param array $meta
* @return mixed
*/
public function afterGetMeta(DataProviderInterface $subject, array $meta)
{
$this->modifyProviderConfigData($subject);

return $meta;
}

/**
* Modify provider configuration
*
* @param DataProviderInterface $dataProvider
*/
private function modifyProviderConfigData(DataProviderInterface $dataProvider)
{
$configData = $dataProvider->getConfigData();
if (!isset($configData['component'])
|| $configData['component'] !== 'Magento_Ui/js/grid/provider'
|| !isset($configData['namespace'])
) {
return;
}

$bookmark = $this->bookmarkManagement->getByIdentifierNamespace(
'current',
$configData['namespace']
);

$dataProvider->setConfigData($this->sanitizer->sanitize(
array_replace(
$configData,
[
'firstLoad' => $bookmark !== null ? false : true
]
)
));
}
}
Loading