diff --git a/AdobeStockAsset/Model/GetAssetList.php b/AdobeStockAsset/Model/GetAssetList.php index 248472442eca..9c1e09c91ac2 100644 --- a/AdobeStockAsset/Model/GetAssetList.php +++ b/AdobeStockAsset/Model/GetAssetList.php @@ -74,7 +74,7 @@ public function execute(SearchCriteriaInterface $searchCriteria): SearchResultIn } catch (AuthenticationException $exception) { throw new LocalizedException( __( - 'Failed to authenticate to Adobe Stock API. Please correct the API credentials in ' + 'Failed to authenticate to Adobe Stock API.
Please correct the API credentials in ' . 'Configuration → System → Adobe Stock Integration.', $this->url->getUrl('adminhtml/system_config/edit/section/system') ) diff --git a/AdobeStockImageAdminUi/Model/Listing/DataProvider.php b/AdobeStockImageAdminUi/Model/Listing/DataProvider.php index b7c2b824e4ba..c2b1900591b5 100644 --- a/AdobeStockImageAdminUi/Model/Listing/DataProvider.php +++ b/AdobeStockImageAdminUi/Model/Listing/DataProvider.php @@ -28,16 +28,16 @@ class DataProvider extends \Magento\Framework\View\Element\UiComponent\DataProvi /** * DataProvider constructor. - * @param string $name - * @param string $primaryFieldName - * @param string $requestFieldName - * @param ReportingInterface $reporting + * @param string $name + * @param string $primaryFieldName + * @param string $requestFieldName + * @param ReportingInterface $reporting * @param SearchCriteriaBuilder $searchCriteriaBuilder - * @param RequestInterface $request - * @param FilterBuilder $filterBuilder + * @param RequestInterface $request + * @param FilterBuilder $filterBuilder * @param GetImageListInterface $getImageList - * @param array $meta - * @param array $data + * @param array $meta + * @param array $data */ public function __construct( string $name, @@ -67,8 +67,22 @@ public function __construct( /** * @inheritdoc - * - * @throws LocalizedException + */ + public function getData() + { + try { + return $this->searchResultToOutput($this->getSearchResult()); + } catch (LocalizedException $exception) { + return [ + 'items' => [], + 'totalRecords' => 0, + 'errorMessage' => $exception->getMessage() + ]; + } + } + + /** + * @inheritdoc */ public function getSearchResult(): SearchResultInterface { diff --git a/AdobeStockImageAdminUi/Test/Mftf/ActionGroup/AdminOpenMediaGalleryForPageNoEditorActionGroup.xml b/AdobeStockImageAdminUi/Test/Mftf/ActionGroup/AdminOpenMediaGalleryForPageNoEditorActionGroup.xml index a577963c973a..efc8ccfb2625 100644 --- a/AdobeStockImageAdminUi/Test/Mftf/ActionGroup/AdminOpenMediaGalleryForPageNoEditorActionGroup.xml +++ b/AdobeStockImageAdminUi/Test/Mftf/ActionGroup/AdminOpenMediaGalleryForPageNoEditorActionGroup.xml @@ -14,7 +14,7 @@ - + diff --git a/AdobeStockImageAdminUi/Test/Unit/Model/Listing/DataProviderTest.php b/AdobeStockImageAdminUi/Test/Unit/Model/Listing/DataProviderTest.php index 21db34858520..639eb38b28cb 100644 --- a/AdobeStockImageAdminUi/Test/Unit/Model/Listing/DataProviderTest.php +++ b/AdobeStockImageAdminUi/Test/Unit/Model/Listing/DataProviderTest.php @@ -14,6 +14,7 @@ use Magento\Framework\Api\Search\SearchCriteria; use Magento\Framework\Api\Search\SearchCriteriaBuilder; use Magento\Framework\Api\Search\SearchResultInterface; +use Magento\Framework\Exception\LocalizedException; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -113,6 +114,33 @@ public function testGetData(array $itemsData): void $this->assertEquals($data, $this->dataProvider->getData()); } + /** + * Verify LocalizedExceptions messages are returned in errorMessage data node + */ + public function testGetDataException(): void + { + $searchCriteria = $this->createMock(SearchCriteria::class); + $searchCriteria->expects($this->once()) + ->method('setRequestName') + ->with('adobe_stock_images_listing_data_source'); + + $this->searchCriteriaBuilder->expects($this->once()) + ->method('create') + ->willReturn($searchCriteria); + + $this->getImageListMock->expects($this->once()) + ->method('execute') + ->willThrowException(new LocalizedException(__('Localized error'))); + + $data = [ + 'items' => [], + 'totalRecords' => 0, + 'errorMessage' => 'Localized error' + ]; + + $this->assertEquals($data, $this->dataProvider->getData()); + } + /** * @param array $itemsData * @return SearchResultInterface|MockObject diff --git a/AdobeUi/view/adminhtml/web/css/source/_module.less b/AdobeUi/view/adminhtml/web/css/source/_module.less index ede28f92bc9d..464ce1022d46 100644 --- a/AdobeUi/view/adminhtml/web/css/source/_module.less +++ b/AdobeUi/view/adminhtml/web/css/source/_module.less @@ -12,7 +12,8 @@ margin: @admin__masonry_grid_image__space/2 -(@admin__masonry_grid_image__space/2); overflow: hidden; - .no-data-message-container { + .no-data-message-container, + .error-message-container { font-size: @data-grid__no-records__font-size; padding: @data-grid__no-records__padding; text-align: center; diff --git a/AdobeUi/view/adminhtml/web/js/components/grid/masonry.js b/AdobeUi/view/adminhtml/web/js/components/grid/masonry.js index 56c9259cb573..5ceaeb4696f2 100644 --- a/AdobeUi/view/adminhtml/web/js/components/grid/masonry.js +++ b/AdobeUi/view/adminhtml/web/js/components/grid/masonry.js @@ -13,7 +13,8 @@ define([ defaults: { template: 'Magento_AdobeUi/grid/masonry', imports: { - rows: '${ $.provider }:data.items' + rows: '${ $.provider }:data.items', + errorMessage: '${ $.provider }:data.errorMessage' }, listens: { 'rows': 'initComponent' @@ -57,7 +58,8 @@ define([ initObservable: function () { this._super() .observe([ - 'rows' + 'rows', + 'errorMessage' ]); return this; @@ -245,6 +247,15 @@ define([ */ hasData: function () { return !!this.rows() && !!this.rows().length; + }, + + /** + * Returns error message returned by the data provider + * + * @returns {String|null} + */ + getErrorMessage: function () { + return this.errorMessage(); } }); }); diff --git a/AdobeUi/view/adminhtml/web/template/grid/masonry.html b/AdobeUi/view/adminhtml/web/template/grid/masonry.html index 9510495b4e9a..fdf13f777a7c 100644 --- a/AdobeUi/view/adminhtml/web/template/grid/masonry.html +++ b/AdobeUi/view/adminhtml/web/template/grid/masonry.html @@ -8,7 +8,10 @@
-
+
+
+ +