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: Implement dynamic dropdown width in SelectField in JSONForm #37289

Conversation

rahulbarwal
Copy link
Contributor

@rahulbarwal rahulbarwal commented Nov 8, 2024

Description

Problem

The SelectField inside JSONForm widget's dropdown width was not dynamically adjusted, resulting in inconsistent responsiveness.

Root cause

The SelectField component's dropdown width was not being updated dynamically, causing the component to become too wide or too narrow, affecting its usability.

Solution

This PR enhances the SelectField component to adjust its dropdown width dynamically for improved responsiveness. This PR handles...

  • Dynamically adjusting the dropdown width based on the available screen space, ensuring a responsive user experience.
  • Properly setting up and tearing down the ResizeObserver to ensure accurate width detection.

Fixes #37279
or
Fixes Issue URL

Warning

If no issue exists, please create an issue first, and check with the maintainers if the issue is valid.

Automation

/ok-to-test tags="@tag.JSONForm"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/11790765022
Commit: 1438c99
Cypress dashboard.
Tags: @tag.JSONForm
Spec:


Tue, 12 Nov 2024 04:59:15 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Enhanced the SelectField component for dynamic dropdown width adjustment based on its wrapper size.
    • Improved filter update handling within the SelectField.
  • Bug Fixes

    • Expanded tests for validation logic to ensure accurate behavior based on the isRequired property.
  • Tests

    • Added comprehensive tests for the SelectField, including mock implementations for ResizeObserver to validate resizing behavior.

@rahulbarwal rahulbarwal requested a review from jsartisan November 8, 2024 07:38
@rahulbarwal rahulbarwal self-assigned this Nov 8, 2024
@github-actions github-actions bot added JSON Form Issue / features related to the JSON form wiget Select Widget Select or dropdown widget Task A simple Todo Widgets & Accelerators Pod Issues related to widgets & Accelerators Widgets Product This label groups issues related to widgets labels Nov 8, 2024
Copy link
Contributor

coderabbitai bot commented Nov 8, 2024

Walkthrough

The pull request introduces enhancements and tests for the SelectField component in the SelectField.test.tsx and SelectField.tsx files. It expands the testing suite to cover validation logic based on the isRequired property and adds a mock ResizeObserver to test responsive behavior. The component itself is modified to manage its dropdown width dynamically using useEffect and useState, ensuring better responsiveness to layout changes.

Changes

File Path Change Summary
app/client/src/widgets/JSONFormWidget/fields/SelectField.test.tsx Enhanced tests for SelectField, added ResizeObserver mock, and expanded isValid function tests.
app/client/src/widgets/JSONFormWidget/fields/SelectField.tsx Added dynamic width management with ResizeObserver, updated state handling for dropdown width.

Assessment against linked issues

Objective Addressed Explanation
Fix select options getting trimmed (#37279)

Possibly related PRs

Suggested labels

Bug, Enhancement, High, Production, Community Reported, Needs Triaging, ok-to-test

Suggested reviewers

  • ApekshaBhosale
  • jacquesikot

In the code's dance, a new width we find,
With tests that ensure it's perfectly aligned.
ResizeObserver now keeps things in check,
SelectField's logic, a well-structured deck.
From validation to width, all in a flow,
A seamless experience, ready to show! 🌟


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.

@github-actions github-actions bot added the Bug Something isn't working label Nov 8, 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: 3

🧹 Outside diff range and nitpick comments (1)
app/client/src/widgets/JSONFormWidget/fields/SelectField.test.tsx (1)

157-161: Ensure consistent mocking of ResizeObserver.

You're mocking window.ResizeObserver here, while elsewhere global.ResizeObserver is used. For consistency, mock ResizeObserver on the same object throughout your tests.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 5e89aa0 and 1438c99.

📒 Files selected for processing (2)
  • app/client/src/widgets/JSONFormWidget/fields/SelectField.test.tsx (2 hunks)
  • app/client/src/widgets/JSONFormWidget/fields/SelectField.tsx (4 hunks)
🧰 Additional context used
🪛 Biome
app/client/src/widgets/JSONFormWidget/fields/SelectField.test.tsx

[error] 137-138: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

🔇 Additional comments (4)
app/client/src/widgets/JSONFormWidget/fields/SelectField.tsx (3)

1-8: LGTM: Clean import organization

The new hooks are properly imported and organized with the existing imports.


236-236: LGTM: Proper dependency management

The dropDownWidth dependency is correctly added to the useMemo dependencies array.


119-141: Verify fix for trimmed options issue

Let's verify that this implementation resolves the reported issue of trimmed select options.

app/client/src/widgets/JSONFormWidget/fields/SelectField.test.tsx (1)

80-245: Tests enhance coverage and ensure component responsiveness.

🧰 Tools
🪛 Biome

[error] 137-138: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

@rahulbarwal
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

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

Copy link

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

@rahulbarwal rahulbarwal added the ok-to-test Required label for CI label Nov 12, 2024
@rahulbarwal rahulbarwal merged commit 8cbf8a5 into release Nov 12, 2024
48 checks passed
@rahulbarwal rahulbarwal deleted the rahulbarwal/issue37279/Bug-Select-options-inside-JSONForm-getting-trimmed branch November 12, 2024 05:26
github-actions bot pushed a commit to Zeral-Zhang/appsmith that referenced this pull request Nov 20, 2024
…smithorg#37289)

## Description
<ins>Problem</ins>

The SelectField inside JSONForm widget's dropdown width was not
dynamically adjusted, resulting in inconsistent responsiveness.

<ins>Root cause</ins>

The SelectField component's dropdown width was not being updated
dynamically, causing the component to become too wide or too narrow,
affecting its usability.

<ins>Solution</ins>

This PR enhances the SelectField component to adjust its dropdown width
dynamically for improved responsiveness. This PR handles...

- Dynamically adjusting the dropdown width based on the available screen
space, ensuring a responsive user experience.
- Properly setting up and tearing down the ResizeObserver to ensure
accurate width detection.

Fixes appsmithorg#37279
_or_  
Fixes `Issue URL`
> [!WARNING]  
> _If no issue exists, please create an issue first, and check with the
maintainers if the issue is valid._

## Automation

/ok-to-test tags="@tag.JSONForm"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/11790765022>
> Commit: 1438c99
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11790765022&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.JSONForm`
> Spec:
> <hr>Tue, 12 Nov 2024 04:59:15 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Enhanced the `SelectField` component for dynamic dropdown width
adjustment based on its wrapper size.
	- Improved filter update handling within the `SelectField`.

- **Bug Fixes**
- Expanded tests for validation logic to ensure accurate behavior based
on the `isRequired` property.

- **Tests**
- Added comprehensive tests for the `SelectField`, including mock
implementations for `ResizeObserver` to validate resizing behavior.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working JSON Form Issue / features related to the JSON form wiget ok-to-test Required label for CI Select Widget Select or dropdown widget Task A simple Todo Widgets & Accelerators Pod Issues related to widgets & Accelerators Widgets Product This label groups issues related to widgets
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Select options inside JSONForm getting trimmed
2 participants