- 
                Notifications
    You must be signed in to change notification settings 
- Fork 9.4k
Implemented UrlFilterApplier component #28932
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
          
     Merged
      
      
            magento-engcom-team
  merged 16 commits into
  magento:2.4-develop
from
gabrieldagama:url-filter-applier-component
  
      
      
   
  Jul 16, 2020 
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            16 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      be428f7
              
                Added url filter applier
              
              
                 984dab1
              
                Simplified PR to a JS only approach
              
              
                 5531f50
              
                Added jasmine tests
              
              
                 1574740
              
                Added url filter applier to product grid
              
              
                 607aed6
              
                Added url filter applier to cms grids
              
              
                 22c2be9
              
                Added mftf for product grid
              
              
                 58158aa
              
                Added cms page mftf tests
              
              
                 1467c6e
              
                Added mftf block test
              
              
                 273607c
              
                Using existing action group
              
              
                 8660c73
              
                Fixed static tests
              
              
                 a8c3f67
              
                Fixed static tests
              
              
                 96e6752
              
                Added block names
              
              
                 c77d812
              
                Implemented suggestions and fixed tests
              
              
                 03b3ef5
              
                Fix static test
              
              
                 b4b16ff
              
                Added escape for block argument
              
              
                 8af0f46
              
                add testCaseId
              
              
                engcom-Charlie File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
        
          
          
            36 changes: 36 additions & 0 deletions
          
          36 
        
  app/code/Magento/Catalog/Test/Mftf/Test/AdminProductGridUrlFilterApplierTest.xml
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| <?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="AdminProductGridUrlFilterApplierTest"> | ||
| <annotations> | ||
| <features value="Catalog"/> | ||
| <stories value="Filter product using GET URL parameter"/> | ||
| <title value="Verify that filter is applied on product grid when filters parameter is set on url"/> | ||
| <description value="Accessing product grid url with filters parameter"/> | ||
| <severity value="MAJOR"/> | ||
| <testCaseId value="https://studio.cucumber.io/projects/131313/test-plan/folders/1320712/scenarios/4931106"/> | ||
| <group value="product"/> | ||
| </annotations> | ||
| <before> | ||
| <actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/> | ||
| <createData entity="simpleProductWithShortNameAndSku" stepKey="createSimpleProduct"/> | ||
| </before> | ||
| <after> | ||
| <actionGroup ref="ClearFiltersAdminDataGridActionGroup" stepKey="clearGridFilter"/> | ||
| <deleteData createDataKey="createSimpleProduct" stepKey="deleteProduct"/> | ||
| <actionGroup ref="AdminLogoutActionGroup" stepKey="logoutOfAdmin"/> | ||
| </after> | ||
| <amOnPage url="{{AdminProductIndexPage.url}}?filters[name]=$$createSimpleProduct.name$$" stepKey="navigateToProductGridWithFilters"/> | ||
| <waitForPageLoad stepKey="waitForProductGrid"/> | ||
| <see selector="{{AdminProductGridSection.productGridNameProduct($$createSimpleProduct.name$$)}}" userInput="$$createSimpleProduct.name$$" stepKey="seeProduct"/> | ||
| <seeElement selector="{{AdminProductGridFilterSection.enabledFilters}}" stepKey="seeEnabledFilters"/> | ||
| <see selector="{{AdminProductGridFilterSection.enabledFilters}}" userInput="Name: $$createSimpleProduct.name$$" stepKey="seeProductNameFilter"/> | ||
| </test> | ||
| </tests> | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
          
            17 changes: 17 additions & 0 deletions
          
          17 
        
  app/code/Magento/Catalog/view/adminhtml/templates/product/grid/url_filter_applier.phtml
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <?php | ||
| /** | ||
| * Copyright © Magento, Inc. All rights reserved. | ||
| * See COPYING.txt for license details. | ||
| */ | ||
|  | ||
| /** @var $block \Magento\Backend\Block\Template */ | ||
| ?> | ||
| <script type="text/x-magento-init"> | ||
| { | ||
| "*": { | ||
| "Magento_Ui/js/grid/url-filter-applier": { | ||
| "listingNamespace": "product_listing" | ||
| } | ||
| } | ||
| } | ||
| </script> | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
          
            36 changes: 36 additions & 0 deletions
          
          36 
        
  app/code/Magento/Cms/Test/Mftf/Test/AdminCmsBlockGridUrlFilterApplierTest.xml
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| <?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="AdminCmsBlockGridUrlFilterApplierTest"> | ||
| <annotations> | ||
| <features value="Cms"/> | ||
| <stories value="Filter CMS block using GET URL parameter"/> | ||
| <title value="Verify that filter is applied on block grid when filters parameter is set on url"/> | ||
| <description value="Accessing block grid url with filters parameter"/> | ||
| <severity value="MAJOR"/> | ||
| <testCaseId value="https://studio.cucumber.io/projects/131313/test-plan/folders/1320712/scenarios/4931106"/> | ||
| <group value="Cms"/> | ||
| </annotations> | ||
| <before> | ||
| <actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/> | ||
| <createData entity="Sales25offBlock" stepKey="createBlock"/> | ||
| </before> | ||
| <after> | ||
| <actionGroup ref="ClearFiltersAdminDataGridActionGroup" stepKey="clearGridFilter"/> | ||
| <deleteData createDataKey="createBlock" stepKey="deletePage"/> | ||
| <actionGroup ref="AdminLogoutActionGroup" stepKey="logoutOfAdmin"/> | ||
| </after> | ||
| <amOnPage url="{{CmsBlocksPage.url}}?filters[title]=$$createBlock.title$$" stepKey="navigateToBlockGridWithFilters"/> | ||
| <waitForPageLoad stepKey="waitForBlockGrid"/> | ||
| <see selector="{{BlockPageActionsSection.blockGridRowByTitle($$createBlock.title$$)}}" userInput="$$createBlock.title$$" stepKey="seeBlock"/> | ||
| <seeElement selector="{{BlockPageActionsSection.activeFilterDiv}}" stepKey="seeEnabledFilters"/> | ||
| <see selector="{{BlockPageActionsSection.activeFilterDiv}}" userInput="Title: $$createBlock.title$$" stepKey="seeBlockTitleFilter"/> | ||
| </test> | ||
| </tests> | 
        
          
          
            36 changes: 36 additions & 0 deletions
          
          36 
        
  app/code/Magento/Cms/Test/Mftf/Test/AdminCmsPageGridUrlFilterApplierTest.xml
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| <?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="AdminCmsPageGridUrlFilterApplierTest"> | ||
| <annotations> | ||
| <features value="CmsPage"/> | ||
| <stories value="Filter CMS page using GET URL parameter"/> | ||
| <title value="Verify that filter is applied on page grid when filters parameter is set on url"/> | ||
| <description value="Accessing page grid url with filters parameter"/> | ||
| <severity value="MAJOR"/> | ||
| <testCaseId value="https://studio.cucumber.io/projects/131313/test-plan/folders/1320712/scenarios/4931106"/> | ||
| <group value="Cms"/> | ||
| </annotations> | ||
| <before> | ||
| <actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/> | ||
| <createData entity="_defaultCmsPage" stepKey="createPage"/> | ||
| </before> | ||
| <after> | ||
| <actionGroup ref="ClearFiltersAdminDataGridActionGroup" stepKey="clearGridFilter"/> | ||
| <deleteData createDataKey="createPage" stepKey="deletePage"/> | ||
| <actionGroup ref="AdminLogoutActionGroup" stepKey="logoutOfAdmin"/> | ||
| </after> | ||
| <amOnPage url="{{CmsPagesPage.url}}?filters[title]=$$createPage.title$$" stepKey="navigateToPageGridWithFilters"/> | ||
| <waitForPageLoad stepKey="waitForPageGrid"/> | ||
| <see selector="{{CmsPagesPageActionsSection.pagesGridRowByTitle($$createPage.title$$)}}" userInput="$$createPage.title$$" stepKey="seePage"/> | ||
| <seeElement selector="{{CmsPagesPageActionsSection.activeFilter}}" stepKey="seeEnabledFilters"/> | ||
| <see selector="{{CmsPagesPageActionsSection.activeFilter}}" userInput="Title: $$createPage.title$$" stepKey="seePageTitleFilter"/> | ||
| </test> | ||
| </tests> | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
          
            18 changes: 18 additions & 0 deletions
          
          18 
        
  app/code/Magento/Cms/view/adminhtml/templates/url_filter_applier.phtml
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <?php | ||
| /** | ||
| * Copyright © Magento, Inc. All rights reserved. | ||
| * See COPYING.txt for license details. | ||
| */ | ||
|  | ||
| /** @var $block \Magento\Backend\Block\Template */ | ||
| /** @var \Magento\Framework\Escaper $escaper */ | ||
| ?> | ||
| <script type="text/x-magento-init"> | ||
| { | ||
| "*": { | ||
| "Magento_Ui/js/grid/url-filter-applier": { | ||
| "listingNamespace": "<?= $escaper->escapeJs($block->getListingNamespace()) ?>" | ||
| } | ||
| } | ||
| } | ||
| </script> | 
        
          
          
            80 changes: 80 additions & 0 deletions
          
          80 
        
  app/code/Magento/Ui/view/base/web/js/grid/url-filter-applier.js
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| /** | ||
| * Copyright © Magento, Inc. All rights reserved. | ||
| * See COPYING.txt for license details. | ||
| */ | ||
|  | ||
| define([ | ||
| 'uiComponent', | ||
| 'underscore' | ||
| ], function (Component, _) { | ||
| 'use strict'; | ||
|  | ||
| return Component.extend({ | ||
| defaults: { | ||
| listingNamespace: null, | ||
| filterProvider: 'componentType = filters, ns = ${ $.listingNamespace }', | ||
| filterKey: 'filters', | ||
| searchString: location.search, | ||
| modules: { | ||
| filterComponent: '${ $.filterProvider }' | ||
| } | ||
| }, | ||
|  | ||
| /** | ||
| * Init component | ||
| * | ||
| * @return {exports} | ||
| */ | ||
| initialize: function () { | ||
| this._super(); | ||
| this.apply(); | ||
|  | ||
| return this; | ||
| }, | ||
|  | ||
| /** | ||
| * Apply filter | ||
| */ | ||
| apply: function () { | ||
| var urlFilter = this.getFilterParam(this.searchString); | ||
|  | ||
| if (_.isUndefined(this.filterComponent())) { | ||
| setTimeout(function () { | ||
| this.apply(); | ||
| }.bind(this), 100); | ||
|  | ||
| return; | ||
| } | ||
|  | ||
| if (Object.keys(urlFilter).length) { | ||
| this.filterComponent().setData(urlFilter, false); | ||
| this.filterComponent().apply(); | ||
| } | ||
| }, | ||
|  | ||
| /** | ||
| * Get filter param from url | ||
| * | ||
| * @returns {Object} | ||
| */ | ||
| getFilterParam: function (url) { | ||
| var searchString = decodeURI(url), | ||
| itemArray; | ||
|  | ||
| return _.chain(searchString.slice(1).split('&')) | ||
| .map(function (item) { | ||
| if (item && item.search(this.filterKey) !== -1) { | ||
| itemArray = item.split('='); | ||
|  | ||
| itemArray[0] = itemArray[0].replace(this.filterKey, '') | ||
| .replace(/[\[\]]/g, ''); | ||
|  | ||
| return itemArray; | ||
| } | ||
| }.bind(this)) | ||
| .compact() | ||
| .object() | ||
| .value(); | ||
| } | ||
| }); | ||
| }); | ||
        
          
          
            67 changes: 67 additions & 0 deletions
          
          67 
        
  dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/grid/url-filter-applier.test.js
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /** | ||
| * Copyright © Magento, Inc. All rights reserved. | ||
| * See COPYING.txt for license details. | ||
| */ | ||
|  | ||
| /*eslint max-nested-callbacks: 0*/ | ||
| define([ | ||
| 'Magento_Ui/js/grid/url-filter-applier' | ||
| ], function (UrlFilterApplier) { | ||
| 'use strict'; | ||
|  | ||
| describe('Magento_Ui/js/grid/url-filter-applier', function () { | ||
| var urlFilterApplierObj, | ||
| filterComponentMock = { | ||
| setData: jasmine.createSpy(), | ||
| apply: jasmine.createSpy() | ||
| }; | ||
|  | ||
| beforeEach(function () { | ||
| urlFilterApplierObj = new UrlFilterApplier({}); | ||
| urlFilterApplierObj.filterComponent = jasmine.createSpy().and.returnValue(filterComponentMock); | ||
| }); | ||
|  | ||
| describe('"getFilterParam" method', function () { | ||
| it('return object from url with a simple filters parameter', function () { | ||
| var urlSearch = '?filters[name]=test'; | ||
|  | ||
| expect(urlFilterApplierObj.getFilterParam(urlSearch)).toEqual({ | ||
| 'name': 'test' | ||
| }); | ||
| }); | ||
| it('return object from url with multiple filters parameter', function () { | ||
| var urlSearch = '?filters[name]=test&filters[qty]=1'; | ||
|  | ||
| expect(urlFilterApplierObj.getFilterParam(urlSearch)).toEqual({ | ||
| 'name': 'test', | ||
| 'qty': '1' | ||
| }); | ||
| }); | ||
| it('return object from url with multiple filters parameter and another parameter', function () { | ||
| var urlSearch = '?filters[name]=test&filters[qty]=1&anotherparam=1'; | ||
|  | ||
| expect(urlFilterApplierObj.getFilterParam(urlSearch)).toEqual({ | ||
| 'name': 'test', | ||
| 'qty': '1' | ||
| }); | ||
| }); | ||
| it('return object from url with another parameter', function () { | ||
| var urlSearch = '?anotherparam=1'; | ||
|  | ||
| expect(urlFilterApplierObj.getFilterParam(urlSearch)).toEqual({}); | ||
| }); | ||
| }); | ||
|  | ||
| describe('"apply" method', function () { | ||
| it('applies url filter on filter component', function () { | ||
| urlFilterApplierObj.searchString = '?filters[name]=test&filters[qty]=1'; | ||
| urlFilterApplierObj.apply(); | ||
| expect(urlFilterApplierObj.filterComponent().setData).toHaveBeenCalledWith({ | ||
| 'name': 'test', | ||
| 'qty': '1' | ||
| }, false); | ||
| expect(urlFilterApplierObj.filterComponent().apply).toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | 
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.