Skip to content

Keep grid filters when adding a partially deselected selection (#38582) - #41122

Open
lbajsarowicz wants to merge 1 commit into
magento:2.4-developfrom
lbajsarowicz:fix/38582-insert-listing-exclude-mode-filters
Open

Keep grid filters when adding a partially deselected selection (#38582)#41122
lbajsarowicz wants to merge 1 commit into
magento:2.4-developfrom
lbajsarowicz:fix/38582-insert-listing-exclude-mode-filters

Conversation

@lbajsarowicz

Copy link
Copy Markdown
Contributor

Description (*)

When a grid is embedded in a form through insertListing (Related Products, Up-Sells and Cross-Sells being the most visible case), selecting rows and then deselecting a few of them switches the selections provider into exclude mode: the selection is expressed as "everything matching the current filters, except these ids".

Magento\Ui\view\base\web\js\form\components\insert-listing.js::updateFromServerData() builds the request for the selected rows and, whenever there is a non-empty id list, clears the filtering state that was just imported from the grid:

_.extend(selectionsData, this.params || {}, selections.params);

if (selections[itemsType] && selections[itemsType].length) {
    selectionsData.filters = {};                       // <- applied grid filters dropped
    selectionsData['filters_modifier'] = {};
    selectionsData['filters_modifier'][this.indexField] = {
        'condition_type': filterType,                  // 'nin' in exclude mode
        value: selections[itemsType]
    };
}

selectionsData.paging = {
    notLimits: 1
};

In include mode this is harmless — the explicit in list fully constrains the result. In exclude mode the only remaining constraint is nin on the handful of excluded ids, so together with paging.notLimits = 1 the modal requests the entire product collection minus the excluded ids instead of the filtered subset. On a catalog with thousands of products the response is huge, the grid never finishes rendering and the product form appears to hang.

This also explains the two workarounds reported in the issue: adding all filtered rows without deselecting any keeps excluded empty so the branch is never entered, and raising the page limit so that every selected row is present on the current page makes canUpdateFromClientData() return true, skipping the server request entirely.

The fix keeps the applied filters in exclude mode and leaves include-mode behaviour untouched.

Fixed Issues (if relevant)

  1. Fixes Related/up-sells/cross-sells products are not being added and product edit page gets break #38582 — Related/up-sells/cross-sells products are not being added and product edit page gets break

Manual testing scenarios (*)

  1. Install a Magento instance with a large catalog (4000+ products, e.g. setup/performance-toolkit/profiles/ce/medium.xml).
  2. Open any product in the admin panel and go to Related Products, Up-Sells, and Cross-SellsAdd Related Products.
  3. Apply a filter that matches ~60 products.
  4. Click Select All, then deselect a few products from the filtered list.
  5. Click Add Selected Products.

Expected result: only the remaining filtered products are added and the form stays responsive.
Actual result before the fix: the request returns the whole catalog minus the deselected ids and the product edit page hangs.

The same scenario applies to Up-Sells and Cross-Sells, and to any other insertListing-based modal.

Questions or comments

Automated coverage is added in dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/form/components/insert-listing.test.js, asserting that the request payload keeps the grid filters in exclude mode and still resets them in include mode. Verified that the new exclude-mode expectation fails against the unpatched component.

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

…to#38582)

Insert-listing's updateFromServerData() cleared the applied grid filters
unconditionally. In exclude mode the request is constrained only by a 'nin'
condition on the excluded ids, so dropping the filters made the modal request
the entire collection (with paging.notLimits = 1) instead of the filtered
subset. On large catalogs this froze the product form when adding related,
up-sell or cross-sell products after deselecting a few filtered rows.

Filters are now preserved in exclude mode and still reset in include mode,
where the explicit 'in' list fully constrains the result.

Fixes magento#38582
@m2-assistant

m2-assistant Bot commented Aug 13, 2026

Copy link
Copy Markdown

Hi @lbajsarowicz. Thank you for your contribution!
Here are some useful tips on how you can test your changes using Magento test environment.
❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names.

Allowed build names are:
  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

You can find more information about the builds here
ℹ️ Run only required test builds during development. Run all test builds before sending your pull request for review.


For more details, review the Code Contributions documentation.
Join Magento Community Engineering Slack and ask your questions in #github channel.

@lbajsarowicz

Copy link
Copy Markdown
Contributor Author

@magento run all tests

@engcom-Bravo engcom-Bravo added the Priority: P2 A defect with this priority could have functionality issues which are not to expectations. label Aug 14, 2026
@github-project-automation github-project-automation Bot moved this to Pending Review in Pull Requests Dashboard Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: pending review

Projects

Status: Pending Review

Development

Successfully merging this pull request may close these issues.

Related/up-sells/cross-sells products are not being added and product edit page gets break

2 participants