Skip to content

chore: External contri/fix/bug 130 file picker widget able to pick a file when max no of files is defined as zero 0 14857 #34893

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

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

Conversation

rohan-arthur
Copy link
Contributor

@rohan-arthur rohan-arthur commented Jul 12, 2024

Description

shadow PR for #34363

Fixes #14857

Automation

/ok-to-test tags=""

🔍 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
  • No

Summary by CodeRabbit

  • New Features

    • Enhanced the FilePicker widget to display styled error messages.
    • Introduced a limit on the maximum number of files that can be uploaded, with appropriate error messages when the limit is set to zero.
  • Bug Fixes

    • Ensured proper error handling in the FilePicker widget when the maximum number of files is exceeded.
  • Tests

    • Added test cases for the FilePicker widget to verify error messages when the max number of files is set to zero.

saiprabhu-dandanayak and others added 2 commits June 20, 2024 17:26
…r-widget-able-to-pick-a-file-when-max-no-of-files-is-defined-as-zero-0-14857' into external-contri/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 bot commented Jul 12, 2024

Important

Review skipped

Auto reviews are limited to specific labels.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The recent updates introduce error handling for the FilePicker widget, specifically addressing situations where the maximum number of files is set to zero. Changes include adding error message functionality within the widget's component and state management. Additionally, Cypress test cases were created to verify this new functionality.

Changes

File Path Change Summary
app/client/cypress/e2e/Regression/ClientSide/Widgets/Filepicker/FilePicker_Max_No_Spec.js Introduced test cases to verify error messages when the max number of files is set to 0.
app/client/src/widgets/FilePickerWidgetV2/component/index.tsx Added styled error message handling and new props (maxNumFiles, errorMessage) for error display.
app/client/src/widgets/FilePickerWidgetV2/constants.ts Added a new constant ERROR_MESSAGE with the value "Cannot upload any files".
app/client/src/widgets/FilePickerWidgetV2/widget/index.tsx Modified error handling, introduced errorMessage state, and updated help text descriptions.

Assessment against linked issues

Objective Addressed Explanation
Prevent file upload when max number of files is set to zero (#14857)
Display error message "Cannot upload any files" when max files is zero (#14857)

Poem

In the land of code, a tweak so bright,
The FilePicker now upholds what's right. 🌟
When zero's the max, no files allowed,
An error message stands tall and proud.
With tests to guide, and constants in play,
Bugs take flight, and smooth runs the day. 🐇


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

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

@github-actions github-actions bot added Widgets Product This label groups issues related to widgets Bug Something isn't working File Picker Widget Low An issue that is neither critical nor breaks a user flow Production skip-changelog Adding this label to a PR prevents it from being listed in the changelog and removed Bug Something isn't working labels Jul 12, 2024
Copy link

🔴 There's new test files in JS, please port to TS and re-trigger Cypress tests:

  1. app/client/cypress/e2e/Regression/ClientSide/Widgets/Filepicker/FilePicker_Max_No_Spec.js

@github-actions github-actions bot added Bug Something isn't working and removed Bug Something isn't working labels Jul 12, 2024
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

Outside diff range, codebase verification and nitpick comments (1)
app/client/cypress/e2e/Regression/ClientSide/Widgets/Filepicker/FilePicker_Max_No_Spec.js (1)

1-6: Use constants for locators and avoid plain strings.

Instead of using plain strings for locators, define constants to ensure maintainability and readability.

-const commonlocators = require("../../../../../locators/commonlocators.json");
+import commonlocators from "../../../../../locators/commonlocators.json";
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7e3092f and e61b0ff.

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
Path-based instructions (1)
app/client/cypress/e2e/Regression/ClientSide/Widgets/Filepicker/FilePicker_Max_No_Spec.js (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.
Use locator variables for locators and do not use plain strings.
Use data-* attributes for selectors.
Avoid Xpaths and CSS attributes.
Avoid selectors like .btn.submit or button[type=submit].
Perform logins via API with LoginFromAPI.
Avoid using it.only.
Use before, beforeEach, after, afterEach correctly.
Clean state before tests.
Use multiple assertions.
Don't treat Cypress as unit tests.
Use constants for strings in locator.
Include datasource operations in before hooks.
Do not use duplicate filenames.

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

6-10: Styled component for error message is correct.

The styled component for error message is correctly defined using styled-components.


34-34: Error message handling is correct.

The error message is correctly displayed if props.errorMessage is present.


50-51: New props maxNumFiles and errorMessage are correctly defined.

The new props maxNumFiles and errorMessage are correctly defined and optional.

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

52-52: New state property errorMessage is correctly defined.

The new state property errorMessage is correctly initialized to null.


712-716: Error message state is correctly managed in componentDidUpdate.

The error message state is correctly reset when the max number of files changes from 0 to a positive number.


803-807: Error message handling on openModal is correct.

The error message is correctly set when the max number of files is 0.


827-827: Error message prop is correctly passed to the component.

The error message state is correctly passed as a prop to the FilePickerComponent.

Comment on lines +20 to +33
it("Should display an error message when clicked on filepicker when max no-of files are set to 0", () => {
EditorNavigation.SelectEntityByName("FilePicker1", EntityType.Widget);
propPane.UpdatePropertyFieldValue("Max no. of files", "1");
const fixturePath = "cypress/fixtures/dummy.pdf";
cy.get(commonlocators.filepickerv2).click();
cy.get(commonlocators.filePickerInput).first().selectFile(fixturePath, {
force: true,
});
cy.get(commonlocators.filePickerUploadButton).click();
cy.get(commonlocators.dashboardItemName).contains("dummy.pdf");
agHelper.GetNClick(commonlocators.filePickerRemoveButton, 0, true);
propPane.UpdatePropertyFieldValue("Max no. of files", "0");
cy.get(commonlocators.filepickerv2).click();
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Test case is valid but consider adding assertions to verify the error message.

The test case is valid for verifying the error message when the max number of files is set to 0. However, consider adding assertions to explicitly verify the presence of the error message.

+ cy.get(commonlocators.filePickerErrorMessage)
+   .should("exist")
+   .and("contain.text", "Cannot upload any files");
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
it("Should display an error message when clicked on filepicker when max no-of files are set to 0", () => {
EditorNavigation.SelectEntityByName("FilePicker1", EntityType.Widget);
propPane.UpdatePropertyFieldValue("Max no. of files", "1");
const fixturePath = "cypress/fixtures/dummy.pdf";
cy.get(commonlocators.filepickerv2).click();
cy.get(commonlocators.filePickerInput).first().selectFile(fixturePath, {
force: true,
});
cy.get(commonlocators.filePickerUploadButton).click();
cy.get(commonlocators.dashboardItemName).contains("dummy.pdf");
agHelper.GetNClick(commonlocators.filePickerRemoveButton, 0, true);
propPane.UpdatePropertyFieldValue("Max no. of files", "0");
cy.get(commonlocators.filepickerv2).click();
});
it("Should display an error message when clicked on filepicker when max no-of files are set to 0", () => {
EditorNavigation.SelectEntityByName("FilePicker1", EntityType.Widget);
propPane.UpdatePropertyFieldValue("Max no. of files", "1");
const fixturePath = "cypress/fixtures/dummy.pdf";
cy.get(commonlocators.filepickerv2).click();
cy.get(commonlocators.filePickerInput).first().selectFile(fixturePath, {
force: true,
});
cy.get(commonlocators.filePickerUploadButton).click();
cy.get(commonlocators.dashboardItemName).contains("dummy.pdf");
agHelper.GetNClick(commonlocators.filePickerRemoveButton, 0, true);
propPane.UpdatePropertyFieldValue("Max no. of files", "0");
cy.get(commonlocators.filepickerv2).click();
cy.get(commonlocators.filePickerErrorMessage)
.should("exist")
.and("contain.text", "Cannot upload any files");
});

@sagar-qa007
Copy link
Contributor

@rohan-arthur Please run cypress test.

@saiprabhu-dandanayak
Copy link
Contributor

Hello @sagar-qa007 and @rohan-arthur, are there any modifications that need to be made for this PR? If so, please let me know; I would be happy to receive the same.

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 Jul 24, 2024
@saiprabhu-dandanayak
Copy link
Contributor

Hi @rohan-arthur , @sagar-qa007 , pls review this pr if you have enough bandwidth , due to in-activity stale label has been attached.

@rahulbarwal
Copy link
Contributor

@saiprabhu-dandanayak I'll check it out.

@github-actions github-actions bot removed the Stale label Jul 25, 2024
Copy link

github-actions bot commented Aug 2, 2024

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 Aug 2, 2024
@saiprabhu-dandanayak
Copy link
Contributor

Took recent pull from release branch and updated the source branch in this #34363

@github-actions github-actions bot removed the Stale label Sep 1, 2024
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 Mar 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
File Picker Widget Low An issue that is neither critical nor breaks a user flow Production skip-changelog Adding this label to a PR prevents it from being listed in the changelog Stale Widgets Product This label groups issues related to widgets
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]-[130]:File picker Widget - able to pick a file when Max no of files is defined as zero (0)
4 participants