Skip to content
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

Used In Content Entities Filters #1593

Merged
merged 15 commits into from
Jul 20, 2020
Merged
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,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="AdminMediaGalleryCatalogUiUsedInCategoryFilterTest">
<annotations>
<features value="AdminMediaGalleryUsedInCategoryFilter"/>
<useCaseId value="https://github.com/magento/adobe-stock-integration/issues/1168"/>
<title value="Used in categories filter"/>
<stories value="Story 58: User sees entities where asset is used in" />
<testCaseId value="https://studio.cucumber.io/projects/131313/test-plan/folders/1320712/scenarios/4951846"/>
<description value="User filters assets used in categories"/>
<severity value="CRITICAL"/>
<group value="media_gallery_ui"/>
</annotations>
<before>
<createData entity="SimpleSubCategory" stepKey="category"/>
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
</before>
<after>
<actionGroup ref="ResetAdminDataGridToDefaultViewActionGroup" stepKey="resetAdminDataGridToDefaultView"/>
<actionGroup ref="AdminEnhancedMediaGalleryViewImageDetails" stepKey="viewContentImageDetails"/>
<actionGroup ref="AdminEnhancedMediaGalleryImageDetailsDeleteActionGroup" stepKey="deleteCategoryImage"/>
<deleteData createDataKey="category" stepKey="deleteCategory"/>
</after>
<actionGroup ref="AdminOpenCategoryPageActionGroup" stepKey="openCategoryPage"/>
<actionGroup ref="AdminCategoriesOpenCategoryActionGroup" stepKey="openCategory">
<argument name="category" value="$$category$$"/>
</actionGroup>
<actionGroup ref="AdminOpenMediaGalleryFromCategoryImageUploaderActionGroup" stepKey="openMediaGalleryFromImageUploader"/>
<actionGroup ref="AdminEnhancedMediaGalleryUploadImageActionGroup" stepKey="uploadImage">
<argument name="image" value="ImageUpload"/>
</actionGroup>
<actionGroup ref="AdminMediaGalleryClickImageInGridActionGroup" stepKey="selectContentImageInGrid">
<argument name="imageName" value="{{ImageUpload.file}}"/>
</actionGroup>
<actionGroup ref="AdminMediaGalleryClickAddSelectedActionGroup" stepKey="clickAddSelectedContentImage"/>
<actionGroup ref="AdminSaveCategoryFormActionGroup" stepKey="saveCategoryForm"/>
<actionGroup ref="AdminOpenMediaGalleryFromCategoryImageUploaderActionGroup" stepKey="openMediaGalleryFromImageUploaderAgain"/>
<actionGroup ref="AdminEnhancedMediaGalleryExpandFilterActionGroup" stepKey="expandFilters"/>
<actionGroup ref="AdminEnhancedMediaGallerySelectUsedInFilterActionGroup" stepKey="setUsedInFilter">
<argument name="filterName" value="Used in Categories"/>
<argument name="optionName" value="$$category.name$$"/>
</actionGroup>
<actionGroup ref="AdminEnhancedMediaGalleryApplyFiltersActionGroup" stepKey="applyFilters"/>
<actionGroup ref="AdminMediaGalleryAssertImageInGridActionGroup" stepKey="assertImageInGrid">
<argument name="image" value="ImageUpload"/>
</actionGroup>
</test>
</tests>
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="AdminMediaGalleryCatalogUiUsedInProductFilterTest">
<annotations>
<features value="AdminMediaGalleryUsedInProductsFilter"/>
<useCaseId value="https://github.com/magento/adobe-stock-integration/issues/1168"/>
<title value="Used in products filter"/>
<stories value="Story 58: User sees entities where asset is used in" />
<testCaseId value="https://studio.cucumber.io/projects/131313/test-plan/folders/1320712/scenarios/4951848"/>
<description value="User filters assets used in products"/>
<severity value="CRITICAL"/>
<group value="media_gallery_ui"/>
</annotations>
<before>
<magentoCLI command="config:set cms/wysiwyg/enabled enabled" stepKey="enableWYSIWYG"/>
<createData entity="SimpleSubCategory" stepKey="category"/>
<createData entity="SimpleProduct" stepKey="product">
<requiredEntity createDataKey="category"/>
</createData>
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
</before>
<after>
<magentoCLI command="config:set cms/wysiwyg/enabled disabled" stepKey="disableWYSIWYG"/>
<actionGroup ref="AdminEnhancedMediaGalleryImageDeleteActionGroup" stepKey="deleteAsset"/>
<actionGroup ref="ResetAdminDataGridToDefaultViewActionGroup" stepKey="resetAdminDataGridToDefaultView"/>
<deleteData createDataKey="product" stepKey="deleteProduct"/>
<deleteData createDataKey="category" stepKey="deleteCategory"/>
</after>
<actionGroup ref="SearchForProductOnBackendActionGroup" stepKey="searchProduct">
<argument name="product" value="$$product$$"/>
</actionGroup>
<actionGroup ref="OpenEditProductOnBackendActionGroup" stepKey="openEditProduct">
<argument name="product" value="$$product$$"/>
</actionGroup>
<click selector="{{AdminProductFormSection.contentTab}}" stepKey="clickContentTab"/>
<waitForElementVisible selector="{{CatalogWYSIWYGSection.TinyMCE4}}" stepKey="waitForTinyMCE4" />
<click selector="{{CatalogWYSIWYGSection.InsertImageIcon}}" stepKey="clickInsertImageIcon" />
<waitForPageLoad stepKey="waitForPageLoad" />
<actionGroup ref="ClickBrowseBtnOnUploadPopupActionGroup" stepKey="clickBrowserBtn"/>
<actionGroup ref="AdminEnhancedMediaGalleryUploadImageActionGroup" stepKey="uploadImage">
<argument name="image" value="ImageUpload"/>
</actionGroup>
<actionGroup ref="AdminMediaGalleryClickImageInGridActionGroup" stepKey="selectContentImageInGrid">
<argument name="imageName" value="{{ImageUpload.file}}"/>
</actionGroup>
<actionGroup ref="AdminMediaGalleryClickAddSelectedActionGroup" stepKey="clickAddSelectedContentImage"/>
<actionGroup ref="AdminMediaGalleryClickOkButtonTinyMce4ActionGroup" stepKey="clickOkButton"/>
<actionGroup ref="SaveProductFormActionGroup" stepKey="saveProduct"/>
<actionGroup ref="AdminOpenStandaloneMediaGalleryActionGroup" stepKey="openStandaloneMediaGallery"/>
<actionGroup ref="AdminEnhancedMediaGalleryExpandFilterActionGroup" stepKey="expandFilters"/>
<actionGroup ref="AdminEnhancedMediaGallerySelectUsedInFilterActionGroup" stepKey="setUsedInFilter">
<argument name="filterName" value="Used in Products"/>
<argument name="optionName" value="$$product.name$$"/>
</actionGroup>
<actionGroup ref="AdminEnhancedMediaGalleryApplyFiltersActionGroup" stepKey="applyFilters"/>
<actionGroup ref="AdminMediaGalleryAssertImageInGridActionGroup" stepKey="assertImageInGrid">
<argument name="image" value="ImageUpload"/>
</actionGroup>
</test>
</tests>
27 changes: 27 additions & 0 deletions MediaGalleryCatalogUi/etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<virtualType name="Magento\MediaGalleryUi\Model\Api\SearchCriteria\CollectionProcessor\FilterProcessor">
<arguments>
<argument name="customFilters" xsi:type="array">
<item name="product_id" xsi:type="object">Magento\MediaGalleryCatalogUi\Model\SearchCriteria\CollectionProcessor\FilterProcessor\Product</item>
<item name="category_id" xsi:type="object">Magento\MediaGalleryCatalogUi\Model\SearchCriteria\CollectionProcessor\FilterProcessor\Category</item>
</argument>
</arguments>
</virtualType>
<virtualType name="Magento\MediaGalleryCatalogUi\Model\SearchCriteria\CollectionProcessor\FilterProcessor\Product" type="Magento\MediaGalleryUi\Model\SearchCriteria\CollectionProcessor\FilterProcessor\Entity">
<arguments>
<argument name="entityType" xsi:type="string">catalog_product</argument>
</arguments>
</virtualType>
<virtualType name="Magento\MediaGalleryCatalogUi\Model\SearchCriteria\CollectionProcessor\FilterProcessor\Category" type="Magento\MediaGalleryUi\Model\SearchCriteria\CollectionProcessor\FilterProcessor\Entity">
<arguments>
<argument name="entityType" xsi:type="string">catalog_category</argument>
</arguments>
</virtualType>
</config>
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<listingToolbar name="listing_top">
<filters name="listing_filters">
<filterSelect
name="product_id"
provider="${ $.parentName }"
sortOrder="100"
component="Magento_Catalog/js/components/product-ui-select"
template="ui/grid/filters/elements/ui-select">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filterOptions" xsi:type="boolean">true</item>
<item name="searchOptions" xsi:type="boolean">true</item>
<item name="filterPlaceholder" xsi:type="string" translate="true">Product Name or SKU</item>
<item name="emptyOptionsHtml" xsi:type="string" translate="true">Start typing to find products</item>
<item name="missingValuePlaceholder" xsi:type="string" translate="true">Product with ID: %s doesn\'t exist</item>
<item name="isDisplayMissingValuePlaceholder" xsi:type="boolean">true</item>
<item name="isDisplayEmptyPlaceholder" xsi:type="boolean">true</item>
<item name="isRemoveSelectedIcon" xsi:type="boolean">true</item>
<item name="filterRateLimitMethod" xsi:type="string">notifyWhenChangesStop</item>
<item name="levelsVisibility" xsi:type="number">1</item>
<item name="searchUrl" xsi:type="url" path="catalog/product/search"/>
<item name="validationUrl" xsi:type="url" path="catalog/product/getSelected"/>
</item>
</argument>
<settings>
<label translate="true">Used in Products</label>
<dataScope>product_id</dataScope>
</settings>
</filterSelect>
<filterSelect
name="category_id"
provider="${ $.parentName }"
sortOrder="110"
component="Magento_Catalog/js/components/new-category"
template="ui/grid/filters/elements/ui-select">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filterOptions" xsi:type="boolean">true</item>
<item name="levelsVisibility" xsi:type="number">1</item>
<item name="filterPlaceholder" xsi:type="string" translate="true">Category Name</item>
<item name="emptyOptionsHtml" xsi:type="string" translate="true">Start typing to find categories</item>
</item>
</argument>
<settings>
<options class="Magento\Catalog\Ui\Component\Product\Form\Categories\Options"/>
<label translate="true">Used in Categories</label>
<dataScope>category_id</dataScope>
<listens>
<link name="${ $.namespace }.${ $.namespace }:responseData">setParsed</link>
</listens>
</settings>
</filterSelect>
</filters>
</listingToolbar>
</listing>
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<listingToolbar name="listing_top">
<filters name="listing_filters">
<filterSelect
name="product_id"
provider="${ $.parentName }"
sortOrder="100"
component="Magento_Catalog/js/components/product-ui-select"
template="ui/grid/filters/elements/ui-select">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filterOptions" xsi:type="boolean">true</item>
<item name="searchOptions" xsi:type="boolean">true</item>
<item name="filterPlaceholder" xsi:type="string" translate="true">Product Name or SKU</item>
<item name="emptyOptionsHtml" xsi:type="string" translate="true">Start typing to find products</item>
<item name="missingValuePlaceholder" xsi:type="string" translate="true">Product with ID: %s doesn\'t exist</item>
<item name="isDisplayMissingValuePlaceholder" xsi:type="boolean">true</item>
<item name="isDisplayEmptyPlaceholder" xsi:type="boolean">true</item>
<item name="isRemoveSelectedIcon" xsi:type="boolean">true</item>
<item name="filterRateLimitMethod" xsi:type="string">notifyWhenChangesStop</item>
<item name="levelsVisibility" xsi:type="number">1</item>
<item name="searchUrl" xsi:type="url" path="catalog/product/search"/>
<item name="validationUrl" xsi:type="url" path="catalog/product/getSelected"/>
</item>
</argument>
<settings>
<label translate="true">Used in Products</label>
<dataScope>product_id</dataScope>
</settings>
</filterSelect>
<filterSelect
name="category_id"
provider="${ $.parentName }"
sortOrder="110"
component="Magento_Catalog/js/components/new-category"
template="ui/grid/filters/elements/ui-select">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filterOptions" xsi:type="boolean">true</item>
<item name="levelsVisibility" xsi:type="number">1</item>
<item name="filterPlaceholder" xsi:type="string" translate="true">Category Name</item>
<item name="emptyOptionsHtml" xsi:type="string" translate="true">Start typing to find categories</item>
</item>
</argument>
<settings>
<options class="Magento\Catalog\Ui\Component\Product\Form\Categories\Options"/>
<label translate="true">Used in Categories</label>
<dataScope>category_id</dataScope>
<listens>
<link name="${ $.namespace }.${ $.namespace }:responseData">setParsed</link>
</listens>
</settings>
</filterSelect>
</filters>
</listingToolbar>
</listing>
97 changes: 97 additions & 0 deletions MediaGalleryCmsUi/Controller/Adminhtml/Block/Search.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\MediaGalleryCmsUi\Controller\Adminhtml\Block;

use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Cms\Api\BlockRepositoryInterface;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Framework\Controller\Result\JsonFactory;
use Magento\Framework\Controller\ResultInterface;

/**
* Controller to search blocks for ui-select component
*/
class Search extends Action implements HttpGetActionInterface
{
/**
* Authorization level of a basic admin session
*
* @see _isAllowed()
*/
const ADMIN_RESOURCE = 'Magento_Cms::block';

/**
* @var JsonFactory
*/
private $resultJsonFactory;

/**
* @var BlockRepositoryInterface
*/
private $blockRepository;

/**
* @var SearchCriteriaBuilder
*/
private $searchCriteriaBuilder;

/**
* @param JsonFactory $resultFactory
* @param BlockRepositoryInterface $blockRepository
* @param SearchCriteriaBuilder $searchCriteriaBuilder
* @param Context $context
*/
public function __construct(
JsonFactory $resultFactory,
BlockRepositoryInterface $blockRepository,
SearchCriteriaBuilder $searchCriteriaBuilder,
Context $context
) {
$this->resultJsonFactory = $resultFactory;
$this->blockRepository = $blockRepository;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
parent::__construct($context);
}

/**
* Execute pages search.
*
* @return ResultInterface
*/
public function execute() : ResultInterface
{
$searchKey = $this->getRequest()->getParam('searchKey');
$currentPage = (int) $this->getRequest()->getParam('page');
$limit = (int) $this->getRequest()->getParam('limit');

$searchResult = $this->blockRepository->getList(
$this->searchCriteriaBuilder->addFilter('title', '%' . $searchKey . '%', 'like')
->setCurrentPage($currentPage)
->setPageSize($limit)
->create()
);

$options = [];
foreach ($searchResult->getItems() as $block) {
$id = $block->getId();
$options[$id] = [
'value' => $id,
'label' => $block->getTitle(),
'is_active' => $block->isActive(),
'optgroup' => false
];
}

return $this->resultJsonFactory->create()->setData([
'options' => $options,
'total' => $searchResult->getTotalCount()
]);
}
}
Loading