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 #341 : Update CustomTextField for full-width support #353

Conversation

saksham-malhotra-27
Copy link
Contributor

@saksham-malhotra-27 saksham-malhotra-27 commented Nov 28, 2024

Issue:
The CustomTextField component does not handle width properly. Specifically, it lacks support for stretching to 100% width.
#341
Implementation:

  • Modified the CustomTextField.jsx file to add a new fullWidth prop as a boolean.
  • Replaced the previous TextFieldWidth prop with the new fullWidth prop to manage the width behavior.
  • The fullWidth boolean simplifies the implementation by directly applying a 100% width when set to true, making it more intuitive and easier to use.

Copy link
Contributor

coderabbitai bot commented Nov 28, 2024

Walkthrough

The CustomTextField component in the CustomTextField.jsx file has been updated to introduce a new boolean prop called fullWidth, which defaults to false. This prop allows the component to dynamically adjust its width based on its value. The sx prop of the TextField now utilizes a ternary operator to determine the width, setting it to "100%" when fullWidth is true, or using the existing TextFieldWidth when false. Additionally, fullWidth has been added to the prop types for validation purposes.

Changes

File Change Summary
frontend/src/components/TextFieldComponents/CustomTextField/CustomTextField.jsx - Added new prop fullWidth (boolean) to CustomTextField component.
- Updated sx prop to conditionally set width based on fullWidth.
- Added fullWidth to CustomTextField.propTypes for prop type validation.

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1442eb8 and cdc3e59.

📒 Files selected for processing (1)
  • frontend/src/components/TextFieldComponents/CustomTextField/CustomTextField.jsx (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • frontend/src/components/TextFieldComponents/CustomTextField/CustomTextField.jsx

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:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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

🧹 Outside diff range and nitpick comments (1)
frontend/src/components/TextFieldComponents/CustomTextField/CustomTextField.jsx (1)

122-122: Props validation's got the right flow! 🎤

The PropTypes validation is correct, but we could improve the organization.

Consider grouping related props together. Move fullWidth next to other layout-related props like TextFieldWidth:

  TextFieldWidth: PropTypes.string,
+ fullWidth: PropTypes.bool,
  inputHeight: PropTypes.string,
  id: PropTypes.string,
  name: PropTypes.string,
  checkCircleIconVisible: PropTypes.bool,
  displayCheckCircleIcon: PropTypes.bool,
  textFieldMargin: PropTypes.string,
  type: PropTypes.string,
- fullWidth: PropTypes.bool,
  required: PropTypes.bool,
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d46ed29 and aa1ba26.

📒 Files selected for processing (1)
  • frontend/src/components/TextFieldComponents/CustomTextField/CustomTextField.jsx (3 hunks)
🔇 Additional comments (2)
frontend/src/components/TextFieldComponents/CustomTextField/CustomTextField.jsx (2)

33-33: Yo, this prop declaration is straight fire! 🔥

The fullWidth prop follows Material-UI conventions perfectly, with the correct default value and naming pattern.


33-33: Drop the beat while we verify these changes! 🎧

Let's make sure existing components using CustomTextField won't break with this new prop.

Also applies to: 60-61

✅ Verification successful

Yo, this change is safe to drop! 🎤

The default fullWidth=false won't break existing components because:

  • Most components explicitly set TextFieldWidth prop (like "241px" or "100%")
  • Components that need full width already specify it through TextFieldWidth="100%"
  • No components directly rely on the fullWidth prop in their implementations

The change maintains backward compatibility while providing better control over the field's width through either fullWidth or TextFieldWidth props.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for existing CustomTextField usages to verify impact
echo "Checking CustomTextField usages..."
rg -l "CustomTextField" --type jsx

# Look specifically for TextFieldWidth prop usage
echo "Checking TextFieldWidth prop usage..."
rg "TextFieldWidth=" --type jsx -A 2 -B 2

Length of output: 296


Script:

#!/bin/bash
# Search for existing CustomTextField usages without file type restriction
echo "Checking CustomTextField usages..."
rg -l "CustomTextField"

# Look specifically for fullWidth prop usage
echo "Checking fullWidth prop usage..."
rg "fullWidth" -A 2 -B 2

# Check the actual CustomTextField component definition
echo "Checking CustomTextField component definition..."
rg "CustomTextField" -A 10 -B 10 "frontend/src/components/TextFieldComponents/CustomTextField/CustomTextField.jsx"

Length of output: 4593


Script:

#!/bin/bash
# Let's check how CustomTextField is actually used in the components
echo "Checking actual usage patterns..."
for file in $(rg -l "CustomTextField" | grep -v "CustomTextField.jsx" | grep -v "test" | grep -v "ReadMe.md"); do
    echo "=== Checking $file ==="
    rg -A 2 -B 2 "<CustomTextField" "$file"
done

Length of output: 12151

@erenfn erenfn self-requested a review December 2, 2024 00:41
Copy link
Collaborator

@erenfn erenfn left a comment

Choose a reason for hiding this comment

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

Right now login page looks like this. (default fullWidth)

image

And this is CreatePopupPage.jsx with fullWidth=true

image

Maybe fullWidth is not what we are looking for. Also please test your code.

@saksham-malhotra-27
Copy link
Contributor Author

@erenfn Could you elaborate on the issue ? I understand your point about full width, but what other concerns are you referring to related to the full-width aspect ?
Also, note that FullWidth here is just a flag for the component. Its behavior depends on whether the parent container is set to full-screen width. For example:

  • Parent div: Width set to 50%.
  • Child div: If set to 100% due to the FullWidth flag, it would still only take up 50% of the screen width since it is relative to the parent container.

@erenfn
Copy link
Collaborator

erenfn commented Dec 2, 2024

I know. The thing is that we wrap the text field in a div, and I believe that is where this problem occurs. Also, you can clearly see from the second image that it doesn't take up 100% of the space of the parent.

@erenfn
Copy link
Collaborator

erenfn commented Dec 10, 2024

@saksham-malhotra-27 Any updates?

@saksham-malhotra-27
Copy link
Contributor Author

Hey @erenfn ! I got a bit busy, but I came across this:

Problem:

In the first CustomTextField, I explicitly applied fullWidth as true. However, in the second one, I didn’t:
image

As a result, the views turned out like this:
image

This happens because the default value of fullWidth is set to false. Even if TextFieldWidth is set to 'full', the fullWidth prop still falls back to its default value:
image

Solution:

Here are two possible approaches to resolve this:

  1. Set fullWidth's default value to true
    This way, it will always default to true, and you’ll need to explicitly set it to false when needed.

  2. Update the logic in CustomTextField
    Configure it so that if TextFieldWidth is 'full' and fullWidth is not explicitly passed, it automatically defaults to true. In all other cases where fullWidth isn’t provided, it defaults to false.

My Recommendation:
I suggest going with the second approach for better flexibility and handling edge cases.

Let me know your thoughts on this! Once you approve, I’ll implement the changes and commit them. Apologies again for the delay—I’ll ensure this gets finished within a day. 😊

@saksham-malhotra-27
Copy link
Contributor Author

Hey! To implement the changes quickly and effectively, I went ahead with the second approach by doing the following:
image

Now, the decision for whether the text field should occupy full width is based on this computed full width property.

I also included "stretch" to account for scenarios where terms commonly associated with flexible layouts, like "stretch", might be used.

Result:
image

@erenfn
Copy link
Collaborator

erenfn commented Dec 10, 2024

Thanks, the second approach makes sense. Could you also check other parts (Like /popup/create, /banner/create, and settings) to ensure they work as intended?

@saksham-malhotra-27
Copy link
Contributor Author

Hey @erenfn! I've checked everything, and it all seems to be working fine on my end. Many of the components use predefined widths like 241px, so it doesn't make much of a difference. Additionally, when fullWidth is set to true, it works as expected.

Could you please review the code once?

@erenfn erenfn self-requested a review December 11, 2024 19:39
Copy link
Collaborator

@erenfn erenfn left a comment

Choose a reason for hiding this comment

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

  • This is when I set fullWidth=true for the second text field

image

  • This is when I set the width of the parent div of the TextField 100% for the second text field:

image

You also have to set the width of the outer div element. The screenshots are taken from /popup/create page by zooming out

@saksham-malhotra-27
Copy link
Contributor Author

Alright ! working on it,
Just confirming: Should I set the parent div's width to 100% for all or only for the /popup/create ?

@erenfn
Copy link
Collaborator

erenfn commented Dec 12, 2024

It should be set to 100% when fullWidth=true

@saksham-malhotra-27
Copy link
Contributor Author

Alright! Will see the issue today.

@saksham-malhotra-27
Copy link
Contributor Author

Hey @erenfn !

Approach 1

  1. One way to fix the "create popup" design is by adding a shared fullWidth state in the component. This would result in the following design:
    image

  2. This change would look like this after implementation:
    image

However, there are some limitations to consider as it's similar to being hard coded. The "Banner Create", "Popup Create", and "CodeTab" under Settings all need similar adjustments. Although we currently use a fixed width for all three.

Approach 2

  1. Modify the container styling in the above mentioned component's individual SCSS files.

image

  1. By adding width: 100% to the container and wrapping the custom text fields in a div with width: 100%, we can ensure that when fullWidth is used, it correctly assigns the width to 100%.
    image

  2. Result :
    image

According to me the 2nd approach is reliable and better than the first one . Let me know your thoughts, I'll change the code accordingly.

@saksham-malhotra-27
Copy link
Contributor Author

Hey @erenfn ! I have pushed the changes.

@erenfn erenfn merged commit 6c2f98b into bluewave-labs:develop Dec 17, 2024
2 checks passed
This was referenced Dec 18, 2024
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.

2 participants