appsmith icon indicating copy to clipboard operation
appsmith copied to clipboard

chore: fixed image not downloading functionality and ImageWidget cypr…

Open Shivam-z opened this issue 1 year ago • 7 comments

Description

In this PR I have modified 3 file chages.

  • I have created helper.tsx file *app/client/src/widgets/ImageWidget/helper.ts in which I have defined one method urlToBase64 which will convert imageurl into base64Url.

  • app/client/src/widgets/ImageWidget/component/index.tsx: In this I have made one new state called downloadUrl which will takes the value from urlToBase64 method and later define the href value.

  • app/client/cypress/e2e/Regression/ClientSide/Widgets/Image/Image3_Spec.ts: I have modified the downloadImage test case according to this implementation.

summary:

As we are fetching image url for base64 conversion. Therefore, this solution only works for images that are hosted on server which allows cross origin request and for images that are hosted on server which doesn't allow cross origin request (getting cors error) the functionality will works as it was working previously.

suggestion for Restiricted Images:

for images hosted on server which does not allow cross origin request, the backend should create base64 url and return to frontend.

Fixes #24632

[!WARNING]
If no issue exists, please create an issue first, and check with the maintainers if the issue is valid.

Automation

/ok-to-test tags=""

:mag: Cypress test results

[!CAUTION]
If you modify the content in this section, you are likely to disrupt the CI result for your PR.

Communication

Should the DevRel and Marketing teams inform users about this change?

  • [ ] Yes
  • [x] No

Summary by CodeRabbit

  • New Features

    • Added base64 conversion for image downloads in the ImageComponent.
    • Introduced download functionality for images in the ImageComponent.
  • Tests

    • Introduced a comprehensive test suite for the ImageComponent, covering image rendering, download button interactions, and edge cases for image URLs.

Shivam-z avatar Jul 08 '24 10:07 Shivam-z

Walkthrough

The changes introduce a function to convert image URLs to base64 and update the ImageWidget component to handle image downloads using this function. Tests have been included to validate image rendering, downloading, and button visibility. These changes address the issue of images not downloading properly by ensuring that the download button provides a base64-encoded version of the image.

Changes

Files Change Summary
app/client/cypress/e2e/Regression/ClientSide/Widgets/Image/Image3_Spec.ts Added urlToBase64 import, updated before hook for base64 conversion, modified download button href assertion.
app/client/src/widgets/ImageWidget/component/index.tsx Added downloadUrl to state, updated lifecycle methods to handle downloadUrl, introduced updateDownloadUrl method.
app/client/src/widgets/ImageWidget/helper.ts Introduced urlToBase64 function for converting URLs to base64.
app/client/src/widgets/ImageWidget/component/index.test.tsx Added tests for ImageComponent, mocked urlToBase64, tested rendering, download button display, image download functionality, and handling empty URLs.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ImageComponent
    participant Helper as urlToBase64 Function

    User->>ImageComponent: Hover over Image
    ImageComponent-->>User: Show Download Button
    User->>ImageComponent: Click Download Button
    ImageComponent->>Helper: Convert Image URL to Base64
    Helper-->>ImageComponent: Return Base64 String
    ImageComponent-->>User: Initiate Download with Base64 URL

Assessment against linked issues

Objective Addressed Explanation
Ensure image download functionality (#24632)
Handling download button visibility (#24632)

Poem

In code we weave, a fix so bright,
Images now download, no more plight.
Base64 magic in widgets we trust,
A seamless click, no more fuss.
With tests in place, all set to gleam,
Our app's now smoother, like a dream. 🌟


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>, 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 generate interesting stats about this repository and render them as a table. -- @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.

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.

coderabbitai[bot] avatar Jul 08 '24 10:07 coderabbitai[bot]

Hi @rajatagrawal , I have added RTL unit test cases for Image Widget , could you please review this PR.

Shivam-z avatar Jul 16 '24 11:07 Shivam-z

This PR has not seen activitiy for a while. It will be closed in 7 days unless further activity is detected.

github-actions[bot] avatar Jul 23 '24 16:07 github-actions[bot]

Hi @rajatagrawal @ApekshaBhosale @sagar-qa007 , please review this PR else it will be auto closed in some days.

Shivam-z avatar Jul 23 '24 18:07 Shivam-z

@rahulbarwal Can you please help review the PR ?

rajatagrawal avatar Jul 25 '24 13:07 rajatagrawal

This PR has not seen activitiy for a while. It will be closed in 7 days unless further activity is detected.

github-actions[bot] avatar Aug 03 '24 16:08 github-actions[bot]

@rajatagrawal @rahulbarwal please look into this PR.

Shivam-z avatar Aug 05 '24 04:08 Shivam-z

This PR has not seen activitiy for a while. It will be closed in 7 days unless further activity is detected.

github-actions[bot] avatar Aug 21 '25 16:08 github-actions[bot]

This PR has been closed because of inactivity.

github-actions[bot] avatar Sep 14 '25 16:09 github-actions[bot]