Skip to content

Issue 30286 - Fix widget layout update removal button to work for multiple layout updates #30992

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

Conversation

zaximus84
Copy link

Description (*)

When adding a widget in the Magento admin (Content > Widgets), the remove button (trash can icon) on layout updates doesn't work for any layout update but the first. This is because the current code relies on \Magento\Framework\View\Helper\SecureHtmlRenderer::renderEventListenerAsTag to generate the js click listeners, and that uses document.querySelector to establish the element. The element selector passed to querySelector is not unique because it comes from javascript templating, and it always selects the first matching element on the page. Every time the "Add Layout Button" is clicked, another layout row is added, but the click handler is just added to the first row again.

Using a widget block (PHP) class in combination with javascript templating to produce the click listeners doesn't work for this scenario, so this PR updates the remove buttons to use a standard onclick attribute. It also updates the new widget MFTF test to add and remove layout rows and confirm the resulting counts.

Fixed Issues (if relevant)

  1. Fixes Can't remove seconde added Layout Update #30286

Manual testing scenarios (*)

  1. In admin, go to Content > Widgets and click New Widget.
  2. Select any widget type and design theme and click Continue.
  3. Under Layout Updates, click Add Layout Update multiple times.
  4. Click the trash can icon on any of the resulting rows and confirm that the intended row is removed.
  5. Give special attention to removing a row other than the first when there are multiples (that was the original failure which prompted this PR).

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)

Zach Nanninga added 2 commits November 18, 2020 13:27
…ock to directly in the template to prevent inaccurate js element selection in SecureHtmlRenderer event listener generation.
@m2-assistant
Copy link

m2-assistant bot commented Nov 19, 2020

Hi @zaximus84. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

❗ 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

You can find more information about the builds here

ℹ️ Please run only needed test builds instead of all when developing. Please run all test builds before sending your PR for review.

For more details, please, review the Magento Contributor Guide documentation.

⚠️ According to the Magento Contribution requirements, all Pull Requests must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 You can find the schedule on the Magento Community Calendar page.

📞 The triage of Pull Requests happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket.

🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

@m2-community-project m2-community-project bot added Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Severity: S2 Major restrictions or short-term circumventions are required until a fix is available. labels Nov 19, 2020
@magento-engcom-team magento-engcom-team added Partner: Blue Acorn iCi partners-contribution Pull Request is created by Magento Partner labels Nov 19, 2020
@mrtuvn
Copy link
Contributor

mrtuvn commented Nov 20, 2020

good catch!. Description clearly to me. But seem a reason previously core team remove this code onclick in template that lead to this issue
@zaximus84
Previous commit related with "MC-29420: Remove event handlers from CE" made by @svitja
svitja
CC @rogyar can you see this

Oh my! Magento now handle click event in php code instead html like before. Maybe this code line here will affect to all element have click event (button, anchor)
https://github.com/magento/magento2/blob/2.4-develop/lib/internal/Magento/Framework/View/Helper/SecureHtmlRenderer.php#L98

@gabrieldagama
Copy link
Contributor

@magento run all tests

@bhaveshpp
Copy link

Magento 2.4

I am facing the same issue in my project.
The console is clear there is no error in the console
https://drive.google.com/file/d/1EEhxFnAlPUu_-4srQGkQOP_iVtlLxIm6/view

Did anyone found any solution to this issue?

Thank you.

@zaximus84
Copy link
Author

@bhaveshpp
I have a PR open for this, though there's apparently a question about whether this would undo a change intentionally made in the past. You can apply my changes as a patch and see if they work for you without side effects:

https://patch-diff.githubusercontent.com/raw/magento/magento2/pull/30992.diff

layout.phtml is the only file that really needs to be updated to fix the issue.

@rogyar
Copy link
Contributor

rogyar commented Nov 26, 2020

@magento run all tests

@rogyar
Copy link
Contributor

rogyar commented Nov 27, 2020

@magento run Functional Tests B2B

@mrtuvn
Copy link
Contributor

mrtuvn commented Nov 28, 2020

@rogyar i think this patch from @zaximus84 is better fix and simplest . Can we have further check and approve this soon ?

@rogyar rogyar added Auto-Tests: Covered All changes in Pull Request is covered by auto-tests Award: MFTF test coverage labels Dec 1, 2020
Copy link
Contributor

@rogyar rogyar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The failing tests are not related to the current changeset

@magento-engcom-team
Copy link
Contributor

Hi @rogyar, thank you for the review.
ENGCOM-8502 has been created to process this Pull Request

@engcom-Bravo engcom-Bravo self-assigned this Dec 1, 2020
@engcom-Bravo
Copy link
Contributor

✔️ QA Passed

Manual testing scenario

  1. From Admin, go to Content - Widget click Add Widget
  2. Select, for example,
  • Type - CMS Page Link
  • Design Theme - Magento Luma
    Click Continue
  1. Using Add Layout Update button, Add 3 Layout Updates, for example
  2. Try to remove the added Layouts using the Remove Layout Update (basket)

BEFORE applying changes provided in this PR, only the first Layout Update could be removed
Peek 2020-12-01 15-23

AFTER switching to the PR, all the Layout Updates can be removed
Peek 2020-12-01 15-43_after

The Widget can be saved successfully
widget_save

@engcom-Foxtrot
Copy link
Contributor

@magento run all tests

magento-engcom-team pushed a commit that referenced this pull request Dec 21, 2020
@magento-engcom-team magento-engcom-team merged commit 1113db5 into magento:2.4-develop Dec 21, 2020
@m2-assistant
Copy link

m2-assistant bot commented Dec 21, 2020

Hi @zaximus84, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Frontend Auto-Tests: Covered All changes in Pull Request is covered by auto-tests Award: MFTF test coverage Component: Widget Partner: Blue Acorn iCi partners-contribution Pull Request is created by Magento Partner Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: accept QA: Added to Regression Scope Scenario was analysed and added to Regression Testing Scope Release Line: 2.4 Severity: S2 Major restrictions or short-term circumventions are required until a fix is available.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't remove seconde added Layout Update
8 participants