Skip to content

fix: update cropped image when crop is set from server side #20

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

Merged
merged 1 commit into from
Apr 7, 2025
Merged

Conversation

javier-godoy
Copy link
Member

@javier-godoy javier-godoy commented Apr 1, 2025

Close #19

Summary by CodeRabbit

  • New Features

    • Enhanced image cropping functionality now supports versatile crop types, offering greater flexibility when adjusting images.
  • Refactor

    • Streamlined and standardized the image cropping component for improved code reliability and maintainability.
    • Updated legal and informational notices to reflect current dates.

@javier-godoy javier-godoy requested review from mlopezFC and paodb April 1, 2025 17:41
Copy link

coderabbitai bot commented Apr 1, 2025

Walkthrough

This pull request introduces modifications to both the Java and TypeScript implementations of the image crop addon. In the Java code, the setCrop(Crop crop) method in the ImageCrop class is updated to include a JavaScript execution line that updates the cropped image on the client side. In the TypeScript code, the ImageCropElement class is enhanced by removing the croppedImageEncode method and replacing it with a new public method _updateCroppedImage, which consolidates cropping functionality. The copyright notice has also been updated.

Changes

File(s) Change Summary
src/main/java/com/.../ImageCrop.java Added JavaScript execution in setCrop(Crop crop) to update the cropped image; updated copyright year to 2024-2025.
src/main/resources/META-INF/.../image-crop.tsx Updated copyright notice (2024-2025); expanded imports to include PercentCrop and convertToPixelCrop; removed croppedImageEncode and introduced public _updateCroppedImage for improved cropping logic; updated onComplete callback.

Assessment against linked issues

Objective Addressed Explanation
Always crop image to a rectangular form even when initial dimensions are unchanged (#19)

Possibly related PRs

  • fix: adjust crop size when the image size changes #13: The changes in the main PR to the setCrop method in the ImageCrop class are related to the new _updateCroppedImage method in the ImageCropElement class from the retrieved PR, as both involve updating the cropped image functionality in response to changes in crop dimensions.
  • fix: update canvas size to avoid white space on result #9: The changes in the main PR, specifically the addition of the _updateCroppedImage method in the image-crop.tsx file, are directly related to the modifications in the retrieved PR, which also involves the image-crop.tsx file and focuses on refining the image cropping logic, including canvas size adjustments.

Suggested reviewers

  • mlopezFC

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7b980ab and 0d98e14.

📒 Files selected for processing (2)
  • src/main/java/com/flowingcode/vaadin/addons/imagecrop/ImageCrop.java (2 hunks)
  • src/main/resources/META-INF/resources/frontend/src/image-crop.tsx (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/java/com/flowingcode/vaadin/addons/imagecrop/ImageCrop.java
🔇 Additional comments (5)
src/main/resources/META-INF/resources/frontend/src/image-crop.tsx (5)

5-5: Updated copyright notice.

Copyright year has been correctly updated to reflect the current year range (2024-2025).


24-24: LGTM! Import statement has been properly expanded.

The import statement now correctly includes additional types and functions from react-image-crop (PercentCrop and convertToPixelCrop) needed for the new functionality.


73-73: Now properly updating the cropped image on load.

Good addition - this ensures the cropped image is updated immediately when the image is loaded with an initial crop, which helps fix the server-side cropping issue.


126-126: Replaced previous implementation with new method.

The call to the new _updateCroppedImage method replaces what was likely a call to the removed croppedImageEncode method, maintaining the same functionality while using the more versatile new method.


164-217: New method consolidates cropping functionality.

The new _updateCroppedImage method correctly handles various crop scenarios and updates the cropped image. This method enables server-side crop updates as specified in the PR objective.

A few observations:

  1. The method name prefixed with underscore (_) suggests it's a private or internal method, but it's marked as public since it needs to be called from the server-side.
  2. The method properly handles both PixelCrop and PercentCrop types using convertToPixelCrop.
  3. The circular crop handling looks correct.
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

@paodb paodb merged commit cec972c into master Apr 7, 2025
3 checks passed
@paodb paodb deleted the fix-19 branch April 7, 2025 22:35
@paodb paodb moved this from To Do to Pending release in Flowing Code Addons Apr 8, 2025
@javier-godoy javier-godoy moved this from Pending release to Done in Flowing Code Addons Apr 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

Image not cropped when initial size is not changed
2 participants