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

10896 Duplicate component shortcut #12320

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

gersona
Copy link
Collaborator

@gersona gersona commented Aug 23, 2024

Proposed changes

  • A New "Duplicate Component" was added to the Manage menu in component details page
  • Additional attributes are copied from the source when duplicating : agreement", "merge_style", "commit_message", "add_message", "delete_message", "merge_message", "addon_message", "pull_message",
Capture d’écran 2024-08-23 à 09 42 01

Checklist

  • Lint and unit tests pass locally with my changes.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added documentation to describe my feature.
  • I have squashed my commits into logic units.
  • I have described the changes in the commit messages.

Other information

fixes #10896

Summary by CodeRabbit

  • New Features

    • Introduced a "Duplicate Component" option in the menu for easier component replication.
    • Added functionality to duplicate components directly from the editing interface for users with appropriate permissions.
  • Improvements

    • Enhanced commit messages for translation operations to provide clearer context and information.
    • Updated forms to allow for more flexible data entry by permitting certain fields to be left blank.
  • Tests

    • Improved test coverage for component creation and category management, ensuring robustness in functionality.

@gersona gersona changed the title 10896 duplicate component 10896 Duplicate component shortcut Aug 23, 2024
Copy link

codecov bot commented Aug 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.15%. Comparing base (69c4f6d) to head (40e65ba).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main   #12320       +/-   ##
===========================================
+ Coverage   24.20%   91.15%   +66.94%     
===========================================
  Files         589      590        +1     
  Lines       60190    60216       +26     
  Branches     9530     9535        +5     
===========================================
+ Hits        14569    54887    +40318     
+ Misses      45487     3687    -41800     
- Partials      134     1642     +1508     
Files Coverage Δ
weblate/trans/forms.py 90.12% <ø> (+52.20%) ⬆️
...tions/0024_alter_component_add_message_and_more.py 100.00% <100.00%> (ø)
weblate/trans/models/component.py 80.52% <ø> (+59.93%) ⬆️
weblate/trans/tests/test_create.py 100.00% <100.00%> (+100.00%) ⬆️
weblate/trans/tests/test_reports.py 100.00% <100.00%> (+100.00%) ⬆️
weblate/trans/tests/utils.py 93.82% <100.00%> (+93.82%) ⬆️
weblate/trans/views/create.py 89.92% <100.00%> (+64.23%) ⬆️

... and 448 files with indirect coverage changes

@gersona gersona marked this pull request as ready for review August 26, 2024 06:49
@nijel nijel added this to the 5.8 milestone Aug 26, 2024
@@ -628,6 +629,7 @@ class Component(models.Model, PathMixin, CacheKeyMixin, ComponentCategoryMixin):
"please consult the documentation for more details."
),
validators=[validate_render_commit],
blank=True,
Copy link
Member

Choose a reason for hiding this comment

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

These should not be blank, we don't want to generate blank commit messages.

"delete_message": forms.HiddenInput(),
"merge_message": forms.HiddenInput(),
"addon_message": forms.HiddenInput(),
"pull_message": forms.HiddenInput(),
Copy link
Member

Choose a reason for hiding this comment

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

Maybe just include an additional field like duplicate_component and apply content from it instead of adding plenty of hidden inputs?

@nijel
Copy link
Member

nijel commented Sep 4, 2024

@coderabbitai review

Copy link

coderabbitai bot commented Sep 4, 2024

Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

coderabbitai bot commented Sep 4, 2024

Walkthrough

The changes introduce a new feature that allows users to duplicate components directly from the menu, enhancing usability. This functionality includes modifications to forms and models to support additional fields related to component duplication. The updates also involve improvements to tests and views to ensure proper functionality and validation of the new duplication feature.

Changes

File Path Change Summary
docs/changes.rst Added a summary of the new component duplication feature in the menu.
weblate/templates/component.html Introduced a new link for users to duplicate components directly from the interface.
weblate/trans/forms.py Added new hidden fields to the form configuration to support duplication functionality.
weblate/trans/migrations/0024_alter_component_add_message_and_more.py Modified existing fields in the component model to improve commit messages related to duplication.
weblate/trans/models/component.py Added blank=True to several TextField declarations to allow flexibility in data entry.
weblate/trans/tests/test_create.py Updated tests to verify the creation of components from existing ones, enhancing test coverage.
weblate/trans/tests/test_reports.py Simplified category setup in tests by consolidating methods.
weblate/trans/tests/utils.py Added a method to create test categories, expanding testing capabilities.
weblate/trans/views/create.py Enhanced component selection logic to support duplication and include relevant data during submissions.

Assessment against linked issues

Objective Addressed Explanation
It's not obvious that a component can be duplicated. (Issue #10896)
The new component does not duplicate key settings from the source component. (Issue #10896)
Make duplication more discoverable with an icon. (Issue #10896) No icon or visual indication for duplication was added.

Poem

In the meadow where I hop and play,
A new feature brightens my day!
With a click, I can copy with glee,
Duplicating components, oh so easily!
Hooray for the changes, let’s celebrate,
A joyful rabbit, I can’t wait! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 69c4f6d and 40e65ba.

Files selected for processing (9)
  • docs/changes.rst (1 hunks)
  • weblate/templates/component.html (1 hunks)
  • weblate/trans/forms.py (1 hunks)
  • weblate/trans/migrations/0024_alter_component_add_message_and_more.py (1 hunks)
  • weblate/trans/models/component.py (7 hunks)
  • weblate/trans/tests/test_create.py (2 hunks)
  • weblate/trans/tests/test_reports.py (2 hunks)
  • weblate/trans/tests/utils.py (2 hunks)
  • weblate/trans/views/create.py (4 hunks)
Additional comments not posted (16)
weblate/trans/migrations/0024_alter_component_add_message_and_more.py (1)

12-100: LGTM!

The migration class and field alterations are correctly implemented. The changes align with the PR objectives of improving the component duplication process and ensuring that essential settings are carried over to the new component.

The default values, help text, and validators provide useful information and ensure the correct rendering of commit messages and add-on messages.

The code changes are approved.

weblate/templates/component.html (1)

101-101: LGTM!

The code changes look good:

  • The new list item is placed appropriately within the "Manage" dropdown menu.
  • Using the current component's ID as a query parameter is an effective way to pre-fill the new component form.
  • Wrapping the link text in a translation tag ensures proper localization support.

Great job!

weblate/trans/tests/test_reports.py (2)

401-403: LGTM!

The code changes are approved. The new setup_category method simplifies the category creation process by directly assigning the category to self.component.category.


405-406: LGTM!

The code changes are approved.

weblate/trans/tests/utils.py (1)

169-173: LGTM!

The new create_category method looks good:

  • It enhances the test suite by allowing the creation of test categories associated with projects.
  • The method implementation is correct and follows the existing coding style and conventions.
  • The import statement is updated to include the Category model.

The code changes are approved.

weblate/trans/tests/test_create.py (4)

188-191: LGTM!

The code changes are approved.


199-202: LGTM!

The code changes are approved.


206-226: LGTM!

The code changes are approved. The validation logic ensures that the component's attributes are correctly reflected in the query string.


7-7: LGTM!

The code changes are approved.

weblate/trans/views/create.py (4)

441-441: LGTM!

The code changes are approved.


473-486: LGTM!

The code changes are approved.


517-520: LGTM!

The code changes are approved.


546-562: LGTM!

The code changes are approved.

docs/changes.rst (1)

9-9: Documentation update looks good!

The added line accurately describes the new feature to duplicate a component from the menu.

weblate/trans/forms.py (1)

1676-1683: LGTM!

The code changes are approved. The new fields added to the Meta class of ComponentCreateForm look good.

weblate/trans/models/component.py (1)

Line range hint 618-623: The code changes look good to me.

Allowing the merge_style field to be blank is fine since it will fall back to the default merge style configured in the settings.

@gersona gersona marked this pull request as draft September 17, 2024 17:33
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.

Issues when duplicating a component
2 participants