Skip to content

Conversation

prasad-madine
Copy link
Contributor

@prasad-madine prasad-madine commented Jun 14, 2024

User description

Description:

In Radio button widget->In property pane->if the options section(label or value) is kept empty the required error message should be displayed.

Bug: In Radio button widget->In property pane->if the options section(label or value) is kept empty the required error message should be displayed

Before:

Screenshot from 2024-06-10 16-47-22

After resolving bug:

Screenshot from 2024-06-26 13-34-38

Summary by CodeRabbit

  • New Features

    • Enhanced the KeyValueComponent to include error validation and messaging for empty Name and Value fields.
    • Added styled components for better layout and error message display.
  • Bug Fixes

    • Improved error handling in the RadioGroupWidget to validate empty labels and values and display appropriate error messages.
  • Tests

    • Streamlined the Canvas context test case to focus on essential interactions, improving test efficiency.

PR Type

Bug fix, Enhancement


Description

  • Added error message handling for empty name and value fields in key-value pairs in the KeyValueComponent.
  • Introduced ErrorMessageBox styled component for displaying error messages.
  • Implemented validatePairs function to validate key-value pairs and set appropriate error messages.
  • Updated the component structure to include error message display below each key-value pair.

Changes walkthrough 📝

Relevant files
Enhancement
KeyValueComponent.tsx
Add validation and error messages for empty key-value pairs

app/client/src/components/propertyControls/KeyValueComponent.tsx

  • Added ErrorMessageBox styled component for error display.
  • Introduced validatePairs function to validate key-value pairs.
  • Updated component to display error messages for empty name or value
    fields.
  • Modified component structure to include error message display.
  • +66/-34 

    💡 PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    @prasad-madine prasad-madine requested review from a team and riodeuno and removed request for a team June 14, 2024 06:54
    Copy link
    Contributor

    coderabbitai bot commented Jun 14, 2024

    Walkthrough

    Recent updates to the KeyValueComponent in the property controls enhance user experience by introducing styled components for layout and error messaging. A new validation function effectively checks for empty fields and manages error states. Additionally, the RadioGroupWidget has improved validation logic to ensure that both labels and values are filled in, providing clearer feedback for users.

    Changes

    Files Change Summary
    .../propertyControls/KeyValueComponent.tsx Introduced styled components FlexBox and ErrorMessageBox, added state for errorMessages, implemented validatePairs for input validation, and modified StyledInputGroup for conditional styling.
    .../RadioGroupWidget/widget/index.tsx Enhanced the optionsCustomValidation function to ensure both labels and values are not empty, updating _isValid and providing appropriate error messages.
    .../cypress/e2e/Regression/ClientSide/IDE/Canvas_Context_Bug_Fixes.js Streamlined test case by removing assertions related to checkbox options, focusing on the setup of the property pane and the action to deselect all widgets.

    Sequence Diagrams

    sequenceDiagram
        participant User
        participant KeyValueComponent
        participant ErrorMessageBox
        User->>KeyValueComponent: Enter Name and Value pairs
        KeyValueComponent->>KeyValueComponent: validatePairs(pairs)
        KeyValueComponent->>ErrorMessageBox: Display error messages if validation fails
        ErrorMessageBox->>User: Show error messages alongside input fields
    
    Loading

    Poem

    🐰 In the land of code, where changes brew,
    Styled components now stand in view.
    Error messages guard the gate,
    Validation checks won't be late.
    Names and values must align,
    For your data to shine! ✨


    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.

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

    Outside diff range and nitpick comments (5)
    app/client/src/components/propertyControls/KeyValueComponent.tsx (2)

    41-45: Consider adding a descriptive comment for the FlexBox styled component.

    Adding a comment explaining the purpose of FlexBox can improve code readability, especially for new contributors or during future maintenance.


    [!TIP]
    Codebase Verification

    The validation logic in the validatePairs function currently only checks if both the label and value fields are empty. It does not handle cases where only one of the fields is empty.

    • Location to address:
      • app/client/src/components/propertyControls/KeyValueComponent.tsx, within the validatePairs function.

    Consider extending the validation logic to handle cases where either the label or value field is empty.

    Analysis chain

    Line range hint 81-144: Ensure error handling covers all necessary cases.

    The current implementation only checks for both fields being empty. Consider extending this to handle cases where one of the fields is empty but not both, which might also require validation.

    Scripts executed

    The following scripts were executed for the analysis:


    Script:

    #!/bin/bash
    # Description: Verify handling of cases where only one of the fields is empty.
    # Test: Search for the usage of validatePairs function and check if there are any cases not covered by current validation.
    rg --type typescript "validatePairs"
    

    Length of output: 71



    Script:

    #!/bin/bash
    # Correcting the search for the usage of validatePairs function in the codebase.
    rg "validatePairs"
    

    Length of output: 662


    Script:

    #!/bin/bash
    # Extracting the implementation of the validatePairs function to analyze its logic.
    ast-grep --lang ts --pattern 'function validatePairs($_) { $$$ }'
    

    Length of output: 67



    Script:

    #!/bin/bash
    # Locate the definition of the validatePairs function within KeyValueComponent.tsx to analyze its implementation.
    rg "function validatePairs" app/client/src/components/propertyControls/KeyValueComponent.tsx
    

    Length of output: 161



    Script:

    #!/bin/bash
    # Extract the full implementation of the validatePairs function from KeyValueComponent.tsx for analysis.
    rg -A 10 "function validatePairs" app/client/src/components/propertyControls/KeyValueComponent.tsx
    

    Length of output: 458

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

    Line range hint 62-62: Replace hasOwnProperty with Object.hasOwn.

    Using Object.hasOwn instead of hasOwnProperty avoids issues related to the object prototype chain and is recommended for checking properties.

    - if (!uniqueLabels.hasOwnProperty(value)) {
    + if (!Object.hasOwn(uniqueLabels, value)) {

    Line range hint 112-112: Correct the invalid typeof comparison.

    The typeof comparison should be against a valid string literal to ensure proper type checking.

    - if (typeof value !== valueType) {
    + if (typeof value !== "string" && typeof value !== "number") {

    Line range hint 158-160: Remove unnecessary else clause.

    The else clause can be omitted as the previous branches contain break statements, making it redundant.

    - else {
    + // Removed unnecessary else clause
    Review details

    Configuration used: CodeRabbit UI
    Review profile: CHILL

    Commits

    Files that changed from the base of the PR and between 8f0f4f9 and 1d77950.

    Files selected for processing (2)
    • app/client/src/components/propertyControls/KeyValueComponent.tsx (9 hunks)
    • app/client/src/widgets/RadioGroupWidget/widget/index.tsx (1 hunks)
    Additional context used
    Biome
    app/client/src/components/propertyControls/KeyValueComponent.tsx

    [error] 205-205: Missing key property for this element in iterable. (lint/correctness/useJsxKeyInIterable)

    The order of the items may change, and having a key can help React identify which item was moved.
    Check the React documentation.

    app/client/src/widgets/RadioGroupWidget/widget/index.tsx

    [error] 62-62: Do not access Object.prototype method 'hasOwnProperty' from target object. (lint/suspicious/noPrototypeBuiltins)

    It's recommended using Object.hasOwn() instead of using Object.hasOwnProperty().
    See MDN web docs for more details.


    [error] 112-112: Invalid typeof comparison value: this expression is not a string literal (lint/suspicious/useValidTypeof)

    not a string literal


    [error] 158-160: This else clause can be omitted because previous branches break early. (lint/style/noUselessElse)

    Unsafe fix: Omit the else clause.

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

    Review details

    Configuration used: CodeRabbit UI
    Review profile: CHILL

    Commits

    Files that changed from the base of the PR and between 1d77950 and ef4beda.

    Files selected for processing (1)
    • app/client/src/components/propertyControls/KeyValueComponent.tsx (8 hunks)
    Files not reviewed due to errors (1)
    • app/client/src/components/propertyControls/KeyValueComponent.tsx (Error: Server error. Please try again later.)

    @riodeuno riodeuno changed the title fix/Added error message when label and value are empty in radio group … fix: Show error message when label and value are both empty in radio group widget's properties Jun 20, 2024
    @riodeuno
    Copy link
    Contributor

    /build-deploy-preview skip-tests=true

    Copy link

    Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/9596052403.
    Workflow: On demand build Docker image and deploy preview.
    skip-tests: true.
    env: ``.
    PR: 34245.
    recreate: .

    Copy link

    Deploy-Preview-URL: https://ce-34245.dp.appsmith.com

    @riodeuno
    Copy link
    Contributor

    @PrasadMadine
    Thanks for creating this PR.
    Please also look at this issue #34308 for our guidelines on contributions.

    The error message doesn't look appropriate as the size and positioning of text don't match the context.

    Screenshot from 2024-06-24 11-50-59

    Here is a screenshot of the expected design.
    image (1)

    @riodeuno riodeuno removed their request for review June 24, 2024 07:56
    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: 0

    Review details

    Configuration used: CodeRabbit UI
    Review profile: CHILL

    Commits

    Files that changed from the base of the PR and between ef4beda and ecd557a.

    Files ignored due to path filters (1)
    • app/client/src/assets/icons/alert/warning-error.svg is excluded by !**/*.svg
    Files selected for processing (1)
    • app/client/src/components/propertyControls/KeyValueComponent.tsx (9 hunks)
    Files not reviewed due to errors (1)
    • app/client/src/components/propertyControls/KeyValueComponent.tsx (no review received)

    @prasad-madine
    Copy link
    Contributor Author

    Hello @riodeuno , Made the suggested UI changes, please review this PR.
    Screenshot from 2024-06-26 13-34-38

    Thankyou

    Copy link

    github-actions bot commented Jul 3, 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 Jul 3, 2024
    @prasad-madine
    Copy link
    Contributor Author

    prasad-madine commented Jul 5, 2024

    Hello @riodeuno
    Could you please review this PR when you have some time?

    Thank you!

    @github-actions github-actions bot removed the Stale label Jul 5, 2024
    @somangshu
    Copy link
    Contributor

    We need to show errors as per the conventions.
    New component is not needed here.

    Screenshot 2024-07-09 at 2 35 11 PM

    @prasad-madine
    Copy link
    Contributor Author

    Hello @riodeuno
    Could you please review this PR?

    Thank you!

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

    Review details

    Configuration used: .coderabbit.yaml
    Review profile: CHILL

    Commits

    Files that changed from the base of the PR and between ecd557a and 7416eec.

    Files selected for processing (1)
    • app/client/cypress/e2e/Regression/ClientSide/IDE/Canvas_Context_Bug_Fixes.js (1 hunks)
    Files skipped from review due to trivial changes (1)
    • app/client/cypress/e2e/Regression/ClientSide/IDE/Canvas_Context_Bug_Fixes.js

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

    Review details

    Configuration used: .coderabbit.yaml
    Review profile: CHILL

    Commits

    Files that changed from the base of the PR and between 7416eec and 6330b2a.

    Files selected for processing (1)
    • app/client/cypress/e2e/Regression/ClientSide/IDE/Canvas_Context_Bug_Fixes.js (1 hunks)
    Files skipped from review due to trivial changes (1)
    • app/client/cypress/e2e/Regression/ClientSide/IDE/Canvas_Context_Bug_Fixes.js

    @riodeuno
    Copy link
    Contributor

    @PrasadMadine Please see the PR #35800. There are some typescript issues in the code that fails the build. I've discussed your PR with the team and we'll be merging your PR once all the tests pass.

    cy.get(`[data-guided-tour-id="explorer-entity-Image1"]`).should("exist");
    });
    });
    });
    Copy link
    Contributor

    Choose a reason for hiding this comment

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

    Please remove this changes as it is not part of functionality.

    @riodeuno riodeuno removed their request for review September 3, 2024 09:09
    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.

    4 participants