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

Draft: Suggestions in Zen mode #11187

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

juliancoffee
Copy link

@juliancoffee juliancoffee commented Mar 13, 2024

Proposed changes

Solves #671, kind of.
At the time of writing, it is functional, but probably need to move most events to javascript to avoid resending Zen each time.
Also, I went via always show suggestions route, but I think that probably may be configured.

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

Summary by CodeRabbit

  • New Features
    • Introduced permission checks for user interactions on suggestions in the translation unit interface.
    • Added a form for users to submit suggestions, enhancing user engagement.
  • Bug Fixes
    • Adjusted the layout of the voting buttons for improved visual positioning.

@juliancoffee juliancoffee marked this pull request as draft March 13, 2024 00:41
@juliancoffee juliancoffee changed the title DRAFT: Suggestions in Zen mode Draft: Suggestions in Zen mode Mar 13, 2024
@@ -25,7 +25,7 @@
{% else %}
{% perm 'suggestion.delete' suggestion as user_can_delete_suggestion %}
{% if user_can_vote_suggestion or user_can_accept_suggestion or user_can_delete_suggestion %}
<div class="btn-float pull-right flip">
<div class="btn-float pull-right flip" style="top: -20px">
Copy link
Member

Choose a reason for hiding this comment

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

Please avoid inline styles.

Copy link
Author

Choose a reason for hiding this comment

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

yeah, I don't like it too, I wonder what should I do instead? Changing the original class doesn't sound like a good idea either, I guess I could create new one?

# Handle accepting/deleting suggestions
_obj, unit_set, _context = parse_path_units(
request, path, (Translation, ProjectLanguage, CategoryLanguage)
)
Copy link
Member

Choose a reason for hiding this comment

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

This is already done at top of this function.

or "spam" in request.POST
or "upvote" in request.POST
or "downvote" in request.POST
)
Copy link
Member

Choose a reason for hiding this comment

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

This is essentially a copy of code from translate function, it should be shared.

Copy link
Author

Choose a reason for hiding this comment

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

Can I just put such a function in the same file, or it should go to some utils.py file?


unit = checksum_form.cleaned_data["unit"]
# We are ignoring any redirects and responses here
_response = handle_suggestions(request, unit, "", "")
Copy link
Member

Choose a reason for hiding this comment

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

If the return value is not needed, there is no need to store it in a variable.

Copy link

codecov bot commented Apr 3, 2024

Codecov Report

Attention: Patch coverage is 0% with 8 lines in your changes missing coverage. Please review.

Project coverage is 90.74%. Comparing base (6aee586) to head (8403ff0).
Report is 3876 commits behind head on main.

Files with missing lines Patch % Lines
weblate/trans/views/edit.py 0.00% 7 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #11187      +/-   ##
==========================================
- Coverage   90.82%   90.74%   -0.08%     
==========================================
  Files         554      559       +5     
  Lines       57306    57680     +374     
  Branches     9122     9212      +90     
==========================================
+ Hits        52046    52341     +295     
- Misses       3640     3704      +64     
- Partials     1620     1635      +15     
Files with missing lines Coverage Δ
weblate/trans/views/edit.py 80.36% <0.00%> (-1.25%) ⬇️

... and 103 files with indirect coverage changes

@juliancoffee
Copy link
Author

Thanks for the review! I want to continue working on it, just got interrupted somewhat.

Copy link

github-actions bot commented May 8, 2024

This pull request has been automatically marked as stale because there wasn’t any recent activity.

It will be closed soon if no further action occurs.

Thank you for your contributions!

@github-actions github-actions bot added the wontfix Nobody will work on this. label May 8, 2024
@juliancoffee
Copy link
Author

meow, bot

@github-actions github-actions bot removed the wontfix Nobody will work on this. label May 9, 2024
Copy link

github-actions bot commented Jun 8, 2024

This pull request has been automatically marked as stale because there wasn’t any recent activity.

It will be closed soon if no further action occurs.

Thank you for your contributions!

@github-actions github-actions bot added wontfix Nobody will work on this. and removed wontfix Nobody will work on this. labels Jun 8, 2024
Copy link

This pull request has been automatically marked as stale because there wasn’t any recent activity.

It will be closed soon if no further action occurs.

Thank you for your contributions!

@github-actions github-actions bot added wontfix Nobody will work on this. and removed wontfix Nobody will work on this. labels Jul 10, 2024
Copy link

This pull request has been automatically marked as stale because there wasn’t any recent activity.

It will be closed soon if no further action occurs.

Thank you for your contributions!

@github-actions github-actions bot added wontfix Nobody will work on this. and removed wontfix Nobody will work on this. labels Aug 10, 2024
Copy link

This pull request has been automatically marked as stale because there wasn’t any recent activity.

It will be closed soon if no further action occurs.

Thank you for your contributions!

@github-actions github-actions bot added the wontfix Nobody will work on this. label Sep 10, 2024
Copy link

coderabbitai bot commented Sep 10, 2024

Walkthrough

The pull request introduces modifications to the HTML templates and backend logic related to user suggestions in the translation interface. Changes include the addition of permission checks and a suggestion submission form in the zen-units.html template, as well as updates to the suggestions.html template for visual adjustments. The backend logic in edit.py is enhanced to process user actions related to suggestions, allowing for acceptance, deletion, and voting based on user permissions.

Changes

Files Change Summary
weblate/templates/snippets/suggestions.html Modified the HTML structure by adding an inline style to reposition the voting button container.
weblate/templates/zen-units.html Added permission checks for user actions and a form for submitting suggestions.
weblate/trans/views/edit.py Introduced a conditional block to handle user actions related to suggestions based on POST data.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Frontend
    participant Backend

    User->>Frontend: Submit suggestion
    Frontend->>Backend: POST request with suggestion data
    Backend->>Backend: Check permissions
    Backend->>Backend: Validate suggestion form
    Backend-->>Frontend: Return success or error response
    Frontend-->>User: Display result
Loading

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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 60e2fd9 and 8403ff0.

Files selected for processing (3)
  • weblate/templates/snippets/suggestions.html (1 hunks)
  • weblate/templates/zen-units.html (1 hunks)
  • weblate/trans/views/edit.py (1 hunks)
Files skipped from review due to trivial changes (1)
  • weblate/templates/snippets/suggestions.html
Additional context used
Ruff
weblate/trans/views/edit.py

897-907: Too many Boolean expressions (9 > 8)

(PLR0916)


917-917: return is not documented in docstring

(DOC201)

GitHub Check: codecov/patch
weblate/trans/views/edit.py

[warning] 910-910: weblate/trans/views/edit.py#L910
Added line #L910 was not covered by tests


[warning] 914-914: weblate/trans/views/edit.py#L914
Added line #L914 was not covered by tests


[warning] 916-917: weblate/trans/views/edit.py#L916-L917
Added lines #L916 - L917 were not covered by tests


[warning] 919-919: weblate/trans/views/edit.py#L919
Added line #L919 was not covered by tests


[warning] 921-921: weblate/trans/views/edit.py#L921
Added line #L921 was not covered by tests

Additional comments not posted (3)
weblate/templates/zen-units.html (3)

93-95: LGTM!

The permission checks are correctly implemented and ensure that the user has the necessary permissions to perform actions on suggestions.


97-99: LGTM!

The form is correctly implemented with the appropriate action URL and method.


101-102: LGTM!

The template inclusion is correctly implemented, and the suggestions variable is passed to the included template as expected.

Comment on lines +896 to +921
if (
request.method == "POST"
and "merge" not in request.POST
and (
"accept" in request.POST
or "accept_edit" in request.POST
or "accept_approve" in request.POST
or "delete" in request.POST
or "spam" in request.POST
or "upvote" in request.POST
or "downvote" in request.POST
)
):
# Handle accepting/deleting suggestions
_obj, unit_set, _context = parse_path_units(
request, path, (Translation, ProjectLanguage, CategoryLanguage)
)

checksum_form = ChecksumForm(unit_set, request.POST)
if not checksum_form.is_valid():
show_form_errors(request, checksum_form)
return HttpResponseBadRequest("Invalid checksum")

unit = checksum_form.cleaned_data["unit"]
# We are ignoring any redirects and responses here
_response = handle_suggestions(request, unit, "", "")
Copy link

Choose a reason for hiding this comment

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

Refactor the code and add tests.

The code segment introduces new functionality to handle accepting or deleting suggestions within the zen function. While the code is functional, there are a few areas for improvement:

  1. The code duplicates logic from the translate function. Consider refactoring the code to share common logic and avoid duplication.
  2. The code has a high number of Boolean expressions, which can be simplified for better readability. Consider breaking down the complex condition into smaller, more manageable conditions.
  3. The code lacks test coverage, as indicated by the static analysis hints. Add appropriate tests to ensure the correctness of the new code paths.
  4. The return statements should be documented in the function's docstring to improve the code's maintainability and readability.

Do you want me to refactor the code to address these issues or open a GitHub issue to track these improvements?

Tools
Ruff

897-907: Too many Boolean expressions (9 > 8)

(PLR0916)


917-917: return is not documented in docstring

(DOC201)

GitHub Check: codecov/patch

[warning] 910-910: weblate/trans/views/edit.py#L910
Added line #L910 was not covered by tests


[warning] 914-914: weblate/trans/views/edit.py#L914
Added line #L914 was not covered by tests


[warning] 916-917: weblate/trans/views/edit.py#L916-L917
Added lines #L916 - L917 were not covered by tests


[warning] 919-919: weblate/trans/views/edit.py#L919
Added line #L919 was not covered by tests


[warning] 921-921: weblate/trans/views/edit.py#L921
Added line #L921 was not covered by tests

@github-actions github-actions bot removed the wontfix Nobody will work on this. label Sep 11, 2024
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