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

fix: ensure an error msg is displayed when max-no of files is 0 and r… #34363

Open
wants to merge 8 commits into
base: release
Choose a base branch
from

Conversation

saiprabhu-dandanayak
Copy link
Contributor

@saiprabhu-dandanayak saiprabhu-dandanayak commented Jun 20, 2024

User Description

Bug : File Picker Bug

I have raised this PR In order to restrict user from uploading files when max-no of files is set to 0 and displaying an error message when and clicks on filepicker

Screenshots

1 file is uploded when max no-of files is set to 0

image

Displaying error msg and restricting user from uploading files

image

Unit testcases

image

Cypress Testing video

FilePicker_Max_No_Spec.js.mp4

Copy link
Contributor

coderabbitai bot commented Jun 20, 2024

Walkthrough

The recent changes introduce enhancements to the FilePicker widget's functionality and testing. They include the addition of error message handling when the maximum number of files allowed is set to 0. This update ensures proper display of error messages through a new prop, styled components, and constants. Corresponding Cypress tests were added to verify this behavior.

Changes

Files Change Summary
.../FilePicker_Max_No_Spec.js
.../FilePicker_Max_No_Spec.ts
Introduced test cases for the FilePicker widget to verify the behavior when the maximum number of files is set to 0, including error message checks.
.../FilePickerWidgetV2/component/index.tsx Added a styled error message component, new props maxNumFiles and errorMessage to handle error scenarios in the FilePicker widget.
.../FilePickerWidgetV2/constants.ts Introduced a new constant ERROR_MESSAGE with the value "Cannot upload any files" to manage error messages centrally.
.../FilePickerWidgetV2/widget/index.tsx Enhanced FilePickerWidget to include errorMessage state, updated prop handling, and integrated error messages based on maxNumFiles values.

Poem

In fields of code where widgets play,
A FilePicker gained a say,
"No files, no go," it now decrees,
With error messages on the breeze.
Tests ensure it works just right,
For users near and out of sight.
A digital dance, in bytes of light. 🌟


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 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 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.

Copy link
Contributor

@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 ca13db0 and 1604e1c.

Files selected for processing (4)
  • app/client/cypress/e2e/Regression/ClientSide/Widgets/Filepicker/FilePicker_Max_No_Spec.js (1 hunks)
  • app/client/src/widgets/FilePickerWidgetV2/component/index.tsx (3 hunks)
  • app/client/src/widgets/FilePickerWidgetV2/constants.ts (1 hunks)
  • app/client/src/widgets/FilePickerWidgetV2/widget/index.tsx (12 hunks)
Files skipped from review due to trivial changes (1)
  • app/client/src/widgets/FilePickerWidgetV2/constants.ts
Additional context used
Biome
app/client/cypress/e2e/Regression/ClientSide/Widgets/Filepicker/FilePicker_Max_No_Spec.js

[error] 15-34: This function expression can be turned into an arrow function. (lint/complexity/useArrowFunction)

Function expressions that don't use this can be turned into arrow functions.
Safe fix: Use an arrow function instead.

app/client/src/widgets/FilePickerWidgetV2/component/index.tsx

[error] 15-15: Change to an optional chain. (lint/complexity/useOptionalChain)

Unsafe fix: Change to an optional chain.

Additional comments not posted (5)
app/client/src/widgets/FilePickerWidgetV2/component/index.tsx (2)

50-51: Adding optional properties maxNumFiles and errorMessage to the interface is appropriate for the new functionality.


8-10: Ensure the ErrorMessage styled component's color is accessible against various backgrounds.

app/client/src/widgets/FilePickerWidgetV2/widget/index.tsx (3)

803-807: The logic to handle the maxNumFiles property and set the error message is clear and correctly implemented.


842-842: The state errorMessage is well-defined and appropriately used to manage error messages based on file upload conditions.


21-21: Ensure that the ERROR_MESSAGE constant and errorMessage state are consistently used across the widget to manage error visibility effectively.

Also applies to: 52-52

Verification successful

Ensure that the ERROR_MESSAGE constant and errorMessage state are consistently used across the widget to manage error visibility effectively.

The search results indicate that both ERROR_MESSAGE and errorMessage are used in various files, including app/client/src/widgets/FilePickerWidgetV2/widget/index.tsx. However, to confirm consistent usage within this specific widget, we need to focus on the relevant lines of code.

  • app/client/src/widgets/FilePickerWidgetV2/widget/index.tsx:import FileDataTypes, { ERROR_MESSAGE } from "../constants";
  • app/client/src/widgets/FilePickerWidgetV2/widget/index.tsx: errorMessage: null,
  • app/client/src/widgets/FilePickerWidgetV2/widget/index.tsx: this.setState({ errorMessage: null });
  • app/client/src/widgets/FilePickerWidgetV2/widget/index.tsx: this.setState({ errorMessage: ERROR_MESSAGE });
  • app/client/src/widgets/FilePickerWidgetV2/widget/index.tsx: this.setState({ errorMessage: null });
  • app/client/src/widgets/FilePickerWidgetV2/widget/index.tsx: errorMessage={this.state.errorMessage}
  • app/client/src/widgets/FilePickerWidgetV2/widget/index.tsx: errorMessage: string | null;

These lines show that ERROR_MESSAGE and errorMessage are indeed being used to manage error states within the FilePickerWidgetV2. The usage appears consistent, with errorMessage being set and reset appropriately and rendered as needed.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify consistent use of `ERROR_MESSAGE` and `errorMessage` across the widget.

# Command to check usage consistency
rg --type tsx 'ERROR_MESSAGE|errorMessage'

Length of output: 72



Script:

#!/bin/bash
# Description: Verify consistent use of `ERROR_MESSAGE` and `errorMessage` across the widget.

# Corrected command to check usage consistency
rg 'ERROR_MESSAGE|errorMessage' --glob '**/*.tsx'

Length of output: 29887

Copy link

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

@github-actions github-actions bot added the Stale label Jun 27, 2024
@saiprabhu-dandanayak
Copy link
Contributor Author

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

Hi @ApekshaBhosale , can you please review this Pr.

@github-actions github-actions bot removed the Stale label Jun 28, 2024
@saiprabhu-dandanayak
Copy link
Contributor Author

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

Hi @ApekshaBhosale , can you please review this Pr.

Hi @ApekshaBhosale
I hope you're well. I’m curious and excited to hear your thoughts on my pull request raised a while ago. Looking forward to your review!
Thank you.

@saiprabhu-dandanayak
Copy link
Contributor Author

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

Hi @ApekshaBhosale , can you please review this Pr.

Hi @ApekshaBhosale I hope you're well. I’m curious and excited to hear your thoughts on my pull request raised a while ago. Looking forward to your review! Thank you.

Hi @rohan-arthur , if you could have an enough bandwidth , could you plese review this pr also.

…smith into fix/bug-130-file-picker-widget-able-to-pick-a-file-when-max-no-of-files-is-defined-as-zero-0-14857
Copy link
Contributor

@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: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1604e1c and 16c1b87.

Files ignored due to path filters (1)
  • app/client/cypress/fixtures/dummy.pdf is excluded by !**/*.pdf
Files selected for processing (1)
  • app/client/cypress/e2e/Regression/ClientSide/Widgets/Filepicker/FilePicker_Max_No_Spec.ts (1 hunks)
Additional context used
Path-based instructions (1)
app/client/cypress/e2e/Regression/ClientSide/Widgets/Filepicker/FilePicker_Max_No_Spec.ts (1)

Pattern app/client/cypress/**/**.*: Follow best practices for Cypress code and e2e automation.
Avoid using cy.wait in code.
Avoid using cy.pause in code.
Avoid using agHelper.sleep().
Use locator variables for locators and do not use plain strings.
Use data-* attributes for selectors.
Avoid Xpaths, Attributes and CSS path.
Avoid selectors like .btn.submit or button[type=submit].
Perform logins via API with LoginFromAPI.
Perform logout via API with LogOutviaAPI.
Perform signup via API with SignupFromAPI.
Avoid using it.only.
Avoid using after and aftereach in test cases.
Use multiple assertions for expect statements.
Avoid using strings for assertions.
Do not use duplicate filenames even with different paths.

Additional comments not posted (2)
app/client/cypress/e2e/Regression/ClientSide/Widgets/Filepicker/FilePicker_Max_No_Spec.ts (2)

12-14: LGTM!

The test suite description and tags are appropriate and follow best practices.


16-18: LGTM!

The before hook correctly sets up the test environment by dragging and dropping the FilePicker widget and verifying its presence.

@saiprabhu-dandanayak
Copy link
Contributor Author

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

Hi @ApekshaBhosale , can you please review this Pr.

Hi @ApekshaBhosale I hope you're well. I’m curious and excited to hear your thoughts on my pull request raised a while ago. Looking forward to your review! Thank you.

Hi @rohan-arthur , if you could have an enough bandwidth , could you plese review this pr also.

Hi @sagar-qa007 , I've just pulled the latest changes from release branch , changed cypress file from .js to .ts extension (As suggeted by coderabbitai ) and raised an updated pull request (PR) to reflect these changes. Please review it and let me know if there any chnages need to be worked on.

…smith into fix/bug-130-file-picker-widget-able-to-pick-a-file-when-max-no-of-files-is-defined-as-zero-0-14857
@rahulbarwal
Copy link
Contributor

@saiprabhu-dandanayak It would be greatly helpful if you can fix the images and video not coming up in the description. Please update the description with correct links(or re-upload the assets)

@saiprabhu-dandanayak
Copy link
Contributor Author

saiprabhu-dandanayak commented Jul 22, 2024

greatly helpful if you can fix the images and video not coming up in the description.

Hi @rahulbarwal , could you pls refresh it again , it could see both images and video , if still you are unable to see those assets , will re-upload them.

image

Full screenshot

github com_appsmithorg_appsmith_pull_34363

@saiprabhu-dandanayak
Copy link
Contributor Author

Hello, @rahulbarwal I've uploaded the assets again and have attached a full page screenshot. If you were unable to view them in the PR description, please check full page screenshot.
Thank You.

@saiprabhu-dandanayak
Copy link
Contributor Author

Hello @rahulbarwal , If you have sufficient bandwidth, please read this PR.
Thanks in advance.

@saiprabhu-dandanayak
Copy link
Contributor Author

Hi @rahulbarwal , @sagar-qa007 , When I recently pulled the latest changes from the release branch and attempted to push my changes to the source branch, I encountered an issue due to a pre-push hook that prevented me from pushing the changes. Can you please provide a solution to resolve this issue?

Screenshot

image

@rahulbarwal
Copy link
Contributor

@saiprabhu-dandanayak
This is a check to prevent pushing unintended changes to CE repo. However there are cases when we actually need to push EE changes.
In order to push those files, we can use git push --no-verify option.

@rahulbarwal rahulbarwal added the Widgets Product This label groups issues related to widgets label Aug 5, 2024
…smith into fix/bug-130-file-picker-widget-able-to-pick-a-file-when-max-no-of-files-is-defined-as-zero-0-14857
@saiprabhu-dandanayak
Copy link
Contributor Author

Hi @rahulbarwal , i have took the recent pull from release branch and updated the source branch , if you have enough bandwidth , pls review this pr.

…smith into fix/bug-130-file-picker-widget-able-to-pick-a-file-when-max-no-of-files-is-defined-as-zero-0-14857
@saiprabhu-dandanayak
Copy link
Contributor Author

Hi @rahulbarwal , i have took recent pull from the release branch and also added unit testcases for the pr, could you pls review this pr if you have enough bandwidth.
Thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Widgets Product This label groups issues related to widgets
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants