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

feat: allows an admin_css: tuple in RTEConfig for a list of CSS files only to be loaded into the admin for the editor #49

Merged
merged 5 commits into from
Jan 4, 2025

Conversation

fsbraun
Copy link
Member

@fsbraun fsbraun commented Jan 4, 2025

…iles only to be loaded into the admin for the editor

Summary by Sourcery

New Features:

  • Added an admin_css tuple to RTEConfig to specify CSS files to be loaded only in the admin interface.

…iles only to be loaded into the admin for the editor
Copy link
Contributor

sourcery-ai bot commented Jan 4, 2025

Reviewer's Guide by Sourcery

This pull request introduces the ability to specify CSS files to be loaded only in the admin interface for the text editor. It adds a new admin_css tuple to the RTEConfig class and updates the TextEditorWidget to include these CSS files when rendering in the admin. The existing CSS loading logic is modified to accommodate this new feature, and tests are updated to ensure proper functionality.

Sequence diagram for CSS loading in admin interface

sequenceDiagram
    participant Admin as Admin Interface
    participant Widget as TextEditorWidget
    participant Config as RTEConfig

    Admin->>Widget: Request widget rendering
    Widget->>Config: Get editor config
    Config-->>Widget: Return config with css and admin_css
    alt add_admin_css is True
        Widget->>Widget: Combine regular CSS with admin CSS
    end
    Widget-->>Admin: Return rendered widget with combined CSS
Loading

Class diagram showing RTEConfig and TextEditorWidget changes

classDiagram
    class RTEConfig {
        +str name
        +str config
        +Iterable[str] js
        +dict css
        +dict admin_css
        +bool inline_editing
        +bool child_plugin_support
        +__init__(name, config, js, css, admin_css, inline_editing, child_plugin_support)
    }

    class TextEditorWidget {
        +bool add_admin_css
        +media()
        +__init__(configuration, action_token, revert_on_cancel, body_css_classes, add_admin_css)
    }

    note for RTEConfig "Added admin_css parameter"
    note for TextEditorWidget "Added add_admin_css flag"
Loading

File-Level Changes

Change Details Files
Added admin_css to RTEConfig to allow specifying CSS files to be loaded only in the admin.
  • Added admin_css parameter to the __init__ method of the RTEConfig class.
  • Initialized the admin_css attribute in the __init__ method.
  • Updated the get_editor_base_config function to include the admin_css parameter with a default value for the TipTap editor.
djangocms_text/editors.py
Modified TextEditorWidget to include admin-specific CSS files.
  • Added add_admin_css parameter to the __init__ method of the TextEditorWidget class.
  • Added logic in the media property to conditionally include CSS files specified in admin_css if add_admin_css is True.
djangocms_text/widgets.py
Updated formfield method of HTMLField to use the updated TextEditorWidget.
  • Modified the formfield method to instantiate TextEditorWidget with add_admin_css=True when used in the admin interface.
djangocms_text/fields.py
Updated get_editor_widget method of TextPlugin to use the updated TextEditorWidget.
  • Modified the get_editor_widget method to instantiate TextEditorWidget with add_admin_css=True.
djangocms_text/cms_plugins.py

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.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a 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. You can also use
    this command to specify where the summary should be inserted.

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

@fsbraun fsbraun changed the title feat: allows an admin_css: tuple in RTEConfig for a list of CSS f… feat: allows an admin_css: tuple in RTEConfig for a list of CSS files only to be loaded into the admin for the editor Jan 4, 2025
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 @fsbraun - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

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.

djangocms_text/editors.py Outdated Show resolved Hide resolved
Copy link

codecov bot commented Jan 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.22%. Comparing base (8426926) to head (bd03ec8).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #49      +/-   ##
==========================================
+ Coverage   81.20%   81.22%   +0.02%     
==========================================
  Files          17       17              
  Lines         931      932       +1     
  Branches      104      104              
==========================================
+ Hits          756      757       +1     
  Misses        132      132              
  Partials       43       43              

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

@fsbraun
Copy link
Member Author

fsbraun commented Jan 4, 2025

@sourcery-ai review

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 @fsbraun - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

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.

@fsbraun fsbraun merged commit 182fabf into main Jan 4, 2025
31 checks passed
@fsbraun fsbraun deleted the feat/allow-admin-css branch January 4, 2025 23:58
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.

1 participant