Skip to content

Conversation

@h-peters
Copy link

@h-peters h-peters commented Nov 11, 2025

This PR updates the _inline_admin_selector to handle both tabular and stacked inlines. Otherwise empty form rows for stacked inlines will not be found and the editor will be initialized twice.

Summary by Sourcery

Fix inline editor initialization by refining selectors to handle both tabular and stacked inlines and exclude empty templates

Bug Fixes:

  • Update inline admin selector to target non-empty tabular and stacked inlines
  • Fix logic to skip initialization of empty inline form templates

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Nov 11, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Refines the CMS editor's inline admin selector to properly target tabular and stacked inlines, ensures empty form templates are detected correctly, and updates admin_selector assignment to prevent double initialization.

Flow diagram for updated inline admin selector logic

flowchart TD
    A["DOMContentLoaded event"] --> B["Check for empty form templates"]
    B -->|If found| C["Update _admin_selector to refined _inline_admin_selector"]
    B -->|If not found| D["Keep _admin_selector as default"]
    C --> E["Call initAll()"]
    D --> E
Loading

File-Level Changes

Change Details Files
Enhanced inline admin selector to handle tabular and stacked inlines and exclude empty forms
  • Replaced generic .form-row selector with distinct data-inline-type="tabular" and "stacked" selectors
  • Appended this._admin_selector to each sub-selector and filtered out .empty-form rows
private/js/cms.editor.js
Refined empty-form detection and admin_selector assignment
  • Switched to document.querySelector(this._admin_selector)?.closest('.empty-form') for accurate empty template detection
  • Simplified assignment by setting this._admin_selector directly to _inline_admin_selector instead of adding :not(.empty-form)
private/js/cms.editor.js

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov
Copy link

codecov bot commented Nov 11, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.39%. Comparing base (df1b635) to head (a6c5793).
⚠️ Report is 33 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #134      +/-   ##
==========================================
- Coverage   81.61%   79.39%   -2.23%     
==========================================
  Files          14       14              
  Lines         941      956      +15     
  Branches      110      111       +1     
==========================================
- Hits          768      759       -9     
- Misses        130      150      +20     
- Partials       43       47       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@fsbraun
Copy link
Member

fsbraun commented Nov 11, 2025

@h-peters Thanks for this PR.

Can you first clarify the issue? How do these changes solve it?

Can you check out the integration tests run specifically to ensure that adding inline fields works?

Those seem to start to fail with this PR (on some combinations).

@h-peters
Copy link
Author

@fsbraun Of course. Sorry, this is my first PR 😃.

If you use StackedInline instead of TabularInline, the editor will also be instantiated on the empty form. When you click the add-row button, the editor is also instantiated, so there are two editors in the DOM. This is because the selector used to check the empty form does not match the html structure of StackedInline. It differs from TabularInline.

In my change i use document.querySelector(this._admin_selector)?.closest('.empty-form') to check if the editor is in an empty-form. If so, set this._admin_selector = this._inline_admin_selector; where this._inline_admin_selector = 'body.change-form [data-inline-type="tabular"] .form-row:not(.empty-form) ' + this._admin_selector + ', body.change-form [data-inline-type="stacked"] .inline-related:not(.empty-form) ' + this._admin_selector;.

I hope this makes it clearer.

As for the integration tests, I can’t quite figure out why some of them are failing. I ran them locally and they were successful. Do you have any idea?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants