Skip to content

Commit

Permalink
Fix register data filter queries (#2789)
Browse files Browse the repository at this point in the history
* Fix register data filter queries

Signed-off-by: Elly Kitoto <[email protected]>

* Fix badge UI padding

Signed-off-by: Elly Kitoto <[email protected]>

* Solve pagination issue on data filter

Signed-off-by: Elly Kitoto <[email protected]>

* Run spotlessApply

Signed-off-by: Elly Kitoto <[email protected]>

---------

Signed-off-by: Elly Kitoto <[email protected]>
  • Loading branch information
ellykits authored Sep 29, 2023
1 parent a4b32b0 commit bc34a70
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,14 @@ fun TopScreenSection(
modifier = modifier.weight(1f).testTag(TOP_ROW_TEXT_TEST_TAG),
)
if (isFilterIconEnabled) {
IconButton(onClick = { onClick.invoke(ToolbarClickEvent.FilterData) }) {
IconButton(
onClick = { onClick.invoke(ToolbarClickEvent.FilterData) },
modifier = Modifier.padding(horizontal = 16.dp),
) {
BadgedBox(
badge = {
if (filteredRecordsCount != null && filteredRecordsCount > -1) {
Badge(modifier = Modifier.size(18.dp)) {
Badge {
Text(
text = filteredRecordsCount.toString(),
overflow = TextOverflow.Clip,
Expand Down Expand Up @@ -180,7 +183,7 @@ fun TopScreenSectionPreview() {
TopScreenSection(
title = "All Clients",
searchText = "Eddy",
filteredRecordsCount = 8,
filteredRecordsCount = 1890,
onSearchTextChanged = {},
toolBarHomeNavigation = ToolBarHomeNavigation.NAVIGATE_BACK,
isFilterIconEnabled = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ constructor(
currentPage.value.let { if (it > 0) currentPage.value = it.minus(1) }
paginateRegisterData(registerUiState.value.registerId)
}
RegisterEvent.ResetFilterRecordsCount -> _filteredRecordsCount.value = -1
RegisterEvent.ResetFilterRecordsCount -> _filteredRecordsCount.longValue = -1
}

fun filterRegisterData(event: RegisterEvent.SearchRegister) {
Expand Down Expand Up @@ -223,8 +223,7 @@ constructor(
// Get filter queries from the map. NOTE: filterId MUST be unique for all resources
val newBaseResourceDataQueries =
createQueriesForRegisterFilter(
registerDataFilterFieldsMap?.get(baseResource.filterId)?.dataQueries
?: baseResource.dataQueries,
registerDataFilterFieldsMap?.get(baseResource.filterId)?.dataQueries,
qrItemMap,
)

Expand Down Expand Up @@ -263,7 +262,7 @@ constructor(
relatedResources.map {
val newDataQueries =
createQueriesForRegisterFilter(
registerDataFilterFieldsMap?.get(it.filterId)?.dataQueries ?: it.dataQueries,
registerDataFilterFieldsMap?.get(it.filterId)?.dataQueries,
qrItemMap,
)
it.copy(
Expand Down Expand Up @@ -407,12 +406,12 @@ constructor(
viewModelScope.launch(dispatcherProvider.io()) {
val currentRegisterConfiguration = retrieveRegisterConfiguration(registerId, paramsMap)

_totalRecordsCount.value =
_totalRecordsCount.longValue =
registerRepository.countRegisterData(registerId = registerId, paramsMap = paramsMap)

// Only count filtered data when queries are updated
if (registerFilterState.value.fhirResourceConfig != null) {
_filteredRecordsCount.value =
_filteredRecordsCount.longValue =
registerRepository.countRegisterData(
registerId = registerId,
paramsMap = paramsMap,
Expand All @@ -428,14 +427,16 @@ constructor(
isFirstTimeSync =
sharedPreferencesHelper
.read(SharedPreferenceKey.LAST_SYNC_TIMESTAMP.name, null)
.isNullOrEmpty() && _totalRecordsCount.value == 0L,
.isNullOrEmpty() && _totalRecordsCount.longValue == 0L,
registerConfiguration = currentRegisterConfiguration,
registerId = registerId,
totalRecordsCount = _totalRecordsCount.value,
filteredRecordsCount = _filteredRecordsCount.value,
totalRecordsCount = _totalRecordsCount.longValue,
filteredRecordsCount = _filteredRecordsCount.longValue,
pagesCount =
ceil(
_totalRecordsCount.value
(if (registerFilterState.value.fhirResourceConfig != null) {
_filteredRecordsCount.longValue
} else _totalRecordsCount.longValue)
.toDouble()
.div(currentRegisterConfiguration.pageSize.toLong()),
)
Expand Down

0 comments on commit bc34a70

Please sign in to comment.