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:icon align when datatype is of image #35992

Conversation

saiprabhu-dandanayak
Copy link
Contributor

@saiprabhu-dandanayak saiprabhu-dandanayak commented Aug 30, 2024

Description

Bug Link

I have raised this PR In-order to fix alignment of the icon in input component when datatype is selected as number and position is selected as right

screenshot

Before issue is resolved , icon dissapears

image

After the issue is resolved

image

Cypress Testing

image

unit Testcases

image

Cypress Testing video

Inputv2_Icon_Align_Spec.js.mp4

Summary by CodeRabbit

  • New Features

    • Introduced a customizable rightElement prop in the BaseInputComponent, allowing users to display an icon on the right side of the input field based on specified properties.
  • Tests

    • Added a new test suite for the BaseInputComponent to validate the rendering and behavior of the component, including checks for icon visibility and alignment.

Copy link
Contributor

coderabbitai bot commented Aug 30, 2024

Walkthrough

The changes introduce a new property, rightElement, to the BaseInputComponent, enhancing its rendered output with an icon on the right side. This addition maintains existing functionality while improving the component's visual appeal. Additionally, a new test suite has been created to validate the component's behavior, particularly focusing on the rendering of the icon when specific props are applied.

Changes

Files Change Summary
app/client/src/widgets/BaseInputWidget/component/index.tsx Added rightElement prop to BaseInputComponent, which calls this.getRightIcon().
app/client/src/widgets/BaseInputWidget/component/index.test.tsx Introduced a test suite for BaseInputComponent, ensuring the icon renders correctly based on props.

Suggested labels

Bug, UX Improvement, ok-to-test, Enhancement, IDE Product

Poem

In the realm of inputs, a new gem's found,
An icon to the right, it twirls around!
With tests to ensure it shines just right,
Our forms now sparkle, a joyous sight!
A little tweak, a grand delight,
Enhancing our widgets, oh what a flight! ✨


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 1c27c16 and 8f08342.

📒 Files selected for processing (2)
  • app/client/src/widgets/BaseInputWidget/component/index.test.tsx (1 hunks)
  • app/client/src/widgets/BaseInputWidget/component/index.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • app/client/src/widgets/BaseInputWidget/component/index.test.tsx
  • app/client/src/widgets/BaseInputWidget/component/index.tsx

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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 67de8c1 and 1c0001d.

Files selected for processing (1)
  • app/client/src/widgets/BaseInputWidget/component/index.tsx (2 hunks)
Additional comments not posted (3)
app/client/src/widgets/BaseInputWidget/component/index.tsx (3)

526-526: Good practice: Use of constants.

Defining ICON_ALIGN_RIGHT as a constant improves code readability and maintainability by avoiding magic strings.


527-531: Well-implemented: Conditional rendering.

The conditional rendering of rightElement ensures that the icon is only displayed when iconAlign is 'right' and iconName is provided. This is a good approach to avoid unnecessary rendering.


567-567: Correct integration: Usage of rightElement.

The rightElement is correctly passed as a prop to the StyledNumericInput component, ensuring proper integration with the existing rendering logic.

Copy link

github-actions bot commented Sep 6, 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 Sep 6, 2024
@saiprabhu-dandanayak
Copy link
Contributor Author

@appsmithorg/query-js-pod , Please review this pr if you have enough bandwidth.
Thanks in advance.

@NilanshBansal
Copy link
Contributor

NilanshBansal commented Sep 12, 2024

@saiprabhu-dandanayak thank you for your contribution 🙏 This issue doesn't come under the purview of QueryJS Pod, tagging @rahulbarwal to take this forward!

@github-actions github-actions bot removed the Stale label Sep 12, 2024
Copy link

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

@rahulbarwal
Copy link
Contributor

Hey @saiprabhu-dandanayak, Sorry for the delay on this PR.
It has some lint issues, please check and fix:
https://github.com/appsmithorg/appsmith/actions/runs/10988694185/job/30505541681?pr=36473#step:9:4455

Run yarn run lint:ci to confirm if issues have been fixed.

@saiprabhu-dandanayak
Copy link
Contributor Author

Hi @rahulbarwal , fixed liniting issue and updated the pr , could you pls check this.
Thank you.

Copy link
Contributor

@rahulbarwal rahulbarwal left a comment

Choose a reason for hiding this comment

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

Lets add some unit tests to this as well please.

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

Outside diff range and nitpick comments (1)
app/client/src/widgets/BaseInputWidget/component/index.tsx (1)

Line range hint 1-1024: Class, let's review some areas for improvement in our code!

  1. TODO comments need attention
    There's a TODO comment on line 26 that needs to be addressed. Remember, TODO comments should be temporary and resolved as soon as possible.

    Would you like me to create a GitHub issue to track this TODO item?

  2. Consider using TypeScript strict mode
    The code could benefit from stricter type checking. Consider enabling TypeScript's strict mode to catch more potential errors at compile-time.

  3. Improve error handling
    The error handling in the component could be more robust. Consider adding more specific error messages and handling edge cases.

  4. Optimize performance
    The component has many conditional renders and complex logic. Consider memoizing some of the functions or using React.memo to optimize performance.

  5. Enhance accessibility
    Ensure that all input elements have proper aria labels and roles for better accessibility.

  6. Unit tests
    I don't see any unit tests in this file. It's crucial to have comprehensive unit tests for such a complex component.

    Would you like me to help create a set of unit tests for this component?

Remember, class, these suggestions are meant to improve our code quality and make our application more robust and maintainable. Keep up the good work!

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1c0001d and 4dbd69b.

Files selected for processing (1)
  • app/client/src/widgets/BaseInputWidget/component/index.tsx (1 hunks)
Additional comments not posted (1)
app/client/src/widgets/BaseInputWidget/component/index.tsx (1)

560-560: Class, pay attention to this important addition!

Well done on adding the rightElement prop to the StyledNumericInput component. This change appears to address the icon alignment issue mentioned in the pull request objectives. However, let's make sure we understand the full impact of this change.

To ensure this change doesn't affect other parts of the codebase, let's run a quick check:

This will help us verify if there are any other places where we might need to make similar changes.

Verification successful

Let's Correct Our Search Approach!

It looks like the previous search attempt encountered an issue recognizing the typescript file type. To ensure we accurately locate instances of StyledNumericInput and the getRightIcon method, we'll adjust our search parameters accordingly.


Excellent Attention to Detail!

After reviewing the search results, it's clear that the addition of the rightElement prop using this.getRightIcon() is confined solely to the BaseInputWidget component. There are no other instances where StyledNumericInput utilizes the getRightIcon method in different parts of the codebase. This ensures that the change is localized and won't inadvertently affect other components or functionalities.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for other occurrences of StyledNumericInput and its usage

# Search for StyledNumericInput usage
echo "Searching for StyledNumericInput usage:"
rg --type typescript "StyledNumericInput" -A 5 -B 5

# Search for getRightIcon method
echo "Searching for getRightIcon method:"
rg --type typescript "getRightIcon" -A 5 -B 5

Length of output: 335


Script:

#!/bin/bash
# Description: Corrected search for StyledNumericInput and getRightIcon in TypeScript files

# Search for StyledNumericInput usage in .ts and .tsx files
echo "Searching for StyledNumericInput usage:"
rg "StyledNumericInput" -A 5 -B 5 --glob "*.ts" --glob "*.tsx"

# Search for getRightIcon method in .ts and .tsx files
echo "Searching for getRightIcon method:"
rg "getRightIcon" -A 5 -B 5 --glob "*.ts" --glob "*.tsx"

Length of output: 7023

Copy link
Contributor

@rahulbarwal rahulbarwal left a comment

Choose a reason for hiding this comment

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

Can we please add unit tests for this?
This will help in ensuring that we don't miss such issues.

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

Outside diff range and nitpick comments (2)
app/client/src/widgets/BaseInputWidget/component/index.test.tsx (2)

8-32: Excellent helper function, but let's add a little extra credit!

Your renderBaseInputComponent function is like a well-organized desk, ready for any test to sit down and work. However, to make it even better, consider adding a comment explaining its purpose and usage. It's like labeling your desk drawers – it helps others understand quickly!

Here's a suggestion:

/**
 * Helper function to render BaseInputComponent with default props.
 * @param props - Optional props to override defaults.
 * @returns Rendered component with testing utilities.
 */
const renderBaseInputComponent = (
  props: Partial<BaseInputComponentProps> = {},
) => {
  // ... (rest of the function)
};

This way, future students (I mean, developers) will know exactly how to use this helpful tool!


34-52: A good start on your test, but let's aim for an A+!

Your test case is like a well-written essay, focusing on an important topic. However, to make it truly outstanding, let's add a few more details:

  1. Test description: Make it more specific, like "Icon should be visible and aligned to the right when the input type is NUMBER and iconAlign is set to 'right'".

  2. Alignment check: Add an assertion to verify the icon's alignment. You can check if the icon's parent element has a class or style indicating right alignment.

  3. Negative test: Consider adding a test case where the icon should not be visible (e.g., when iconName is not provided).

Here's an example of how you might improve the alignment check:

const iconWrapper = container.querySelector('.input-icon-wrapper');
expect(iconWrapper).toHaveStyle('justify-content: flex-end');

Remember, in testing, we want to be thorough, just like double-checking your homework!

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4dbd69b and caa89b1.

Files selected for processing (1)
  • app/client/src/widgets/BaseInputWidget/component/index.test.tsx (1 hunks)
Additional comments not posted (2)
app/client/src/widgets/BaseInputWidget/component/index.test.tsx (2)

1-6: Well done on your imports, class!

You've done a splendid job importing all the necessary modules for our test. It's like you've packed your backpack with all the right tools for a successful learning journey!


1-52: Overall, a commendable effort on your test file!

Class, this test file is like a well-written essay. It has a clear introduction (imports), a strong body (helper function and test case), and addresses the main point of our lesson (icon visibility issue).

However, remember that in the pursuit of knowledge, there's always room for improvement. Let's work on adding more detailed comments, expanding our test coverage, and making our assertions more precise.

Keep up the good work, and don't forget to apply these lessons to your future coding assignments!

@rahulbarwal
Copy link
Contributor

@saiprabhu-dandanayak client-lint is failing for latest changes: https://github.com/appsmithorg/appsmith/actions/runs/11032799313/job/30642535328?pr=36473#step:9:4550

Please fix and run yarn run lint:ci to confirm if your fix is working.

@yatinappsmith yatinappsmith merged commit c2fcd51 into appsmithorg:release Sep 26, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants