[FEATURE REQUEST] Take advantage of the search_min_length capability#4792
[FEATURE REQUEST] Take advantage of the search_min_length capability#4792nero002 wants to merge 2 commits intoowncloud:masterfrom
search_min_length capability#4792Conversation
|
@jesmrec can you please review |
There was a problem hiding this comment.
Good job @nero002! 💯 Some comments here. Let us know if you have any questions about them!
NOTE 1: Just for you to know, we use underscores for the name branch (feature/search_min_lenght_capability). Do not remove the branch, but keep in mind for future PRs 😄
NOTE 2: Be careful with the names. The correct spelling is length, not lenght
| class AddMemberFragment: Fragment(), SearchMembersAdapter.SearchMembersAdapterListener { | ||
| private var _binding: AddMemberFragmentBinding? = null | ||
| private val binding get() = _binding!! | ||
| private val getStoredCapabilitiesUseCase: GetStoredCapabilitiesUseCase by inject() |
There was a problem hiding this comment.
If you inject a use case directly into the fragment, we are not following the Clean Architecture. In these cases, we use the ViewModels, which contain the methods that execute the use cases.
In this case, if you want to run getStoredCapabilitiesUseCase you would need to use the CapabilityViewModel in the fragment (or create a new method in SpaceMembersViewModel that runs that use case)
private val capabilityViewModel: CapabilityViewModel by viewModel {
parametersOf(
requireArguments().getString(ARG_ACCOUNT_NAME)
)
}
Let us know if you have any questions about the app architecture 😄
| ReleaseNote( | ||
| title = R.string.release_notes_4_8_0_title_search_minimum_length, | ||
| subtitle = R.string.release_notes_4_8_0_subtitle_search_minimum_length, | ||
| type = ReleaseNoteType.ENHANCEMENT | ||
| ), |
There was a problem hiding this comment.
Release note not needed in this case 😄
| if (newText.length >= minimumSearchLength) { | ||
| spaceMembersViewModel.searchMembers(newText) | ||
| } else { | ||
| spaceMembersViewModel.clearSearch() | ||
| } |
There was a problem hiding this comment.
I would not use more than line of code for this block. My suggestion:
if (newText.length >= minimumSearchLength) { spaceMembersViewModel.searchMembers(newText) } else { spaceMembersViewModel.clearSearch() }
| private fun initSearchMinLength() { | ||
| val accountName = requireArguments().getString(ARG_ACCOUNT_NAME) ?: return | ||
| minimumSearchLength = getStoredCapabilitiesUseCase( | ||
| GetStoredCapabilitiesUseCase.Params(accountName = accountName) | ||
| )?.getFilesSharingSearchMinLength() ?: OCCapability.DEFAULT_FILES_SHARING_SEARCH_MIN_LENGTH | ||
| } | ||
|
|
There was a problem hiding this comment.
Based on the comment above about Clean Architecture, this method is not longer needed. Instead, you must run the ViewModel method
| public static final String CAPABILITIES_SHARING_PUBLIC_MULTIPLE = "sharing_public_multiple"; | ||
| public static final String CAPABILITIES_SHARING_PUBLIC_SUPPORTS_UPLOAD_ONLY = "supports_upload_only"; | ||
| public static final String CAPABILITIES_SHARING_RESHARING = "sharing_resharing"; | ||
| public static final String CAPABILITIES_SHARING_SEARCH_MIN_LENGTH = "search_min_length"; |
There was a problem hiding this comment.
Not needed. db/ProviderMeta.java is deprecated as it belongs to the old database
| filesSharingSearchMinLength = capabilities?.fileSharingCapabilities?.fileSharingSearchMinLenght | ||
| ?: capabilities?.fileSharingCapabilities?.fileSharingSearchMinLength, |
There was a problem hiding this comment.
Is it OK? The same code appears before and after ?:
capabilities?.fileSharingCapabilities?.fileSharingSearchMinLenght ?: capabilities?.fileSharingCapabilities?.fileSharingSearchMinLength
| @Json(name = "search_min_lenght") | ||
| val fileSharingSearchMinLenght: Int?, | ||
| @Json(name = "search_min_length") | ||
| val fileSharingSearchMinLength: Int?, |
There was a problem hiding this comment.
Unit tests for response objects are not maintained at this moment in the project. In the future, we will have to discuss about them but right now we only create unit tests for datasources and repositories. So, you can remove this file 😄
| fun getFilesSharingSearchMinLength(): Int = | ||
| filesSharingSearchMinLength?.takeIf { it > 0 } ?: DEFAULT_FILES_SHARING_SEARCH_MIN_LENGTH | ||
|
|
||
| companion object { | ||
| const val DEFAULT_FILES_SHARING_SEARCH_MIN_LENGTH = 3 | ||
| } | ||
|
|
There was a problem hiding this comment.
I wouldn't set a default value for filesSharingSearchMinLenght in the model (OCCapability) when it's null, because we are losing some information that comes from the server. Instead, I would handle this in the fragment after observing the capabilities. What do you think?
There was a problem hiding this comment.
The same for these tests. We are not maintaining tests for model classes. We have to discuss about them - you can remove the tests from OCCapabilityTest.kt 👍🏻
search_min_lenght capability
search_min_lenght capabilitysearch_min_lenght capability
| val minSearchLength = capabilities?.getFilesSharingSearchMinLength() | ||
| ?: OCCapability.DEFAULT_FILES_SHARING_SEARCH_MIN_LENGTH | ||
|
|
||
| if (userQuery.length < minSearchLength) { | ||
| return MatrixCursor(COLUMNS) | ||
| } |
There was a problem hiding this comment.
Could yo try to refactor this? Detekt workflow (link) is failing in the CI system because the method searchUsersAndGroups exceeds 100 lines
search_min_lenght capabilitysearch_min_length capability
Related Issues
App:
ReleaseNotesViewModel.ktcreating a newReleaseNote()with String resources (if required)Description
files_sharing.search_min_lenghtdrive the minimum typed characters required before running user/member searches.3when the capability is not provided.QA
./gradlew :owncloudComLibrary:testDebugUnitTest --tests "*CapabilityResponseTest" :owncloudDomain:testDebugUnitTest --tests "*OCCapabilityTest"./gradlew :owncloudApp:compileOriginalDebugKotlin3when capability is absent.