-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
chore: external merge request from Contributor #36553
chore: external merge request from Contributor #36553
Conversation
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThe pull request introduces enhancements to the search and filter functionalities across several components. Key changes include the addition of testing scripts and dependencies to improve code quality, the implementation of focus behavior for input fields after clearing filters, and the introduction of unit tests for the Changes
Assessment against linked issues
Possibly related PRs
Suggested labels
Suggested reviewers
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this 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 (4)
app/client/packages/design-system/widgets-old/src/SearchComponent/index.test.tsx (3)
14-27
: Excellent test suite setup, students!Your use of a describe block to group tests and the creation of a mock function for onSearch show good organization. The renderComponent helper function is a smart move to reduce code duplication and improve test readability. Well done!
However, let's take it a step further. Can anyone tell me how we might improve this setup?
Consider extracting the default props into a separate constant. This would make it easier to maintain and update default props across all tests. Here's an example:
const defaultProps = { onSearch: onSearchMock, placeholder: "Search...", value: "", }; const renderComponent = (props = {}) => { return render( <SearchComponent {...defaultProps} {...props} />, ); };This approach allows for easier maintenance and clearer default prop values. Who can tell me why this might be beneficial in the long run?
28-43
: Good job on your first test case, class!You've done well in testing the clearing functionality of the SearchComponent. Your use of act to handle state updates shows good understanding of React's testing best practices. The assertions effectively check both the UI state and the callback invocation.
Now, let's think about what we might be missing. Can anyone suggest some additional scenarios we should test?
Consider adding the following test cases to increase our test coverage:
- Test that typing in the input field triggers the onSearch callback after the debounce period.
- Verify that the cross icon only appears when there's text in the input.
- Check that the component behaves correctly when enableClientSideSearch is false.
Who would like to take a shot at implementing one of these test cases?
45-63
: Nice work on your second test case, students!You've done a good job testing how the component handles prop updates. Your use of rerender to simulate prop changes is spot on, and your assertion correctly checks that the UI reflects the updated value.
However, let's think about how we can make this test even more robust. Can anyone suggest an improvement?
Consider adding an intermediate step to this test:
- First, simulate user input to change the local state.
- Then, update the prop value.
- Finally, assert that the new prop value overrides the local state.
This would ensure that the component correctly prioritizes prop values over local state. Here's an example of how you might implement this:
it("should reset localValue when component receives a new value prop, overriding user input", () => { const { getByPlaceholderText, rerender } = renderComponent({ value: "initial", }); const inputElement = getByPlaceholderText("Search...") as HTMLInputElement; expect(inputElement.value).toBe("initial"); // Simulate user input fireEvent.change(inputElement, { target: { value: "user input" } }); expect(inputElement.value).toBe("user input"); // Update prop rerender( <SearchComponent onSearch={onSearchMock} placeholder="Search..." value="updated prop" />, ); expect(inputElement.value).toBe("updated prop"); });Who can explain why testing this scenario is important for maintaining the component's expected behavior?
app/client/packages/design-system/widgets-old/src/SearchComponent/index.tsx (1)
117-119
: Excellent addition to our lesson plan!This change ensures that after we erase the blackboard (clear the search), we're ready to write again immediately. It's like making sure the chalk is in your hand after erasing!
However, let's make our code a bit more explicit for our future students:
Consider adding a comment to explain why we're focusing the input:
if (this.inputRef.current) { + // Retain focus on the input field after clearing this.inputRef.current.focus(); }
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
🔇 Files ignored due to path filters (1)
app/client/yarn.lock
is excluded by!**/yarn.lock
,!**/*.lock
📒 Files selected for processing (7)
- app/client/packages/design-system/widgets-old/package.json (2 hunks)
- app/client/packages/design-system/widgets-old/src/SearchComponent/index.test.tsx (1 hunks)
- app/client/packages/design-system/widgets-old/src/SearchComponent/index.tsx (2 hunks)
- app/client/packages/design-system/widgets-old/tsconfig.json (1 hunks)
- app/client/src/widgets/MultiSelectTreeWidget/component/index.tsx (1 hunks)
- app/client/src/widgets/MultiSelectWidgetV2/component/index.tsx (1 hunks)
- app/client/src/widgets/SingleSelectTreeWidget/component/index.tsx (1 hunks)
🔇 Additional comments not posted (11)
app/client/packages/design-system/widgets-old/tsconfig.json (1)
6-6
: Very good addition, class! Let's discuss why this is important.Children, today we're learning about TypeScript configuration. Can you see the new line we've added? It says
"types": ["jest"]
. This is like telling our computer to include a special book about Jest in our TypeScript library.Jest, as you might remember from our previous lessons, is a tool we use to test our code. By adding it here, we're making sure that our TypeScript compiler understands all the special words and rules that Jest uses.
This change, while small, is a step towards better code quality. It's like double-checking our homework before we hand it in. Good job!
app/client/packages/design-system/widgets-old/package.json (3)
11-13
: Excellent addition of testing scripts, class!I'm pleased to see you've added these important testing scripts to your package.json. Remember, testing is like doing your homework - it helps you catch mistakes before they become big problems!
Let's review what each script does:
"test"
: Runs all your tests, like a final exam."test:watch"
: Keeps an eye on your tests as you work, like a study buddy."test:coverage"
: Checks how much of your code is tested, like grading your test paper.Keep up the good work! These additions will help maintain the quality of your code.
17-17
: A+ for adding these testing tools to your toolkit!Class, let's examine the new testing tools you've added to your devDependencies:
@testing-library/jest-dom
: This is like a special set of colored pencils that help you draw more detailed test pictures.@types/jest
andts-jest
: These are your TypeScript homework helpers. They make sure your tests speak the same language as your code.jest
: This is your main testing textbook. It has all the rules and methods for writing good tests.jest-environment-jsdom
: Think of this as a practice stage where your components can act out their roles before the big show.These additions show that you're taking your testing seriously. Good job on setting up a comprehensive testing environment!
Also applies to: 19-19, 28-29, 33-33
11-13
: Let's connect the dots, shall we?Class, we've made some wonderful improvements to our testing setup. However, I'm a bit puzzled about how these changes relate to our lesson plan (PR objectives).
Our objectives mentioned fixing issues with cursor position and component functionality, but these changes are all about testing. Can you raise your hand and explain:
- How do these testing improvements support the fixes mentioned in the PR objectives?
- Are there additional files in this PR that implement the actual fixes?
- Will you be adding tests specific to the cursor position and component functionality issues?
Remember, it's important to show your work and explain your thinking!
Also applies to: 17-17, 19-19, 28-29, 33-33
app/client/packages/design-system/widgets-old/src/SearchComponent/index.test.tsx (1)
1-12
: Well done on setting up the test environment, class!Your imports and mocks are spot on! You've correctly imported the necessary testing utilities and the component under test. The mock implementations for lodash's debounce and the SVG icon loader are excellent choices to simplify our test environment. Keep up the good work!
app/client/packages/design-system/widgets-old/src/SearchComponent/index.tsx (3)
89-89
: Well done, class! Let's examine this new addition.The introduction of the
inputRef
is a smart move. It's like giving each student a name tag – it helps us keep track of them better! This reference will allow us to interact directly with the input element, which is crucial for maintaining focus.
Line range hint
1-144
: Class dismissed! Let's recap today's lesson.We've made some excellent improvements to our
SearchComponent
:
- We've added a new
inputRef
to keep track of our input element.- We've updated our
clearSearch
method to retain focus after clearing.- We've connected our
inputRef
to theSearchInputWrapper
in the render method.These changes work together to solve the problem of losing cursor position when clearing the search, just like we wanted. Great job, everyone! Remember to test these changes thoroughly to ensure they work as expected in all scenarios.
126-126
: A gold star for connecting the dots!Adding the
inputRef
prop to ourSearchInputWrapper
is like assigning seats to students – it ensures everything is in its right place. This change completes our lesson on retaining cursor position.To make sure our lesson plan is foolproof, let's do a quick pop quiz:
Let's verify that we're using the
inputRef
consistently:This will help us ensure we haven't missed any spots where we should be using our new reference.
✅ Verification successful
Let's Correct That Command and Try Again!
It seems the previous search had a hiccup with the file type. Let's adjust the file type to
ts
to ensureripgrep
recognizes it. Here's the updated script to verify the consistent use ofinputRef
:
Excellent Work on Integrating
inputRef
!You've successfully incorporated the
inputRef
across theSearchComponent
, ensuring that the cursor position retention feature is well-supported. Everything checks out perfectly!🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check for consistent use of inputRef in SearchComponent # Test: Search for inputRef usage in SearchComponent rg --type typescript 'inputRef' app/client/packages/design-system/widgets-old/src/SearchComponent/index.tsxLength of output: 142
Script:
#!/bin/bash # Description: Check for consistent use of inputRef in SearchComponent with corrected file type # Test: Search for inputRef usage in SearchComponent using the correct file type rg --type ts 'inputRef' app/client/packages/design-system/widgets-old/src/SearchComponent/index.tsxLength of output: 265
app/client/src/widgets/MultiSelectTreeWidget/component/index.tsx (1)
169-178
: Well done, class! This change improves user experience.Now, let's examine what we've learned from this code modification:
- The
clearButton
component has been enhanced to focus on the input field after clearing it.- This improvement allows users to immediately start typing after clearing the filter, without the need for an additional click.
- The conditional check
if (inputRef.current)
ensures that we only attempt to focus if the input reference is available, preventing potential errors.Can anyone tell me how this change relates to our lesson on user interface responsiveness? Remember, every interaction should feel smooth and intuitive!
app/client/src/widgets/SingleSelectTreeWidget/component/index.tsx (1)
176-185
: Excellent work, class! This change deserves a gold star!Now, let's examine why this improvement is so important:
User Experience: By focusing the input field after clearing, we're making it easier for our users to continue their work without interruption. It's like handing them a fresh piece of paper right after they've erased their previous work!
Efficiency: This small change can save countless clicks and frustrations. Remember, in the world of user interfaces, every millisecond counts!
Accessibility: For users relying on keyboard navigation, this change is particularly helpful. It's like making sure everyone can reach the blackboard, regardless of their height!
Keep up the good work! This is precisely the kind of attention to detail that makes our software user-friendly and accessible.
app/client/src/widgets/MultiSelectWidgetV2/component/index.tsx (1)
178-187
: Well done, class! This change deserves a gold star!Your modification to the
clearButton
component is a fantastic improvement to our multi-select widget. Let's break down why this is so good:
You've added a focus on the input element when the clear button is clicked. This is excellent because it allows our users to immediately start typing after clearing the filter. It's like erasing the blackboard and having the chalk ready in your hand!
The use of the
inputRef
to access the input element is a proper way to interact with DOM elements in React. It's like using the right tool for the right job in our classroom.The condition
if (inputRef.current)
is a safe way to ensure the input element exists before trying to focus on it. This is like checking if a student is present before calling on them to answer a question.This change will significantly enhance the user experience, making our multi-select widget more intuitive and efficient to use. Keep up the excellent work!
…smith into fix/retaining-input-reference
…smith into fix/retaining-input-reference
…iprabhu-dandanayak/appsmith into external-contri/fix/retaining-input-reference
This PR has not seen activitiy for a while. It will be closed in 7 days unless further activity is detected. |
This PR has been closed because of inactivity. |
Description
Fixes #36268
Original PR: #36268
EE PR:
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.All"
🔍 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?
Warning
Tests have not run on the HEAD f3fcc29 yet
Fri, 27 Sep 2024 06:17:04 UTC
Summary by CodeRabbit
New Features
Bug Fixes
MultiSelect
,SingleSelect
, andMultiSelectTree
components.