From 3356b1fe1429662c4441e4620be59fcf8542f272 Mon Sep 17 00:00:00 2001 From: Denis Kopylov Date: Thu, 1 Oct 2020 14:52:24 +0300 Subject: [PATCH 01/12] [Ui] Don't trigger grid reload at first page load --- .../Component/Filters/Type/AbstractFilter.php | 35 +++++- .../Magento/Ui/Model/BookmarkManagement.php | 101 ++++++++++-------- .../Ui/view/base/web/js/grid/provider.js | 18 +++- 3 files changed, 103 insertions(+), 51 deletions(-) diff --git a/app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php b/app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php index f5d3af44f71f4..b03d6baae540f 100644 --- a/app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php +++ b/app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php @@ -3,8 +3,12 @@ * 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\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; @@ -57,6 +61,8 @@ abstract class AbstractFilter extends AbstractComponent * @param FilterModifier $filterModifier * @param array $components * @param array $data + * @param BookmarkManagementInterface|null $bookmarkManagement + * @param RequestInterface|null $request */ public function __construct( ContextInterface $context, @@ -64,13 +70,38 @@ public function __construct( 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); + + $filterData = $this->getContext()->getFiltersParams(); + if (!$request->isAjax()) { + $bookmark = $bookmarkManagement->getByIdentifierNamespace( + 'current', + $context->getNamespace() + ); + if (null !== $bookmark) { + $bookmarkConfig = $bookmark->getConfig(); + $filterData = $bookmarkConfig['current']['filters']['applied'] ?? []; + + $request->setParams( + [ + 'paging' => $bookmarkConfig['current']['paging'] ?? [] + ] + ); + } + } + + $this->filterData = $filterData; } /** diff --git a/app/code/Magento/Ui/Model/BookmarkManagement.php b/app/code/Magento/Ui/Model/BookmarkManagement.php index 0659ce2ded7bc..3983bba6da1d6 100644 --- a/app/code/Magento/Ui/Model/BookmarkManagement.php +++ b/app/code/Magento/Ui/Model/BookmarkManagement.php @@ -3,42 +3,58 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); namespace Magento\Ui\Model; -class BookmarkManagement implements \Magento\Ui\Api\BookmarkManagementInterface +use Magento\Authorization\Model\UserContextInterface; +use Magento\Framework\Api\FilterBuilder; +use Magento\Framework\Api\SearchCriteriaBuilder; +use Magento\Ui\Api\BookmarkManagementInterface; +use Magento\Ui\Api\BookmarkRepositoryInterface; + +/** + * Bookmark Management class provide functional for retrieving bookmarks by params + * @SuppressWarnings(PHPMD.LongVariable) + */ +class BookmarkManagement implements BookmarkManagementInterface { /** - * @var \Magento\Ui\Api\BookmarkRepositoryInterface + * @var BookmarkRepositoryInterface */ protected $bookmarkRepository; /** - * @var \Magento\Framework\Api\SearchCriteriaBuilder + * @var SearchCriteriaBuilder */ protected $searchCriteriaBuilder; /** - * @var \Magento\Framework\Api\FilterBuilder + * @var FilterBuilder */ protected $filterBuilder; /** - * @var \Magento\Authorization\Model\UserContextInterface + * @var UserContextInterface */ protected $userContext; /** - * @param \Magento\Ui\Api\BookmarkRepositoryInterface $bookmarkRepository - * @param \Magento\Framework\Api\FilterBuilder $filterBuilder - * @param \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder - * @param \Magento\Authorization\Model\UserContextInterface $userContext + * @var array + */ + private $bookmarkRegistry = []; + + /** + * @param BookmarkRepositoryInterface $bookmarkRepository + * @param FilterBuilder $filterBuilder + * @param SearchCriteriaBuilder $searchCriteriaBuilder + * @param UserContextInterface $userContext */ public function __construct( - \Magento\Ui\Api\BookmarkRepositoryInterface $bookmarkRepository, - \Magento\Framework\Api\FilterBuilder $filterBuilder, - \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder, - \Magento\Authorization\Model\UserContextInterface $userContext + BookmarkRepositoryInterface $bookmarkRepository, + FilterBuilder $filterBuilder, + SearchCriteriaBuilder $searchCriteriaBuilder, + UserContextInterface $userContext ) { $this->bookmarkRepository = $bookmarkRepository; $this->searchCriteriaBuilder = $searchCriteriaBuilder; @@ -47,9 +63,12 @@ public function __construct( } /** - * {@inheritdoc} + * Create search criteria builder with namespace and user filters + * + * @param $namespace + * @return void */ - public function loadByNamespace($namespace) + private function prepareSearchCriteriaBuilderByNamespace($namespace): void { $userIdFilter = $this->filterBuilder ->setField('user_id') @@ -64,11 +83,16 @@ public function loadByNamespace($namespace) $this->searchCriteriaBuilder->addFilters([$userIdFilter]); $this->searchCriteriaBuilder->addFilters([$namespaceFilter]); + } + /** + * {@inheritdoc} + */ + public function loadByNamespace($namespace) + { + $this->prepareSearchCriteriaBuilderByNamespace($namespace); $searchCriteria = $this->searchCriteriaBuilder->create(); - $searchResults = $this->bookmarkRepository->getList($searchCriteria); - - return $searchResults; + return $this->bookmarkRepository->getList($searchCriteria); } /** @@ -76,35 +100,24 @@ public function loadByNamespace($namespace) */ public function getByIdentifierNamespace($identifier, $namespace) { - $userIdFilter = $this->filterBuilder - ->setField('user_id') - ->setConditionType('eq') - ->setValue($this->userContext->getUserId()) - ->create(); - $identifierFilter = $this->filterBuilder - ->setField('identifier') - ->setConditionType('eq') - ->setValue($identifier) - ->create(); - $namespaceFilter = $this->filterBuilder - ->setField('namespace') - ->setConditionType('eq') - ->setValue($namespace) - ->create(); + if (!isset($this->bookmarkRegistry[$identifier . $namespace])) { + $this->prepareSearchCriteriaBuilderByNamespace($namespace); + $identifierFilter = $this->filterBuilder + ->setField('identifier') + ->setConditionType('eq') + ->setValue($identifier) + ->create(); + $this->searchCriteriaBuilder->addFilters([$identifierFilter]); - $this->searchCriteriaBuilder->addFilters([$userIdFilter]); - $this->searchCriteriaBuilder->addFilters([$identifierFilter]); - $this->searchCriteriaBuilder->addFilters([$namespaceFilter]); - - $searchCriteria = $this->searchCriteriaBuilder->create(); - $searchResults = $this->bookmarkRepository->getList($searchCriteria); - if ($searchResults->getTotalCount() > 0) { - foreach ($searchResults->getItems() as $searchResult) { - $bookmark = $this->bookmarkRepository->getById($searchResult->getId()); - return $bookmark; + $searchCriteria = $this->searchCriteriaBuilder->create(); + $searchResults = $this->bookmarkRepository->getList($searchCriteria); + if ($searchResults->getTotalCount() > 0) { + $items = $searchResults->getItems(); + $this->bookmarkRegistry[$identifier . $namespace] = array_shift($items); + return $this->bookmarkRegistry[$identifier . $namespace]; } } - return null; + return $this->bookmarkRegistry[$identifier . $namespace] ?? null; } } diff --git a/app/code/Magento/Ui/view/base/web/js/grid/provider.js b/app/code/Magento/Ui/view/base/web/js/grid/provider.js index 2ba8bd73af910..42657c4d91ae1 100644 --- a/app/code/Magento/Ui/view/base/web/js/grid/provider.js +++ b/app/code/Magento/Ui/view/base/web/js/grid/provider.js @@ -47,16 +47,24 @@ define([ _.bindAll(this, 'onReload'); this._super() - .initStorage() - .clearData(); + .initStorage(); - // Load data when there will - // be no more pending assets. - resolver(this.reload, this); + /* Call set data with predefined data for correct rendering action column */ + this.setData(this.data); + + resolver(this.triggerReloaded, this); return this; }, + /** + * Trigger reloaded event + */ + triggerReloaded: function () { + this.firstLoad = false; + this.trigger('reloaded'); + }, + /** * Initializes storage component. * From 13fc4b3ca927cd0f9624ccc9535d9e5efad613be Mon Sep 17 00:00:00 2001 From: Denis Kopylov Date: Thu, 1 Oct 2020 15:48:46 +0300 Subject: [PATCH 02/12] [Ui] Fix unit tests --- .../Magento/Ui/Test/Unit/Model/BookmarkManagementTest.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/app/code/Magento/Ui/Test/Unit/Model/BookmarkManagementTest.php b/app/code/Magento/Ui/Test/Unit/Model/BookmarkManagementTest.php index 45693cebf4042..3bf4e287d7214 100644 --- a/app/code/Magento/Ui/Test/Unit/Model/BookmarkManagementTest.php +++ b/app/code/Magento/Ui/Test/Unit/Model/BookmarkManagementTest.php @@ -140,10 +140,8 @@ public function testGetByIdentifierNamespace() Filter::KEY_CONDITION_TYPE => 'eq' ] ); - $bookmarkId = 1; $bookmark = $this->getMockBuilder(BookmarkInterface::class) ->getMockForAbstractClass(); - $bookmark->expects($this->once())->method('getId')->willReturn($bookmarkId); $searchCriteria = $this->getMockBuilder(SearchCriteriaInterface::class) ->getMockForAbstractClass(); $this->filterBuilder->expects($this->at(0)) @@ -169,10 +167,6 @@ public function testGetByIdentifierNamespace() ->method('getList') ->with($searchCriteria) ->willReturn($searchResult); - $this->bookmarkRepository->expects($this->once()) - ->method('getById') - ->with($bookmarkId) - ->willReturn($bookmark); $this->assertEquals( $bookmark, $this->bookmarkManagement->getByIdentifierNamespace($identifier, $namespace) From 0afc67cc3f972420c5b270cbeeec8ddd58e96c61 Mon Sep 17 00:00:00 2001 From: Denis Kopylov Date: Mon, 5 Oct 2020 13:12:01 +0300 Subject: [PATCH 03/12] [Ui] Fix unit tests --- .../Ui/Component/Filters/Type/Select.php | 20 ++++++++- .../Component/Filters/Type/DateRangeTest.php | 31 ++++++++++++- .../Unit/Component/Filters/Type/DateTest.php | 43 ++++++++++++++++--- .../Unit/Component/Filters/Type/InputTest.php | 31 ++++++++++++- .../Unit/Component/Filters/Type/RangeTest.php | 30 ++++++++++++- .../Component/Filters/Type/SelectTest.php | 31 ++++++++++++- 6 files changed, 170 insertions(+), 16 deletions(-) diff --git a/app/code/Magento/Ui/Component/Filters/Type/Select.php b/app/code/Magento/Ui/Component/Filters/Type/Select.php index 06a821019b680..7fac34d499a99 100644 --- a/app/code/Magento/Ui/Component/Filters/Type/Select.php +++ b/app/code/Magento/Ui/Component/Filters/Type/Select.php @@ -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; @@ -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, @@ -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 + ); } /** diff --git a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/DateRangeTest.php b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/DateRangeTest.php index dd8456460d6b3..d8441940ea0af 100644 --- a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/DateRangeTest.php +++ b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/DateRangeTest.php @@ -8,11 +8,13 @@ namespace Magento\Ui\Test\Unit\Component\Filters\Type; use Magento\Framework\Api\FilterBuilder; +use Magento\Framework\App\RequestInterface; use Magento\Framework\View\Element\UiComponent\ContextInterface; use Magento\Framework\View\Element\UiComponent\ContextInterface as UiContext; use Magento\Framework\View\Element\UiComponent\DataProvider\DataProviderInterface; use Magento\Framework\View\Element\UiComponent\Processor; use Magento\Framework\View\Element\UiComponentFactory; +use Magento\Ui\Api\BookmarkManagementInterface; use Magento\Ui\Component\Filters\FilterModifier; use Magento\Ui\Component\Filters\Type\DateRange; use Magento\Ui\Component\Form\Element\DataType\Date as FormDate; @@ -41,6 +43,16 @@ class DateRangeTest extends TestCase */ protected $filterModifierMock; + /** + * @var BookmarkManagementInterface|MockObject + */ + private $bookmarkManagementMock; + + /** + * @var RequestInterface|MockObject + */ + private $requestMock; + /** * Set up */ @@ -61,6 +73,16 @@ protected function setUp(): void FilterModifier::class, ['applyFilterModifier'] ); + + $this->bookmarkManagementMock = $this->getMockForAbstractClass( + BookmarkManagementInterface::class + ); + $this->bookmarkManagementMock->expects($this->never())->method('getByIdentifierNamespace'); + + $this->requestMock = $this->getMockBuilder(RequestInterface::class) + ->addMethods(['isAjax']) + ->getMockForAbstractClass(); + $this->requestMock->expects($this->once())->method('isAjax')->willReturn(true); } /** @@ -76,7 +98,10 @@ public function testGetComponentName() $this->uiComponentFactory, $this->filterBuilderMock, $this->filterModifierMock, - [] + [], + [], + $this->bookmarkManagementMock, + $this->requestMock ); $this->assertSame(DateRange::NAME, $dateRange->getComponentName()); } @@ -148,7 +173,9 @@ public function testPrepare($name, $filterData, $expectedCondition) $this->filterBuilderMock, $this->filterModifierMock, [], - ['name' => $name] + ['name' => $name], + $this->bookmarkManagementMock, + $this->requestMock ); $dateRange->prepare(); diff --git a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/DateTest.php b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/DateTest.php index ec3d864a2871a..2c3bc1118681f 100644 --- a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/DateTest.php +++ b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/DateTest.php @@ -9,10 +9,12 @@ use Magento\Framework\Api\Filter; use Magento\Framework\Api\FilterBuilder; +use Magento\Framework\App\RequestInterface; use Magento\Framework\View\Element\UiComponent\ContextInterface; use Magento\Framework\View\Element\UiComponent\DataProvider\DataProviderInterface; use Magento\Framework\View\Element\UiComponent\Processor; use Magento\Framework\View\Element\UiComponentFactory; +use Magento\Ui\Api\BookmarkManagementInterface; use Magento\Ui\Component\Filters\FilterModifier; use Magento\Ui\Component\Filters\Type\Date; use Magento\Ui\Component\Form\Element\DataType\Date as FormDate; @@ -49,6 +51,16 @@ class DateTest extends TestCase */ private $dataProviderMock; + /** + * @var BookmarkManagementInterface|MockObject + */ + private $bookmarkManagementMock; + + /** + * @var MockObject + */ + private $requestMock; + /** * Set up */ @@ -69,6 +81,16 @@ protected function setUp(): void ->getMock(); $this->dataProviderMock = $this->getMockForAbstractClass(DataProviderInterface::class); + + $this->bookmarkManagementMock = $this->getMockForAbstractClass( + BookmarkManagementInterface::class + ); + $this->bookmarkManagementMock->expects($this->never())->method('getByIdentifierNamespace'); + + $this->requestMock = $this->getMockBuilder(RequestInterface::class) + ->addMethods(['isAjax']) + ->getMockForAbstractClass(); + $this->requestMock->expects($this->once())->method('isAjax')->willReturn(true); } /** @@ -84,7 +106,10 @@ public function testGetComponentName() $this->uiComponentFactory, $this->filterBuilderMock, $this->filterModifierMock, - [] + [], + [], + $this->bookmarkManagementMock, + $this->requestMock ); static::assertSame(Date::NAME, $date->getComponentName()); @@ -148,7 +173,9 @@ public function testPrepare(string $name, bool $showsTime, array $filterData, ?a [ 'name' => $name, 'config' => ['options' => ['showsTime' => $showsTime]], - ] + ], + $this->bookmarkManagementMock, + $this->requestMock ); $date->prepare(); } @@ -209,8 +236,10 @@ public function getPrepareDataProvider() 'showsTime' => false, 'filterData' => ['test_date' => ['from' => '11-05-2015', 'to' => '11-05-2015']], 'expectedCondition' => [ - 'date_from' => '2015-05-11 00:00:00', 'type_from' => 'gteq', - 'date_to' => '2015-05-11 23:59:59', 'type_to' => 'lteq' + 'date_from' => '2015-05-11 00:00:00', + 'type_from' => 'gteq', + 'date_to' => '2015-05-11 23:59:59', + 'type_to' => 'lteq' ], ], [ @@ -230,8 +259,10 @@ public function getPrepareDataProvider() 'showsTime' => true, 'filterData' => ['test_date' => ['from' => '11-05-2015 10:20:00', 'to' => '11-05-2015 18:25:00']], 'expectedCondition' => [ - 'date_from' => '2015-05-11 10:20:00', 'type_from' => 'gteq', - 'date_to' => '2015-05-11 18:25:00', 'type_to' => 'lteq' + 'date_from' => '2015-05-11 10:20:00', + 'type_from' => 'gteq', + 'date_to' => '2015-05-11 18:25:00', + 'type_to' => 'lteq' ], ], ]; diff --git a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/InputTest.php b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/InputTest.php index 83ad794107288..2a2651a0c0309 100644 --- a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/InputTest.php +++ b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/InputTest.php @@ -9,11 +9,13 @@ use Magento\Framework\Api\Filter; use Magento\Framework\Api\FilterBuilder; +use Magento\Framework\App\RequestInterface; use Magento\Framework\View\Element\UiComponent\ContextInterface; use Magento\Framework\View\Element\UiComponent\DataProvider\DataProviderInterface; use Magento\Framework\View\Element\UiComponent\Processor; use Magento\Framework\View\Element\UiComponentFactory; use Magento\Framework\View\Element\UiComponentInterface; +use Magento\Ui\Api\BookmarkManagementInterface; use Magento\Ui\Component\Filters\FilterModifier; use Magento\Ui\Component\Filters\Type\Input; use PHPUnit\Framework\MockObject\MockObject; @@ -41,6 +43,16 @@ class InputTest extends TestCase */ protected $filterModifierMock; + /** + * @var BookmarkManagementInterface|MockObject + */ + private $bookmarkManagementMock; + + /** + * @var RequestInterface|MockObject + */ + private $requestMock; + /** * @inheritdoc */ @@ -61,6 +73,16 @@ protected function setUp(): void FilterModifier::class, ['applyFilterModifier'] ); + + $this->bookmarkManagementMock = $this->getMockForAbstractClass( + BookmarkManagementInterface::class + ); + $this->bookmarkManagementMock->expects($this->never())->method('getByIdentifierNamespace'); + + $this->requestMock = $this->getMockBuilder(RequestInterface::class) + ->addMethods(['isAjax']) + ->getMockForAbstractClass(); + $this->requestMock->expects($this->once())->method('isAjax')->willReturn(true); } /** @@ -76,7 +98,10 @@ public function testGetComponentName(): void $this->uiComponentFactory, $this->filterBuilderMock, $this->filterModifierMock, - [] + [], + [], + $this->bookmarkManagementMock, + $this->requestMock ); $this->assertSame(Input::NAME, $date->getComponentName()); @@ -165,7 +190,9 @@ public function testPrepare(string $name, array $filterData, ?array $expectedCon $this->filterBuilderMock, $this->filterModifierMock, [], - ['name' => $name] + ['name' => $name], + $this->bookmarkManagementMock, + $this->requestMock ); $date->prepare(); diff --git a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/RangeTest.php b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/RangeTest.php index e0f140b3ae901..e3b00726d5f48 100644 --- a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/RangeTest.php +++ b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/RangeTest.php @@ -9,10 +9,12 @@ use Magento\Framework\Api\Filter; use Magento\Framework\Api\FilterBuilder; +use Magento\Framework\App\RequestInterface; use Magento\Framework\View\Element\UiComponent\ContextInterface; use Magento\Framework\View\Element\UiComponent\DataProvider\DataProviderInterface; use Magento\Framework\View\Element\UiComponent\Processor; use Magento\Framework\View\Element\UiComponentFactory; +use Magento\Ui\Api\BookmarkManagementInterface; use Magento\Ui\Component\Filters\FilterModifier; use Magento\Ui\Component\Filters\Type\Range; use PHPUnit\Framework\MockObject\MockObject; @@ -40,6 +42,16 @@ class RangeTest extends TestCase */ protected $filterModifierMock; + /** + * @var BookmarkManagementInterface|MockObject + */ + private $bookmarkManagementMock; + + /** + * @var RequestInterface|MockObject + */ + private $requestMock; + /** * Set up */ @@ -57,6 +69,15 @@ protected function setUp(): void FilterModifier::class, ['applyFilterModifier'] ); + $this->bookmarkManagementMock = $this->getMockForAbstractClass( + BookmarkManagementInterface::class + ); + $this->bookmarkManagementMock->expects($this->never())->method('getByIdentifierNamespace'); + + $this->requestMock = $this->getMockBuilder(RequestInterface::class) + ->addMethods(['isAjax']) + ->getMockForAbstractClass(); + $this->requestMock->expects($this->once())->method('isAjax')->willReturn(true); } /** @@ -72,7 +93,10 @@ public function testGetComponentName() $this->uiComponentFactory, $this->filterBuilderMock, $this->filterModifierMock, - [] + [], + [], + $this->bookmarkManagementMock, + $this->requestMock ); $this->assertSame(Range::NAME, $range->getComponentName()); @@ -139,7 +163,9 @@ public function testPrepare($name, $filterData, $expectedCalls) $this->filterBuilderMock, $this->filterModifierMock, [], - ['name' => $name] + ['name' => $name], + $this->bookmarkManagementMock, + $this->requestMock ); $range->prepare(); } diff --git a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/SelectTest.php b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/SelectTest.php index 83de1a87a981c..82dfd47d7c6f4 100644 --- a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/SelectTest.php +++ b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/SelectTest.php @@ -9,12 +9,14 @@ use Magento\Framework\Api\Filter; use Magento\Framework\Api\FilterBuilder; +use Magento\Framework\App\RequestInterface; use Magento\Framework\Data\OptionSourceInterface; use Magento\Framework\View\Element\UiComponent\ContextInterface; use Magento\Framework\View\Element\UiComponent\DataProvider\DataProviderInterface; use Magento\Framework\View\Element\UiComponent\Processor; use Magento\Framework\View\Element\UiComponentFactory; use Magento\Framework\View\Element\UiComponentInterface; +use Magento\Ui\Api\BookmarkManagementInterface; use Magento\Ui\Component\Filters\FilterModifier; use Magento\Ui\Component\Filters\Type\Select; use PHPUnit\Framework\MockObject\MockObject; @@ -42,6 +44,16 @@ class SelectTest extends TestCase */ protected $filterModifierMock; + /** + * @var BookmarkManagementInterface|MockObject + */ + private $bookmarkManagementMock; + + /** + * @var MockObject + */ + private $requestMock; + /** * Set up */ @@ -62,6 +74,16 @@ protected function setUp(): void FilterModifier::class, ['applyFilterModifier'] ); + + $this->bookmarkManagementMock = $this->getMockForAbstractClass( + BookmarkManagementInterface::class + ); + $this->bookmarkManagementMock->expects($this->never())->method('getByIdentifierNamespace'); + + $this->requestMock = $this->getMockBuilder(RequestInterface::class) + ->addMethods(['isAjax']) + ->getMockForAbstractClass(); + $this->requestMock->expects($this->once())->method('isAjax')->willReturn(true); } /** @@ -78,7 +100,10 @@ public function testGetComponentName() $this->filterBuilderMock, $this->filterModifierMock, null, - [] + [], + [], + $this->bookmarkManagementMock, + $this->requestMock ); $this->assertSame(Select::NAME, $date->getComponentName()); @@ -173,7 +198,9 @@ public function testPrepare($data, $filterData, $expectedCondition) $this->filterModifierMock, $selectOptions, [], - $data + $data, + $this->bookmarkManagementMock, + $this->requestMock ); $date->prepare(); From 69906df19eba027fec82f49fb007d00fdeb6ad5b Mon Sep 17 00:00:00 2001 From: Denis Kopylov Date: Mon, 19 Oct 2020 23:52:39 +0300 Subject: [PATCH 04/12] Fix static tests --- .../Magento/Ui/Component/Filters/Type/AbstractFilter.php | 2 +- app/code/Magento/Ui/Model/BookmarkManagement.php | 8 ++++---- .../Ui/Test/Unit/Component/Filters/Type/DateTest.php | 2 +- .../Ui/Test/Unit/Component/Filters/Type/SelectTest.php | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php b/app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php index b03d6baae540f..5eede724429ad 100644 --- a/app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php +++ b/app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php @@ -115,7 +115,7 @@ public function getComponentName() } /** - * {@inheritdoc} + * @inheridoc */ public function prepare() { diff --git a/app/code/Magento/Ui/Model/BookmarkManagement.php b/app/code/Magento/Ui/Model/BookmarkManagement.php index 3983bba6da1d6..7a0012a2c1d4f 100644 --- a/app/code/Magento/Ui/Model/BookmarkManagement.php +++ b/app/code/Magento/Ui/Model/BookmarkManagement.php @@ -65,10 +65,10 @@ public function __construct( /** * Create search criteria builder with namespace and user filters * - * @param $namespace + * @param string $namespace * @return void */ - private function prepareSearchCriteriaBuilderByNamespace($namespace): void + private function prepareSearchCriteriaBuilderByNamespace(string $namespace): void { $userIdFilter = $this->filterBuilder ->setField('user_id') @@ -86,7 +86,7 @@ private function prepareSearchCriteriaBuilderByNamespace($namespace): void } /** - * {@inheritdoc} + * @inheritdoc */ public function loadByNamespace($namespace) { @@ -96,7 +96,7 @@ public function loadByNamespace($namespace) } /** - * {@inheritdoc} + * @inheritdoc */ public function getByIdentifierNamespace($identifier, $namespace) { diff --git a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/DateTest.php b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/DateTest.php index 2c3bc1118681f..5fa4c5f7a03c1 100644 --- a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/DateTest.php +++ b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/DateTest.php @@ -57,7 +57,7 @@ class DateTest extends TestCase private $bookmarkManagementMock; /** - * @var MockObject + * @var RequestInterface|MockObject */ private $requestMock; diff --git a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/SelectTest.php b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/SelectTest.php index 82dfd47d7c6f4..1c9e473b46c7c 100644 --- a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/SelectTest.php +++ b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/SelectTest.php @@ -50,7 +50,7 @@ class SelectTest extends TestCase private $bookmarkManagementMock; /** - * @var MockObject + * @var RequestInterface|MockObject */ private $requestMock; From f5ca43e36e2487ec3dffc9b4c3118650c556a014 Mon Sep 17 00:00:00 2001 From: Denis Kopylov Date: Tue, 20 Oct 2020 02:10:53 +0300 Subject: [PATCH 05/12] Refactoring and fix functional tests --- .../ui_component/customer_address_listing.xml | 10 +++++++++- .../Ui/Component/Filters/Type/AbstractFilter.php | 6 +++++- .../Test/Unit/Component/Filters/Type/DateRangeTest.php | 2 -- .../Ui/Test/Unit/Component/Filters/Type/DateTest.php | 2 -- .../Ui/Test/Unit/Component/Filters/Type/InputTest.php | 2 -- .../Ui/Test/Unit/Component/Filters/Type/RangeTest.php | 2 -- .../Ui/Test/Unit/Component/Filters/Type/SelectTest.php | 2 -- .../Framework/View/Element/UiComponent/Context.php | 4 ++-- 8 files changed, 16 insertions(+), 14 deletions(-) diff --git a/app/code/Magento/Customer/view/adminhtml/ui_component/customer_address_listing.xml b/app/code/Magento/Customer/view/adminhtml/ui_component/customer_address_listing.xml index fb42a2c5a0787..fa4aae0cf7e3b 100644 --- a/app/code/Magento/Customer/view/adminhtml/ui_component/customer_address_listing.xml +++ b/app/code/Magento/Customer/view/adminhtml/ui_component/customer_address_listing.xml @@ -36,7 +36,15 @@ - + + + + + ${ $.provider }:params.parent_id + + + + diff --git a/app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php b/app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php index 5eede724429ad..73162aedc06bb 100644 --- a/app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php +++ b/app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php @@ -84,7 +84,7 @@ public function __construct( $request = $request ?: ObjectManager::getInstance()->get(RequestInterface::class); $filterData = $this->getContext()->getFiltersParams(); - if (!$request->isAjax()) { + if (null === $filterData) { $bookmark = $bookmarkManagement->getByIdentifierNamespace( 'current', $context->getNamespace() @@ -98,6 +98,10 @@ public function __construct( 'paging' => $bookmarkConfig['current']['paging'] ?? [] ] ); + + if (isset($bookmarkConfig['current']['request_params'])) { + $request->setParams($bookmarkConfig['current']['request_params']); + } } } diff --git a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/DateRangeTest.php b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/DateRangeTest.php index d8441940ea0af..f666714c592c5 100644 --- a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/DateRangeTest.php +++ b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/DateRangeTest.php @@ -80,9 +80,7 @@ protected function setUp(): void $this->bookmarkManagementMock->expects($this->never())->method('getByIdentifierNamespace'); $this->requestMock = $this->getMockBuilder(RequestInterface::class) - ->addMethods(['isAjax']) ->getMockForAbstractClass(); - $this->requestMock->expects($this->once())->method('isAjax')->willReturn(true); } /** diff --git a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/DateTest.php b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/DateTest.php index 5fa4c5f7a03c1..138abe7c7028d 100644 --- a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/DateTest.php +++ b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/DateTest.php @@ -88,9 +88,7 @@ protected function setUp(): void $this->bookmarkManagementMock->expects($this->never())->method('getByIdentifierNamespace'); $this->requestMock = $this->getMockBuilder(RequestInterface::class) - ->addMethods(['isAjax']) ->getMockForAbstractClass(); - $this->requestMock->expects($this->once())->method('isAjax')->willReturn(true); } /** diff --git a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/InputTest.php b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/InputTest.php index 2a2651a0c0309..536fe98157eb0 100644 --- a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/InputTest.php +++ b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/InputTest.php @@ -80,9 +80,7 @@ protected function setUp(): void $this->bookmarkManagementMock->expects($this->never())->method('getByIdentifierNamespace'); $this->requestMock = $this->getMockBuilder(RequestInterface::class) - ->addMethods(['isAjax']) ->getMockForAbstractClass(); - $this->requestMock->expects($this->once())->method('isAjax')->willReturn(true); } /** diff --git a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/RangeTest.php b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/RangeTest.php index e3b00726d5f48..ac04d4dd6efa5 100644 --- a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/RangeTest.php +++ b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/RangeTest.php @@ -75,9 +75,7 @@ protected function setUp(): void $this->bookmarkManagementMock->expects($this->never())->method('getByIdentifierNamespace'); $this->requestMock = $this->getMockBuilder(RequestInterface::class) - ->addMethods(['isAjax']) ->getMockForAbstractClass(); - $this->requestMock->expects($this->once())->method('isAjax')->willReturn(true); } /** diff --git a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/SelectTest.php b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/SelectTest.php index 1c9e473b46c7c..eb2e816aeb288 100644 --- a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/SelectTest.php +++ b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/SelectTest.php @@ -81,9 +81,7 @@ protected function setUp(): void $this->bookmarkManagementMock->expects($this->never())->method('getByIdentifierNamespace'); $this->requestMock = $this->getMockBuilder(RequestInterface::class) - ->addMethods(['isAjax']) ->getMockForAbstractClass(); - $this->requestMock->expects($this->once())->method('isAjax')->willReturn(true); } /** diff --git a/lib/internal/Magento/Framework/View/Element/UiComponent/Context.php b/lib/internal/Magento/Framework/View/Element/UiComponent/Context.php index 8f980d82d4be0..e562baf83383c 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/Context.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/Context.php @@ -225,7 +225,7 @@ public function getRequestParam($key, $defaultValue = null) */ public function getFiltersParams() { - return $this->getRequestParam(self::FILTER_VAR, []); + return $this->getRequestParam(self::FILTER_VAR); } /** @@ -233,7 +233,7 @@ public function getFiltersParams() */ public function getFilterParam($key, $defaultValue = null) { - $filter = $this->getFiltersParams(); + $filter = $this->getFiltersParams() ?? []; return $filter[$key] ?? $defaultValue; } From 5efe1923f0d15541e97df517242a501aa4b9aa14 Mon Sep 17 00:00:00 2001 From: Denis Kopylov Date: Fri, 23 Oct 2020 17:30:49 +0300 Subject: [PATCH 06/12] [Ui] Refactoring of ui listing reload trigger logic --- .../RemoveCustomerAddressListingBookmark.php | 59 ++++++++++++++++ .../DataProvider/NotificationDataProvider.php | 24 +++++++ .../Component/Filters/Type/AbstractFilter.php | 2 + .../Ui/DataProvider/AbstractDataProvider.php | 30 +++++++- .../Plugin/AddBookmarkAvailabilityFlag.php | 68 +++++++++++++++++++ .../Magento/Ui/Model/BookmarkManagement.php | 5 +- app/code/Magento/Ui/etc/adminhtml/di.xml | 3 + .../Ui/view/base/web/js/grid/provider.js | 22 ++++-- .../UiComponent/DataProvider/DataProvider.php | 29 +++++++- .../DataProvider/DataProviderInterface.php | 16 +++++ .../View/Element/UiComponentFactory.php | 13 ++-- 11 files changed, 251 insertions(+), 20 deletions(-) create mode 100644 app/code/Magento/Customer/Setup/Patch/Data/RemoveCustomerAddressListingBookmark.php create mode 100644 app/code/Magento/Ui/DataProvider/Plugin/AddBookmarkAvailabilityFlag.php diff --git a/app/code/Magento/Customer/Setup/Patch/Data/RemoveCustomerAddressListingBookmark.php b/app/code/Magento/Customer/Setup/Patch/Data/RemoveCustomerAddressListingBookmark.php new file mode 100644 index 0000000000000..32247a7d9aac4 --- /dev/null +++ b/app/code/Magento/Customer/Setup/Patch/Data/RemoveCustomerAddressListingBookmark.php @@ -0,0 +1,59 @@ +moduleDataSetup = $moduleDataSetup; + } + + public static function getDependencies() + { + return []; + } + + public function getAliases() + { + return []; + } + + /** + * Remove customer address listing bookmark + * It's should be reinitialized due to additional request params + * + * @return RemoveCustomerAddressListingBookmark + */ + public function apply() + { + $this->moduleDataSetup->startSetup(); + + $this->moduleDataSetup->deleteTableRow( + $this->moduleDataSetup->getTable('ui_bookmark'), + 'namespace', + 'customer_address_listing' + ); + + $this->moduleDataSetup->endSetup(); + + return $this; + } +} diff --git a/app/code/Magento/ReleaseNotification/Ui/DataProvider/NotificationDataProvider.php b/app/code/Magento/ReleaseNotification/Ui/DataProvider/NotificationDataProvider.php index a1e558a5a2f84..d6cac1f6222f2 100644 --- a/app/code/Magento/ReleaseNotification/Ui/DataProvider/NotificationDataProvider.php +++ b/app/code/Magento/ReleaseNotification/Ui/DataProvider/NotificationDataProvider.php @@ -57,6 +57,13 @@ class NotificationDataProvider implements DataProviderInterface */ private $meta; + /** + * Namespace + * + * @var string + */ + private $namespace; + /** * @param string $name * @param SearchResultInterface $searchResult @@ -211,4 +218,21 @@ public function getSearchResult() { return $this->searchResult; } + + /** + * @inheridoc + */ + public function getNamespace() + { + return $this->namespace; + } + + /** + * @inheridoc + * @param string $namespace + */ + public function setNamespace(string $namespace) + { + $this->namespace = $namespace; + } } diff --git a/app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php b/app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php index 73162aedc06bb..6c73d1f1930e7 100644 --- a/app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php +++ b/app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php @@ -3,6 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); namespace Magento\Ui\Component\Filters\Type; @@ -89,6 +90,7 @@ public function __construct( 'current', $context->getNamespace() ); + if (null !== $bookmark) { $bookmarkConfig = $bookmark->getConfig(); $filterData = $bookmarkConfig['current']['filters']['applied'] ?? []; diff --git a/app/code/Magento/Ui/DataProvider/AbstractDataProvider.php b/app/code/Magento/Ui/DataProvider/AbstractDataProvider.php index 6e4e488619e86..9d87028807193 100644 --- a/app/code/Magento/Ui/DataProvider/AbstractDataProvider.php +++ b/app/code/Magento/Ui/DataProvider/AbstractDataProvider.php @@ -3,12 +3,14 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Ui\DataProvider; use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection; use Magento\Framework\View\Element\UiComponent\DataProvider\DataProviderInterface; - // phpcs:disable Magento2.Classes.AbstractApi +// phpcs:disable Magento2.Classes.AbstractApi + /** * @inheritdoc * @@ -55,6 +57,13 @@ abstract class AbstractDataProvider implements DataProviderInterface, \Countable */ protected $collection; + /** + * Namespace + * + * @var string + */ + protected $namespace; + /** * @param string $name * @param string $primaryFieldName @@ -301,6 +310,23 @@ public function setConfigData($config) */ public function getAllIds() { - return $this->getCollection()->getAllIds(); + return $this->getCollection()->getAllIds(); + } + + /** + * @inheridoc + */ + public function getNamespace() + { + return $this->namespace; + } + + /** + * @inheridoc + * @param string $namespace + */ + public function setNamespace(string $namespace) + { + $this->namespace = $namespace; } } diff --git a/app/code/Magento/Ui/DataProvider/Plugin/AddBookmarkAvailabilityFlag.php b/app/code/Magento/Ui/DataProvider/Plugin/AddBookmarkAvailabilityFlag.php new file mode 100644 index 0000000000000..8ccc51e745859 --- /dev/null +++ b/app/code/Magento/Ui/DataProvider/Plugin/AddBookmarkAvailabilityFlag.php @@ -0,0 +1,68 @@ +bookmarkManagement = $bookmarkManagement; + $this->sanitizer = $sanitizer; + } + + public function afterGetMeta(DataProviderInterface $subject, $meta) + { + $this->modifyProviderConfigData($subject); + + return $meta; + } + + private function modifyProviderConfigData(DataProviderInterface $dataProvider) + { + $configData = $dataProvider->getConfigData(); + if (!isset($configData['component']) + || $configData['component'] !== 'Magento_Ui/js/grid/provider' + ) { + return; + } + + $bookmark = $this->bookmarkManagement->getByIdentifierNamespace( + 'current', + $dataProvider->getNamespace() + ); + + $dataProvider->setConfigData($this->sanitizer->sanitize( + array_replace( + $configData, + [ + 'firstLoad' => $bookmark !== null ? false : true + ] + ) + )); + } +} diff --git a/app/code/Magento/Ui/Model/BookmarkManagement.php b/app/code/Magento/Ui/Model/BookmarkManagement.php index 7a0012a2c1d4f..78e868a65daf9 100644 --- a/app/code/Magento/Ui/Model/BookmarkManagement.php +++ b/app/code/Magento/Ui/Model/BookmarkManagement.php @@ -114,10 +114,11 @@ public function getByIdentifierNamespace($identifier, $namespace) if ($searchResults->getTotalCount() > 0) { $items = $searchResults->getItems(); $this->bookmarkRegistry[$identifier . $namespace] = array_shift($items); - return $this->bookmarkRegistry[$identifier . $namespace]; + } else { + $this->bookmarkRegistry[$identifier . $namespace] = null; } } - return $this->bookmarkRegistry[$identifier . $namespace] ?? null; + return $this->bookmarkRegistry[$identifier . $namespace]; } } diff --git a/app/code/Magento/Ui/etc/adminhtml/di.xml b/app/code/Magento/Ui/etc/adminhtml/di.xml index e220581c42c24..32a05c91cf688 100644 --- a/app/code/Magento/Ui/etc/adminhtml/di.xml +++ b/app/code/Magento/Ui/etc/adminhtml/di.xml @@ -61,4 +61,7 @@ + + + diff --git a/app/code/Magento/Ui/view/base/web/js/grid/provider.js b/app/code/Magento/Ui/view/base/web/js/grid/provider.js index 42657c4d91ae1..03458dd3721fe 100644 --- a/app/code/Magento/Ui/view/base/web/js/grid/provider.js +++ b/app/code/Magento/Ui/view/base/web/js/grid/provider.js @@ -20,6 +20,7 @@ define([ return Element.extend({ defaults: { + initialized: false, firstLoad: true, lastError: false, storageConfig: { @@ -49,10 +50,17 @@ define([ this._super() .initStorage(); - /* Call set data with predefined data for correct rendering action column */ - this.setData(this.data); + if (this.firstLoad) { + this.clearData(); + // Load data when there will + // be no more pending assets. + resolver(this.reload, this); + } else { + /* Call set data with predefined data for correct rendering action column */ + this.setData(this.data); - resolver(this.triggerReloaded, this); + resolver(this.triggerReloaded, this); + } return this; }, @@ -61,7 +69,7 @@ define([ * Trigger reloaded event */ triggerReloaded: function () { - this.firstLoad = false; + this.initialized = true; this.trigger('reloaded'); }, @@ -143,7 +151,7 @@ define([ onParamsChange: function () { // It's necessary to make a reload only // after the initial loading has been made. - if (!this.firstLoad) { + if (this.initialized) { this.reload(); } }, @@ -158,7 +166,7 @@ define([ this.set('lastError', true); - this.firstLoad = false; + this.initialized = true; alert({ content: $t('Something went wrong.') @@ -171,7 +179,7 @@ define([ * @param {Object} data - Retrieved data object. */ onReload: function (data) { - this.firstLoad = false; + this.initialized = true; this.set('lastError', false); diff --git a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProvider.php b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProvider.php index baa4e94eed978..ba5d025a706db 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProvider.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProvider.php @@ -3,6 +3,8 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Framework\View\Element\UiComponent\DataProvider; use Magento\Framework\Api\FilterBuilder; @@ -12,9 +14,6 @@ use Magento\Framework\Api\Search\SearchResultInterface; use Magento\Framework\App\RequestInterface; -/** - * Class DataProvider - */ class DataProvider implements DataProviderInterface { /** @@ -75,6 +74,13 @@ class DataProvider implements DataProviderInterface */ protected $searchCriteria; + /** + * Namespace + * + * @var string + */ + protected $namespace; + /** * @param string $name * @param string $primaryFieldName @@ -312,4 +318,21 @@ public function getSearchResult() { return $this->reporting->search($this->getSearchCriteria()); } + + /** + * @inheridoc + */ + public function getNamespace() + { + return $this->namespace; + } + + /** + * @inheridoc + * @param string $namespace + */ + public function setNamespace(string $namespace) + { + $this->namespace = $namespace; + } } diff --git a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProviderInterface.php b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProviderInterface.php index d939a01648f6b..84e6ead0547ce 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProviderInterface.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProviderInterface.php @@ -3,6 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Framework\View\Element\UiComponent\DataProvider; use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection; @@ -121,4 +122,19 @@ public function getSearchCriteria(); * @return \Magento\Framework\Api\Search\SearchResultInterface */ public function getSearchResult(); + + /** + * Get namespace + * + * @return string + */ + public function getNamespace(); + + /** + * Set namespace + * + * @param string $namespace + * @return void + */ + public function setNamespace(string $namespace); } diff --git a/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php b/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php index 5e1bc93b9c033..b78b3017a88a5 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php @@ -159,9 +159,9 @@ protected function createChildComponent( $components = array_filter($components); $componentArguments['components'] = $components; - /** - * Prevent passing ACL restricted blocks to htmlContent constructor - */ + /** + * Prevent passing ACL restricted blocks to htmlContent constructor + */ if (isset($componentArguments['block']) && !$componentArguments['block']) { return null; } @@ -235,7 +235,7 @@ public function create($identifier, $name = null, array $arguments = []) list($className, $componentArguments) = $this->argumentsResolver($identifier, $rawComponentData); $componentArguments = array_replace_recursive($componentArguments, $arguments); $children = isset($componentArguments['data']['config']['children']) ? - $componentArguments['data']['config']['children'] : []; + $componentArguments['data']['config']['children'] : []; $children = $this->getBundleChildren($children); } @@ -280,7 +280,7 @@ protected function getBundleChildren(array $children = []) foreach ($children as $identifier => $config) { if (!isset($config['componentType'])) { throw new LocalizedException( - new Phrase( + __( 'The "componentType" configuration parameter is required for the "%1" component.', $identifier ) @@ -289,7 +289,7 @@ protected function getBundleChildren(array $children = []) if (!isset($componentArguments['context'])) { throw new LocalizedException( - new \Magento\Framework\Phrase( + __( 'An error occurred with the UI component. Each component needs context. Verify and try again.' ) ); @@ -327,6 +327,7 @@ protected function mergeMetadata($identifier, array $bundleComponents, $reverseM $dataProvider = $this->getDataProvider($identifier, $bundleComponents); if ($dataProvider instanceof DataProviderInterface) { //Dynamic meta from data providers should not contain templates. + $dataProvider->setNamespace($identifier); $metadata = $dataProvider->getMeta(); $metadata = [ $identifier => $this->sanitizer->sanitizeComponentMetadata(['children' => $metadata]) From 471e5ca64685947d5e415a3544efa3d7923f435b Mon Sep 17 00:00:00 2001 From: Denis Kopylov Date: Fri, 23 Oct 2020 17:59:09 +0300 Subject: [PATCH 07/12] Fix unit tests --- .../Ui/Test/Unit/Component/Filters/Type/DateRangeTest.php | 6 ++++-- .../Ui/Test/Unit/Component/Filters/Type/DateTest.php | 6 +++++- .../Ui/Test/Unit/Component/Filters/Type/InputTest.php | 6 +++++- .../Ui/Test/Unit/Component/Filters/Type/RangeTest.php | 6 +++++- .../Ui/Test/Unit/Component/Filters/Type/SelectTest.php | 6 +++++- 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/DateRangeTest.php b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/DateRangeTest.php index f666714c592c5..f56147570e64d 100644 --- a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/DateRangeTest.php +++ b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/DateRangeTest.php @@ -59,7 +59,7 @@ class DateRangeTest extends TestCase protected function setUp(): void { $this->contextMock = $this->getMockForAbstractClass( - \Magento\Framework\View\Element\UiComponent\ContextInterface::class, + UiContext::class, [], '', false @@ -77,7 +77,9 @@ protected function setUp(): void $this->bookmarkManagementMock = $this->getMockForAbstractClass( BookmarkManagementInterface::class ); - $this->bookmarkManagementMock->expects($this->never())->method('getByIdentifierNamespace'); + $this->bookmarkManagementMock->expects($this->once()) + ->method('getByIdentifierNamespace') + ->willReturn(null); $this->requestMock = $this->getMockBuilder(RequestInterface::class) ->getMockForAbstractClass(); diff --git a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/DateTest.php b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/DateTest.php index 138abe7c7028d..9d78d98789298 100644 --- a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/DateTest.php +++ b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/DateTest.php @@ -85,7 +85,6 @@ protected function setUp(): void $this->bookmarkManagementMock = $this->getMockForAbstractClass( BookmarkManagementInterface::class ); - $this->bookmarkManagementMock->expects($this->never())->method('getByIdentifierNamespace'); $this->requestMock = $this->getMockBuilder(RequestInterface::class) ->getMockForAbstractClass(); @@ -99,6 +98,9 @@ protected function setUp(): void public function testGetComponentName() { $this->contextMock->expects(static::never())->method('getProcessor'); + $this->bookmarkManagementMock->expects($this->once()) + ->method('getByIdentifierNamespace') + ->willReturn(null); $date = new Date( $this->contextMock, $this->uiComponentFactory, @@ -153,6 +155,8 @@ public function testPrepare(string $name, bool $showsTime, array $filterData, ?a ->method('getDataProvider') ->willReturn($this->dataProviderMock); + $this->bookmarkManagementMock->expects($this->never())->method('getByIdentifierNamespace'); + if ($expectedCondition !== null) { $this->processFilters($name, $showsTime, $filterData, $expectedCondition, $uiComponent); } diff --git a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/InputTest.php b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/InputTest.php index 536fe98157eb0..71609cf3c56e4 100644 --- a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/InputTest.php +++ b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/InputTest.php @@ -77,7 +77,6 @@ protected function setUp(): void $this->bookmarkManagementMock = $this->getMockForAbstractClass( BookmarkManagementInterface::class ); - $this->bookmarkManagementMock->expects($this->never())->method('getByIdentifierNamespace'); $this->requestMock = $this->getMockBuilder(RequestInterface::class) ->getMockForAbstractClass(); @@ -91,6 +90,9 @@ protected function setUp(): void public function testGetComponentName(): void { $this->contextMock->expects($this->never())->method('getProcessor'); + $this->bookmarkManagementMock->expects($this->once()) + ->method('getByIdentifierNamespace') + ->willReturn(null); $date = new Input( $this->contextMock, $this->uiComponentFactory, @@ -152,6 +154,8 @@ public function testPrepare(string $name, array $filterData, ?array $expectedCon ->method('getDataProvider') ->willReturn($dataProvider); + $this->bookmarkManagementMock->expects($this->never())->method('getByIdentifierNamespace'); + $this->uiComponentFactory->expects($this->any()) ->method('create') ->with($name, Input::COMPONENT, ['context' => $this->contextMock]) diff --git a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/RangeTest.php b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/RangeTest.php index ac04d4dd6efa5..886a85f88da15 100644 --- a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/RangeTest.php +++ b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/RangeTest.php @@ -72,7 +72,6 @@ protected function setUp(): void $this->bookmarkManagementMock = $this->getMockForAbstractClass( BookmarkManagementInterface::class ); - $this->bookmarkManagementMock->expects($this->never())->method('getByIdentifierNamespace'); $this->requestMock = $this->getMockBuilder(RequestInterface::class) ->getMockForAbstractClass(); @@ -86,6 +85,9 @@ protected function setUp(): void public function testGetComponentName() { $this->contextMock->expects($this->never())->method('getProcessor'); + $this->bookmarkManagementMock->expects($this->once()) + ->method('getByIdentifierNamespace') + ->willReturn(null); $range = new Range( $this->contextMock, $this->uiComponentFactory, @@ -155,6 +157,8 @@ public function testPrepare($name, $filterData, $expectedCalls) ->method('addFilter') ->with($filter); + $this->bookmarkManagementMock->expects($this->never())->method('getByIdentifierNamespace'); + $range = new Range( $this->contextMock, $this->uiComponentFactory, diff --git a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/SelectTest.php b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/SelectTest.php index eb2e816aeb288..ef3071d6155d0 100644 --- a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/SelectTest.php +++ b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/SelectTest.php @@ -78,7 +78,6 @@ protected function setUp(): void $this->bookmarkManagementMock = $this->getMockForAbstractClass( BookmarkManagementInterface::class ); - $this->bookmarkManagementMock->expects($this->never())->method('getByIdentifierNamespace'); $this->requestMock = $this->getMockBuilder(RequestInterface::class) ->getMockForAbstractClass(); @@ -92,6 +91,9 @@ protected function setUp(): void public function testGetComponentName() { $this->contextMock->expects($this->never())->method('getProcessor'); + $this->bookmarkManagementMock->expects($this->once()) + ->method('getByIdentifierNamespace') + ->willReturn(null); $date = new Select( $this->contextMock, $this->uiComponentFactory, @@ -155,6 +157,8 @@ public function testPrepare($data, $filterData, $expectedCondition) ->method('getDataProvider') ->willReturn($dataProvider); + $this->bookmarkManagementMock->expects($this->never())->method('getByIdentifierNamespace'); + if ($expectedCondition !== null) { $filterMock = $this->createMock(Filter::class); $this->filterBuilderMock->expects($this->any()) From f83cfb00b0893e620348fe72f9ade534efc99c83 Mon Sep 17 00:00:00 2001 From: Denis Kopylov Date: Sat, 24 Oct 2020 02:39:11 +0300 Subject: [PATCH 08/12] [Ui] Revert changes due to semantic check failure --- .../DataProvider/NotificationDataProvider.php | 24 --------------- .../Ui/DataProvider/AbstractDataProvider.php | 30 ++----------------- .../Plugin/AddBookmarkAvailabilityFlag.php | 3 +- .../UiComponent/DataProvider/DataProvider.php | 29 ++---------------- .../DataProvider/DataProviderInterface.php | 16 ---------- .../View/Element/UiComponentFactory.php | 7 ++++- 6 files changed, 13 insertions(+), 96 deletions(-) diff --git a/app/code/Magento/ReleaseNotification/Ui/DataProvider/NotificationDataProvider.php b/app/code/Magento/ReleaseNotification/Ui/DataProvider/NotificationDataProvider.php index d6cac1f6222f2..a1e558a5a2f84 100644 --- a/app/code/Magento/ReleaseNotification/Ui/DataProvider/NotificationDataProvider.php +++ b/app/code/Magento/ReleaseNotification/Ui/DataProvider/NotificationDataProvider.php @@ -57,13 +57,6 @@ class NotificationDataProvider implements DataProviderInterface */ private $meta; - /** - * Namespace - * - * @var string - */ - private $namespace; - /** * @param string $name * @param SearchResultInterface $searchResult @@ -218,21 +211,4 @@ public function getSearchResult() { return $this->searchResult; } - - /** - * @inheridoc - */ - public function getNamespace() - { - return $this->namespace; - } - - /** - * @inheridoc - * @param string $namespace - */ - public function setNamespace(string $namespace) - { - $this->namespace = $namespace; - } } diff --git a/app/code/Magento/Ui/DataProvider/AbstractDataProvider.php b/app/code/Magento/Ui/DataProvider/AbstractDataProvider.php index 9d87028807193..6e4e488619e86 100644 --- a/app/code/Magento/Ui/DataProvider/AbstractDataProvider.php +++ b/app/code/Magento/Ui/DataProvider/AbstractDataProvider.php @@ -3,14 +3,12 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ - namespace Magento\Ui\DataProvider; use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection; use Magento\Framework\View\Element\UiComponent\DataProvider\DataProviderInterface; -// phpcs:disable Magento2.Classes.AbstractApi - + // phpcs:disable Magento2.Classes.AbstractApi /** * @inheritdoc * @@ -57,13 +55,6 @@ abstract class AbstractDataProvider implements DataProviderInterface, \Countable */ protected $collection; - /** - * Namespace - * - * @var string - */ - protected $namespace; - /** * @param string $name * @param string $primaryFieldName @@ -310,23 +301,6 @@ public function setConfigData($config) */ public function getAllIds() { - return $this->getCollection()->getAllIds(); - } - - /** - * @inheridoc - */ - public function getNamespace() - { - return $this->namespace; - } - - /** - * @inheridoc - * @param string $namespace - */ - public function setNamespace(string $namespace) - { - $this->namespace = $namespace; + return $this->getCollection()->getAllIds(); } } diff --git a/app/code/Magento/Ui/DataProvider/Plugin/AddBookmarkAvailabilityFlag.php b/app/code/Magento/Ui/DataProvider/Plugin/AddBookmarkAvailabilityFlag.php index 8ccc51e745859..ebadfa6846e55 100644 --- a/app/code/Magento/Ui/DataProvider/Plugin/AddBookmarkAvailabilityFlag.php +++ b/app/code/Magento/Ui/DataProvider/Plugin/AddBookmarkAvailabilityFlag.php @@ -47,13 +47,14 @@ 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', - $dataProvider->getNamespace() + $configData['namespace'] ); $dataProvider->setConfigData($this->sanitizer->sanitize( diff --git a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProvider.php b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProvider.php index ba5d025a706db..baa4e94eed978 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProvider.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProvider.php @@ -3,8 +3,6 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -declare(strict_types=1); - namespace Magento\Framework\View\Element\UiComponent\DataProvider; use Magento\Framework\Api\FilterBuilder; @@ -14,6 +12,9 @@ use Magento\Framework\Api\Search\SearchResultInterface; use Magento\Framework\App\RequestInterface; +/** + * Class DataProvider + */ class DataProvider implements DataProviderInterface { /** @@ -74,13 +75,6 @@ class DataProvider implements DataProviderInterface */ protected $searchCriteria; - /** - * Namespace - * - * @var string - */ - protected $namespace; - /** * @param string $name * @param string $primaryFieldName @@ -318,21 +312,4 @@ public function getSearchResult() { return $this->reporting->search($this->getSearchCriteria()); } - - /** - * @inheridoc - */ - public function getNamespace() - { - return $this->namespace; - } - - /** - * @inheridoc - * @param string $namespace - */ - public function setNamespace(string $namespace) - { - $this->namespace = $namespace; - } } diff --git a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProviderInterface.php b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProviderInterface.php index 84e6ead0547ce..d939a01648f6b 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProviderInterface.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProviderInterface.php @@ -3,7 +3,6 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ - namespace Magento\Framework\View\Element\UiComponent\DataProvider; use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection; @@ -122,19 +121,4 @@ public function getSearchCriteria(); * @return \Magento\Framework\Api\Search\SearchResultInterface */ public function getSearchResult(); - - /** - * Get namespace - * - * @return string - */ - public function getNamespace(); - - /** - * Set namespace - * - * @param string $namespace - * @return void - */ - public function setNamespace(string $namespace); } diff --git a/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php b/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php index b78b3017a88a5..cb72dd6aacd5e 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php @@ -327,7 +327,12 @@ protected function mergeMetadata($identifier, array $bundleComponents, $reverseM $dataProvider = $this->getDataProvider($identifier, $bundleComponents); if ($dataProvider instanceof DataProviderInterface) { //Dynamic meta from data providers should not contain templates. - $dataProvider->setNamespace($identifier); + $dataProvider->setConfigData($this->sanitizer->sanitize(array_merge( + $dataProvider->getConfigData(), + [ + 'namespace' => $identifier + ] + ))); $metadata = $dataProvider->getMeta(); $metadata = [ $identifier => $this->sanitizer->sanitizeComponentMetadata(['children' => $metadata]) From 1ced8208bd9175a12560edd69fab7365dc70c6cf Mon Sep 17 00:00:00 2001 From: Denis Kopylov Date: Sat, 24 Oct 2020 02:45:33 +0300 Subject: [PATCH 09/12] Fix static tests --- app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php | 1 + .../Magento/Framework/View/Element/UiComponent/Context.php | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php b/app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php index 6c73d1f1930e7..38c59a322bfd7 100644 --- a/app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php +++ b/app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php @@ -16,6 +16,7 @@ use Magento\Framework\Api\FilterBuilder; use Magento\Ui\Component\Filters\FilterModifier; +//phpcs:disable Magento2.Classes.AbstractApi /** * Abstract class AbstractFilter * @api diff --git a/lib/internal/Magento/Framework/View/Element/UiComponent/Context.php b/lib/internal/Magento/Framework/View/Element/UiComponent/Context.php index e562baf83383c..57d7ca52ff756 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/Context.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/Context.php @@ -3,6 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Framework\View\Element\UiComponent; use Magento\Framework\App\ObjectManager; @@ -386,7 +387,7 @@ public function getUrl($route = '', $params = []) * @param UiComponentInterface $component * @return void */ - protected function prepareDataSource(array & $data, UiComponentInterface $component) + protected function prepareDataSource(array &$data, UiComponentInterface $component) { $childComponents = $component->getChildComponents(); if (!empty($childComponents)) { From d1c151a1548d911f97d7048525118bd9c37bd7c5 Mon Sep 17 00:00:00 2001 From: Denis Kopylov Date: Sat, 24 Oct 2020 03:15:50 +0300 Subject: [PATCH 10/12] Fix integration tests --- .../ui_component/customer_address_listing.xml | 12 +++++------- .../Form/Modifier/Data/AssociatedProductsTest.php | 5 ++++- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/code/Magento/Customer/view/adminhtml/ui_component/customer_address_listing.xml b/app/code/Magento/Customer/view/adminhtml/ui_component/customer_address_listing.xml index fa4aae0cf7e3b..5d91af4e8e480 100644 --- a/app/code/Magento/Customer/view/adminhtml/ui_component/customer_address_listing.xml +++ b/app/code/Magento/Customer/view/adminhtml/ui_component/customer_address_listing.xml @@ -37,13 +37,11 @@ - - - - ${ $.provider }:params.parent_id - - - + + + ${ $.provider }:params.parent_id + + diff --git a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Ui/DataProvider/Product/Form/Modifier/Data/AssociatedProductsTest.php b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Ui/DataProvider/Product/Form/Modifier/Data/AssociatedProductsTest.php index ea96514ebde32..a28df3edbce04 100644 --- a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Ui/DataProvider/Product/Form/Modifier/Data/AssociatedProductsTest.php +++ b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Ui/DataProvider/Product/Form/Modifier/Data/AssociatedProductsTest.php @@ -103,7 +103,10 @@ public function testAddManuallyConfigurationsWithNotFilterableInGridAttribute(): 'test_configurable' ], ]); - $context = $this->objectManager->create(ContextInterface::class, ['request' => $request]); + $context = $this->objectManager->create(ContextInterface::class, [ + 'request' => $request, + 'namespace' => ConfigurablePanel::ASSOCIATED_PRODUCT_LISTING + ]); /** @var UiComponentFactory $uiComponentFactory */ $uiComponentFactory = $this->objectManager->get(UiComponentFactory::class); $uiComponent = $uiComponentFactory->create( From 7d6bedbfba28691f78b3085d411e2331661c07a9 Mon Sep 17 00:00:00 2001 From: Denis Kopylov Date: Sat, 24 Oct 2020 04:44:17 +0300 Subject: [PATCH 11/12] Fix static tests --- .../Data/RemoveCustomerAddressListingBookmark.php | 12 ++++++++++++ .../Ui/Component/Filters/Type/AbstractFilter.php | 5 +++++ .../Plugin/AddBookmarkAvailabilityFlag.php | 14 ++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/app/code/Magento/Customer/Setup/Patch/Data/RemoveCustomerAddressListingBookmark.php b/app/code/Magento/Customer/Setup/Patch/Data/RemoveCustomerAddressListingBookmark.php index 32247a7d9aac4..1ce4ea4553035 100644 --- a/app/code/Magento/Customer/Setup/Patch/Data/RemoveCustomerAddressListingBookmark.php +++ b/app/code/Magento/Customer/Setup/Patch/Data/RemoveCustomerAddressListingBookmark.php @@ -18,6 +18,8 @@ class RemoveCustomerAddressListingBookmark implements DataPatchInterface private $moduleDataSetup; /** + * RemoveCustomerAddressListingBookmark constructor + * * @param ModuleDataSetupInterface $moduleDataSetup */ public function __construct( @@ -26,11 +28,21 @@ public function __construct( $this->moduleDataSetup = $moduleDataSetup; } + /** + * Retrieve patch dependencies + * + * @return array|string[] + */ public static function getDependencies() { return []; } + /** + * Retrieve patch aliases + * + * @return array|string[] + */ public function getAliases() { return []; diff --git a/app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php b/app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php index 38c59a322bfd7..bc0a1fb6a1a2a 100644 --- a/app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php +++ b/app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php @@ -17,6 +17,7 @@ use Magento\Ui\Component\Filters\FilterModifier; //phpcs:disable Magento2.Classes.AbstractApi + /** * Abstract class AbstractFilter * @api @@ -57,6 +58,8 @@ abstract class AbstractFilter extends AbstractComponent protected $filterModifier; /** + * AbstractFilter constructor + * * @param ContextInterface $context * @param UiComponentFactory $uiComponentFactory * @param FilterBuilder $filterBuilder @@ -122,6 +125,8 @@ public function getComponentName() } /** + * Prepare filter component + * * @inheridoc */ public function prepare() diff --git a/app/code/Magento/Ui/DataProvider/Plugin/AddBookmarkAvailabilityFlag.php b/app/code/Magento/Ui/DataProvider/Plugin/AddBookmarkAvailabilityFlag.php index ebadfa6846e55..c84e4e400ef8c 100644 --- a/app/code/Magento/Ui/DataProvider/Plugin/AddBookmarkAvailabilityFlag.php +++ b/app/code/Magento/Ui/DataProvider/Plugin/AddBookmarkAvailabilityFlag.php @@ -24,6 +24,8 @@ class AddBookmarkAvailabilityFlag private $sanitizer; /** + * AddBookmarkAvailabilityFlag constructor + * * @param BookmarkManagementInterface $bookmarkManagement * @param Sanitizer $sanitizer */ @@ -35,6 +37,13 @@ public function __construct( $this->sanitizer = $sanitizer; } + /** + * Modify provider configuration and return meta + * + * @param DataProviderInterface $subject + * @param $meta + * @return mixed + */ public function afterGetMeta(DataProviderInterface $subject, $meta) { $this->modifyProviderConfigData($subject); @@ -42,6 +51,11 @@ public function afterGetMeta(DataProviderInterface $subject, $meta) return $meta; } + /** + * Modify provider configuration + * + * @param DataProviderInterface $dataProvider + */ private function modifyProviderConfigData(DataProviderInterface $dataProvider) { $configData = $dataProvider->getConfigData(); From fe12c88b9268f7f5decb9155041541ec65b96e12 Mon Sep 17 00:00:00 2001 From: Denis Kopylov Date: Sat, 24 Oct 2020 14:53:34 +0300 Subject: [PATCH 12/12] Update customer address grid rendering logic --- ...dRequestParamToDataProviderRendererUrl.php | 101 ++++++++++++++++++ .../RemoveCustomerAddressListingBookmark.php | 71 ------------ .../Magento/Customer/etc/adminhtml/di.xml | 7 +- .../ui_component/customer_address_listing.xml | 8 +- .../view/base/ui_component/customer_form.xml | 1 - .../Component/Filters/Type/AbstractFilter.php | 37 +++---- .../Plugin/AddBookmarkAvailabilityFlag.php | 4 +- 7 files changed, 126 insertions(+), 103 deletions(-) create mode 100644 app/code/Magento/Customer/Model/Plugin/Customer/DataProviderWithDefaultAddresses/AddRequestParamToDataProviderRendererUrl.php delete mode 100644 app/code/Magento/Customer/Setup/Patch/Data/RemoveCustomerAddressListingBookmark.php diff --git a/app/code/Magento/Customer/Model/Plugin/Customer/DataProviderWithDefaultAddresses/AddRequestParamToDataProviderRendererUrl.php b/app/code/Magento/Customer/Model/Plugin/Customer/DataProviderWithDefaultAddresses/AddRequestParamToDataProviderRendererUrl.php new file mode 100644 index 0000000000000..acc84d3dcff04 --- /dev/null +++ b/app/code/Magento/Customer/Model/Plugin/Customer/DataProviderWithDefaultAddresses/AddRequestParamToDataProviderRendererUrl.php @@ -0,0 +1,101 @@ +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; + } +} diff --git a/app/code/Magento/Customer/Setup/Patch/Data/RemoveCustomerAddressListingBookmark.php b/app/code/Magento/Customer/Setup/Patch/Data/RemoveCustomerAddressListingBookmark.php deleted file mode 100644 index 1ce4ea4553035..0000000000000 --- a/app/code/Magento/Customer/Setup/Patch/Data/RemoveCustomerAddressListingBookmark.php +++ /dev/null @@ -1,71 +0,0 @@ -moduleDataSetup = $moduleDataSetup; - } - - /** - * Retrieve patch dependencies - * - * @return array|string[] - */ - public static function getDependencies() - { - return []; - } - - /** - * Retrieve patch aliases - * - * @return array|string[] - */ - public function getAliases() - { - return []; - } - - /** - * Remove customer address listing bookmark - * It's should be reinitialized due to additional request params - * - * @return RemoveCustomerAddressListingBookmark - */ - public function apply() - { - $this->moduleDataSetup->startSetup(); - - $this->moduleDataSetup->deleteTableRow( - $this->moduleDataSetup->getTable('ui_bookmark'), - 'namespace', - 'customer_address_listing' - ); - - $this->moduleDataSetup->endSetup(); - - return $this; - } -} diff --git a/app/code/Magento/Customer/etc/adminhtml/di.xml b/app/code/Magento/Customer/etc/adminhtml/di.xml index 9f207ea8bebd1..8aaa50577decc 100644 --- a/app/code/Magento/Customer/etc/adminhtml/di.xml +++ b/app/code/Magento/Customer/etc/adminhtml/di.xml @@ -6,13 +6,13 @@ */ --> - + Magento\Customer\Model\Backend\Customer - + @@ -41,4 +41,7 @@ CustomerGridCollectionReporting + + + diff --git a/app/code/Magento/Customer/view/adminhtml/ui_component/customer_address_listing.xml b/app/code/Magento/Customer/view/adminhtml/ui_component/customer_address_listing.xml index 5d91af4e8e480..fb42a2c5a0787 100644 --- a/app/code/Magento/Customer/view/adminhtml/ui_component/customer_address_listing.xml +++ b/app/code/Magento/Customer/view/adminhtml/ui_component/customer_address_listing.xml @@ -36,13 +36,7 @@ - - - - ${ $.provider }:params.parent_id - - - + diff --git a/app/code/Magento/Customer/view/base/ui_component/customer_form.xml b/app/code/Magento/Customer/view/base/ui_component/customer_form.xml index 065d87792665f..dbf862356bad2 100644 --- a/app/code/Magento/Customer/view/base/ui_component/customer_form.xml +++ b/app/code/Magento/Customer/view/base/ui_component/customer_form.xml @@ -11,7 +11,6 @@ customer_form.customer_form_data_source Customer Information - true diff --git a/app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php b/app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php index bc0a1fb6a1a2a..1dfada38273ad 100644 --- a/app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php +++ b/app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php @@ -88,30 +88,27 @@ public function __construct( ->get(BookmarkManagementInterface::class); $request = $request ?: ObjectManager::getInstance()->get(RequestInterface::class); - $filterData = $this->getContext()->getFiltersParams(); - if (null === $filterData) { - $bookmark = $bookmarkManagement->getByIdentifierNamespace( - 'current', - $context->getNamespace() - ); + $this->filterData = $this->getContext()->getFiltersParams(); + if ($this->filterData !== null) { + return; + } - if (null !== $bookmark) { - $bookmarkConfig = $bookmark->getConfig(); - $filterData = $bookmarkConfig['current']['filters']['applied'] ?? []; + $bookmark = $bookmarkManagement->getByIdentifierNamespace( + 'current', + $context->getNamespace() + ); - $request->setParams( - [ - 'paging' => $bookmarkConfig['current']['paging'] ?? [] - ] - ); + if ($bookmark !== null) { + $bookmarkConfig = $bookmark->getConfig(); + $this->filterData = $bookmarkConfig['current']['filters']['applied'] ?? []; - if (isset($bookmarkConfig['current']['request_params'])) { - $request->setParams($bookmarkConfig['current']['request_params']); - } - } + $request->setParams( + [ + 'paging' => $bookmarkConfig['current']['paging'] ?? [], + 'search' => $bookmarkConfig['current']['search']['value'] ?? '' + ] + ); } - - $this->filterData = $filterData; } /** diff --git a/app/code/Magento/Ui/DataProvider/Plugin/AddBookmarkAvailabilityFlag.php b/app/code/Magento/Ui/DataProvider/Plugin/AddBookmarkAvailabilityFlag.php index c84e4e400ef8c..d6ba75a84f107 100644 --- a/app/code/Magento/Ui/DataProvider/Plugin/AddBookmarkAvailabilityFlag.php +++ b/app/code/Magento/Ui/DataProvider/Plugin/AddBookmarkAvailabilityFlag.php @@ -41,10 +41,10 @@ public function __construct( * Modify provider configuration and return meta * * @param DataProviderInterface $subject - * @param $meta + * @param array $meta * @return mixed */ - public function afterGetMeta(DataProviderInterface $subject, $meta) + public function afterGetMeta(DataProviderInterface $subject, array $meta) { $this->modifyProviderConfigData($subject);