-
Notifications
You must be signed in to change notification settings - Fork 515
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: [Clear Button is active when no input is selected in Dropdown] #9264
Fix: [Clear Button is active when no input is selected in Dropdown] #9264
Conversation
Warning Rate limit exceeded@ANIR1604 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 2 minutes and 32 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (2)
WalkthroughThe changes in this pull request focus on enhancing the state management of the Changes
Assessment against linked issues
Possibly related PRs
Suggested reviewers
Poem
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
CodeRabbit Configuration File (
|
✅ Deploy Preview for care-ohc ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
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 (2)
src/components/Form/AutoCompleteAsync.tsx (2)
95-99
: Consider resetting hasTyped when input is clearedThe input handling looks good, but consider resetting
hasTyped
to false when the input becomes empty through backspace/delete to maintain consistency with the component's behavior.const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => { const newQuery = event.target.value; setQuery(newQuery); - setHasTyped(newQuery.length > 0); // Set hasTyped to true if input is not empty + setHasTyped(newQuery.length > 0); // Update hasTyped based on input presence
107-108
: Consider simplifying the visibility conditionWhile the logic is correct, the condition could be more readable by grouping related checks.
- const shouldShowClearButton = (hasSelection || hasTyped) && query !== ""; // Exclude placeholder when query is empty + const shouldShowClearButton = query !== "" && (hasSelection || hasTyped); // Show only when there's input and user interaction
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
src/components/Form/AutoCompleteAsync.tsx
(4 hunks)
🔇 Additional comments (4)
src/components/Form/AutoCompleteAsync.tsx (4)
67-67
: LGTM: Clean state management addition
The new state variable hasTyped
is well-named and appropriately initialized to track user interaction with the input field.
101-105
: LGTM: Comprehensive selection handling
The selection handler properly manages all relevant states, ensuring the input field reflects the selected option while maintaining the typed state.
147-157
: LGTM: Comprehensive clear button implementation
The clear button implementation properly resets all relevant states and maintains good UX with tooltips and accessibility features.
Line range hint 1-236
: Verify similar patterns in other form components
Let's ensure consistency across other form components that might have similar clear button functionality.
✅ Verification successful
Clear button implementation is consistent with existing patterns
The implementation in AutoCompleteAsync.tsx
follows the same clear button pattern found in other form components:
TextFormField.tsx
usesCareIcon
withl-times-circle
for clearing inputModelCrudEditor.tsx
uses similar icon pattern for removal actions- The new implementation maintains consistency with these existing patterns, including:
- Using the same icon (
l-times-circle
) - Proper positioning (absolute positioning on the right)
- Similar interaction patterns (click to clear)
- Consistent styling approach
- Using the same icon (
The changes align well with the existing codebase patterns and maintain UI/UX consistency across form components.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for similar clear button patterns in other form components
echo "Searching for similar clear button implementations..."
rg -l "CareIcon.*times-circle" "src/components/Form"
# Search for other autocomplete implementations
echo "Checking for other autocomplete implementations..."
rg -l "Combobox.*clear.*selection" "src/components"
Length of output: 421
Script:
#!/bin/bash
# Let's examine the clear button implementations in the identified files
echo "Checking ModelCrudEditor.tsx implementation:"
rg -A 5 -B 5 "times-circle" "src/components/Form/ModelCrudEditor.tsx"
echo "\nChecking TextFormField.tsx implementation:"
rg -A 5 -B 5 "times-circle" "src/components/Form/FormFields/TextFormField.tsx"
# Let's also check for other Combobox components that might have similar patterns
echo "\nChecking for other Combobox components:"
ast-grep --pattern 'const $_ = ($_: Props) => {
$$$
Combobox
$$$
}'
Length of output: 1218
@Jacobjeevan I had not touched the other codes but its giving errors in Cypress Tests that are being shown in different components. And the clear button is working smoothly after making the code changes |
@ANIR1604 Any updates? |
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 (3)
src/components/Assets/AssetsList.tsx (2)
Line range hint
461-477
: Consider using a more robust null checkThe current check
facility === null
might miss cases wherefacility
isundefined
. Consider using a more inclusive check.- {facility === null && ( + {!facility && (
498-506
: Enhance error logging messageWhile the null check is good, the error message could be more descriptive to aid debugging.
- console.error("No facility selected"); + console.error("Navigation failed: No facility selected in FacilitiesSelectDialogue");src/components/Patient/ManagePatients.tsx (1)
960-973
: Consider adding error notification for better UXWhile the error logging is good, consider showing a user-friendly notification when no facility is selected.
} else { console.error("No facility selected"); + Notification.Error({ + msg: "Please select a facility to continue" + }); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (3)
src/components/Assets/AssetsList.tsx
(4 hunks)src/components/ExternalResult/FacilitiesSelectDialogue.tsx
(1 hunks)src/components/Patient/ManagePatients.tsx
(2 hunks)
🔇 Additional comments (5)
src/components/ExternalResult/FacilitiesSelectDialogue.tsx (1)
14-14
: LGTM: Type enhancement for better null safety
The change to make selectedFacility
explicitly nullable improves type safety and aligns with the component's behavior.
src/components/Assets/AssetsList.tsx (2)
49-49
: LGTM: Consistent state initialization
The initialization of facility
and selectedFacility
states with null
is consistent with the type changes and provides clear initial state representation.
Also applies to: 55-56
480-485
: LGTM: Proper state cleanup
The facility state reset logic is well-implemented with appropriate condition checking.
src/components/Patient/ManagePatients.tsx (2)
105-106
: LGTM: Consistent state initialization
The initialization of selectedFacility
as null is consistent with the pattern used across other components.
978-978
: LGTM: Proper state cleanup
The reset of selectedFacility
to null on cancel is appropriate.
Now It's working Perfect Sir @Jacobjeevan. I had attached a screencast of the website after the changes. Plz review and approve my PR if it's ok. Screencast.from.2024-12-06.03-55-34.webm |
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 (1)
src/components/Patient/ManagePatients.tsx (1)
978-991
: Enhance error message clarityWhile the error handling is good, the error messages could be more descriptive and actionable.
Consider updating the error messages to be more specific:
- Notification.Error({ msg: "No facility selected" }); + Notification.Error({ msg: "Please select a facility to proceed" }); - Notification.Error({ msg: "Unknown dialog state" }); + Notification.Error({ msg: "Invalid operation requested. Please try again" });
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
src/components/Assets/AssetsList.tsx
(4 hunks)src/components/Patient/ManagePatients.tsx
(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- src/components/Assets/AssetsList.tsx
🔇 Additional comments (2)
src/components/Patient/ManagePatients.tsx (2)
103-104
: LGTM: Proper state initialization
The nullable type definition and null initialization for selectedFacility
state is appropriate for handling the unselected state.
996-996
: LGTM: Proper state cleanup
The reset of selectedFacility
to null in the cancel handler ensures proper cleanup of the selection state.
@Jacobjeevan Solved all the errors related to clear selection at all instances. |
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 (1)
src/components/Patient/ManagePatients.tsx (1)
978-993
: Consider extracting dialog handlers into separate functions.The current implementation works correctly but could be more maintainable. Consider refactoring the handlers into separate functions for better readability and testability.
+ const handleFacilityDialogOk = () => { + if (!selectedFacility) { + Notification.Error({ msg: "No facility selected" }); + return; + } + + const routes = { + create: `facility/${selectedFacility.id}/patient`, + 'list-discharged': `facility/${selectedFacility.id}/discharged-patients` + }; + + const route = routes[showDialog]; + if (route) { + navigate(route); + } + }; + + const handleFacilityDialogCancel = () => { + setShowDialog(undefined); + setSelectedFacility(null); + }; <FacilitiesSelectDialogue show={!!showDialog} setSelected={(e) => setSelectedFacility(e)} selectedFacility={selectedFacility} - handleOk={() => { - if (selectedFacility) { - switch (showDialog) { - case "create": - navigate(`facility/${selectedFacility.id}/patient`); - break; - case "list-discharged": - navigate(`facility/${selectedFacility.id}/discharged-patients`); - break; - } - } else { - Notification.Error({ msg: "No facility selected" }); - } - }} - handleCancel={() => { - setShowDialog(undefined); - setSelectedFacility(null); - }} + handleOk={handleFacilityDialogOk} + handleCancel={handleFacilityDialogCancel} />
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
src/components/Patient/ManagePatients.tsx
(2 hunks)
🔇 Additional comments (1)
src/components/Patient/ManagePatients.tsx (1)
103-104
: LGTM! Explicit nullable type improves type safety.
The state initialization with explicit null type aligns well with TypeScript best practices and helps prevent undefined behavior.
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 (1)
src/components/Assets/AssetsList.tsx (1)
Line range hint
461-472
: Fix the handleOk implementation and null checkTwo issues need attention:
- The
handleOk
function returns undefined without any action, which seems incorrect- The null check should use strict equality for better type safety
Apply these changes:
- {facility == null && ( + {facility === null && ( <FacilitiesSelectDialogue show={importAssetModalOpen} setSelected={(e) => setFacility(e)} selectedFacility={selectedFacility} - handleOk={() => { - return undefined; - }} + handleOk={() => { + if (selectedFacility) { + setFacility(selectedFacility); + setImportAssetModalOpen(false); + } + }} handleCancel={() => { return setImportAssetModalOpen(false); }} />
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
src/components/Assets/AssetsList.tsx
(4 hunks)src/components/Patient/ManagePatients.tsx
(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- src/components/Patient/ManagePatients.tsx
🧰 Additional context used
📓 Learnings (1)
src/components/Assets/AssetsList.tsx (1)
Learnt from: Jacobjeevan
PR: ohcnetwork/care_fe#9080
File: src/components/Users/LinkedFacilities.tsx:42-42
Timestamp: 2024-11-12T12:46:55.920Z
Learning: In the `LinkedFacilities` component (`src/components/Users/LinkedFacilities.tsx`), when using `FacilitySelect` which supports an array of `FacilityModel` items, and restricting selection to just one, it's acceptable to keep the `facility` state typed as `any` to maintain compatibility.
🔇 Additional comments (3)
src/components/Assets/AssetsList.tsx (3)
55-55
: LGTM: State initialization follows established patterns
The initialization of selectedFacility
as an optional FacilityModel
aligns with the component's requirements and existing patterns.
494-503
: LGTM: Robust facility selection handling
The implementation includes all necessary safeguards:
- Null check before navigation
- User feedback through notification
- Proper state cleanup on cancel
55-55
: Verify alignment with PR objectives
While the facility selection implementation is solid, let's verify if these changes address the original issue regarding the clear button visibility in the dropdown component.
Also applies to: 494-503
@rithviknishad Ok I will be working on this tomorrow. Can't I change it to null at Time 0 ? In my point of view it will be a great approach to give it a null value. |
@rithviknishad Sir plz review my PR ... Are we ok to go with these changes ? |
@ANIR1604 Your efforts have helped advance digital healthcare and TeleICU systems. 🚀 Thank you for taking the time out to make CARE better. We hope you continue to innovate and contribute; your impact is immense! 🙌 |
Proposed Changes
Behaviour after the changes
Screen Records
Screencast.from.2024-12-02.00-14-08.webm
Summary by CodeRabbit
New Features
Bug Fixes
Documentation