Fix search button behavior for empty input#2541
Conversation
📝 WalkthroughWalkthroughMifosOutlinedTextField now shows Changes
Sequence DiagramsequenceDiagram
actor User
participant SearchBox
participant SearchViewModel
participant MifosOutlinedTextField
User->>SearchBox: Trigger search (empty input)
SearchBox->>SearchViewModel: onSearch("")
activate SearchViewModel
SearchViewModel->>SearchViewModel: if input.isEmpty() then showEmptyError=true, searchResult=Empty
SearchViewModel-->>SearchBox: emit updated state
deactivate SearchViewModel
SearchBox->>MifosOutlinedTextField: render with isError=true, errorText="feature_search_empty_input_field"
activate MifosOutlinedTextField
Note right of MifosOutlinedTextField: supportingText renders errorText only if isError==true
MifosOutlinedTextField-->>User: show error message
deactivate MifosOutlinedTextField
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
feature/search/src/commonMain/kotlin/com/mifos/feature/search/SearchViewModel.kt (1)
42-48: Clear error state when user starts typing.The error remains visible until the user clicks the search button again, even after they've started typing. For better UX, the error should be cleared immediately when the user updates the search text to a non-empty value.
is SearchScreenEvent.UpdateSearchText -> { viewModelScope.launch { state.value = state.value.copy( searchText = event.searchText, + showEmptyError = false, ) } }
🧹 Nitpick comments (1)
feature/search/src/commonMain/kotlin/com/mifos/feature/search/SearchViewModel.kt (1)
50-58: Consider clearing error state when clearing search text.When the user explicitly clears the search text, it's a reset action. The error state should probably also be cleared to provide a clean slate.
is SearchScreenEvent.ClearSearchText -> { viewModelScope.launch { state.value = state.value.copy( searchText = "", + showEmptyError = false, ) searchResultState.update { SearchResultState.Empty() } } }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
core/designsystem/src/commonMain/kotlin/com/mifos/core/designsystem/component/MifosOutlinedTextField.kt(1 hunks)feature/search/src/commonMain/kotlin/com/mifos/feature/search/SearchViewModel.kt(3 hunks)feature/search/src/commonMain/kotlin/com/mifos/feature/search/components/SearchBox.kt(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: PR Checks / Static Analysis Check
🔇 Additional comments (2)
core/designsystem/src/commonMain/kotlin/com/mifos/core/designsystem/component/MifosOutlinedTextField.kt (1)
210-226: LGTM! Improved consistency of error state handling.The change ensures that
errorTextis only rendered when botherrorText != nullANDisError == true. This prevents the inconsistency where error text could be displayed even whenisErroris false, which aligns with the explicit error state management introduced in this PR.feature/search/src/commonMain/kotlin/com/mifos/feature/search/SearchViewModel.kt (1)
92-132: Good implementation of empty input validation.The core logic correctly validates search input and provides appropriate feedback:
- Prevents search execution when input is empty
- Sets error flag for UI feedback
- Resets results to empty state
- Clears error flag when valid search is performed
This successfully addresses the issue where clicking search with empty input showed previous results.
Also applies to: 146-146
feature/search/src/commonMain/kotlin/com/mifos/feature/search/components/SearchBox.kt
Show resolved
Hide resolved
feature/search/src/commonMain/kotlin/com/mifos/feature/search/SearchViewModel.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Please address the @coderabbitai changes, other than that it looks good to me. This can be merged after the suggested changes are implemented.
Also apply the PR checks before pushing your recent changes to fix build issues in Github Actions.
...system/src/commonMain/kotlin/com/mifos/core/designsystem/component/MifosOutlinedTextField.kt
Show resolved
Hide resolved
|
@biplab1 I think this PR is ready to be merged. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In
`@feature/search/src/commonMain/composeResources/values/feature_search_strings.xml`:
- Line 18: The string resource feature_search_empty_input_field uses "External
ID" which is inconsistent with the rest of the UI that uses "External Id";
update the value of feature_search_empty_input_field to use "External Id" (i.e.,
"Please enter Name or Account Number or External Id to search") so
capitalization matches existing resources, or if you prefer the "ID" style,
update all other occurrences to "External ID" to keep consistency across the
codebase.
feature/search/src/commonMain/composeResources/values/feature_search_strings.xml
Show resolved
Hide resolved
| ) : ViewModel() { | ||
|
|
||
| var state = mutableStateOf(SearchScreenState()) | ||
| private set |
There was a problem hiding this comment.
@Shreyash16b To improve UI/UX, Stateflow should be used to get the most current state. Although this falls outside the purview of this ticket, a new one can be created for this purpose.
Fixes - Jira-#505
Issue : When search button is clicked with empty input field, it showed the previous results.
Before
MIFOSAC-505.Before.mp4
After
MIFOSAC-505.After.mp4
Now :
Please make sure these boxes are checked before submitting your pull request - thanks!
Run the static analysis check
./gradlew checkorci-prepush.shto make sure you didn't break anythingIf you have multiple commits please combine them into one commit by squashing them.
Summary by CodeRabbit
Bug Fixes
New Features
✏️ Tip: You can customize this high-level summary in your review settings.