From 21004c19555c50aecd8c424ae304a857db4bd0ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manu=20Mu=C3=B1oz?= Date: Mon, 2 Dec 2024 12:32:21 +0100 Subject: [PATCH] fix: [ANDROAPP-6354] line listing filters for orgUnit and category MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Manu Muñoz --- .../org/analytics/charts/ChartsRepositoryImpl.kt | 16 +++++++++++++--- .../charts/bindings/LineListingExtensions.kt | 10 ++++++---- .../charts/bindings/LineListingExtensionsTest.kt | 4 +++- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/dhis_android_analytics/src/main/java/dhis2/org/analytics/charts/ChartsRepositoryImpl.kt b/dhis_android_analytics/src/main/java/dhis2/org/analytics/charts/ChartsRepositoryImpl.kt index c948c543b8..5e07432766 100644 --- a/dhis_android_analytics/src/main/java/dhis2/org/analytics/charts/ChartsRepositoryImpl.kt +++ b/dhis_android_analytics/src/main/java/dhis2/org/analytics/charts/ChartsRepositoryImpl.kt @@ -311,9 +311,19 @@ class ChartsRepositoryImpl( if (filters.isNotEmpty()) { filters.forEach { (columnIndex, value) -> lineListHeaderCache[trackerVisualizationUid]?.get(columnIndex)?.let { - filteredRepository = filteredRepository.withColumn( - column = it.withFilters(value), - ) + if (it is TrackerLineListItem.Category) { + val filterCategories = d2.categoryModule().categoryOptions() + .byDisplayName().like(value) + .blockingGetUids() + + filteredRepository = filteredRepository.withColumn( + column = it.withFilters(value, filterCategories), + ) + } else { + filteredRepository = filteredRepository.withColumn( + column = it.withFilters(value), + ) + } } } } diff --git a/dhis_android_analytics/src/main/java/dhis2/org/analytics/charts/bindings/LineListingExtensions.kt b/dhis_android_analytics/src/main/java/dhis2/org/analytics/charts/bindings/LineListingExtensions.kt index 62ffd52bed..fbb4b006e5 100644 --- a/dhis_android_analytics/src/main/java/dhis2/org/analytics/charts/bindings/LineListingExtensions.kt +++ b/dhis_android_analytics/src/main/java/dhis2/org/analytics/charts/bindings/LineListingExtensions.kt @@ -9,7 +9,10 @@ import org.hisp.dhis.android.core.analytics.trackerlinelist.TrackerLineListItem import org.hisp.dhis.android.core.common.RelativeOrganisationUnit import org.hisp.dhis.android.core.common.RelativePeriod -fun TrackerLineListItem.withFilters(value: String): TrackerLineListItem { +fun TrackerLineListItem.withFilters( + value: String, + categories: List = emptyList(), +): TrackerLineListItem { return when (this) { TrackerLineListItem.CreatedBy -> this TrackerLineListItem.LastUpdatedBy -> this @@ -51,7 +54,7 @@ fun TrackerLineListItem.withFilters(value: String): TrackerLineListItem { is TrackerLineListItem.OrganisationUnitItem -> this.copy( filters = this.filters + listOf( - OrganisationUnitFilter.Absolute(value), + OrganisationUnitFilter.Like(value), ), ) @@ -78,10 +81,9 @@ fun TrackerLineListItem.withFilters(value: String): TrackerLineListItem { EnumFilter.Like(value), ), ) - is TrackerLineListItem.Category -> this.copy( filters = this.filters + listOf( - DataFilter.Like(value), + DataFilter.In(categories), ), ) } diff --git a/dhis_android_analytics/src/test/java/dhis2/org/analytics/charts/bindings/LineListingExtensionsTest.kt b/dhis_android_analytics/src/test/java/dhis2/org/analytics/charts/bindings/LineListingExtensionsTest.kt index bf5ef59419..ca1a2f4878 100644 --- a/dhis_android_analytics/src/test/java/dhis2/org/analytics/charts/bindings/LineListingExtensionsTest.kt +++ b/dhis_android_analytics/src/test/java/dhis2/org/analytics/charts/bindings/LineListingExtensionsTest.kt @@ -1,5 +1,6 @@ package dhis2.org.analytics.charts.bindings +import org.hisp.dhis.android.core.analytics.trackerlinelist.DataFilter import org.hisp.dhis.android.core.analytics.trackerlinelist.TrackerLineListItem import org.junit.Test @@ -14,8 +15,9 @@ class LineListingExtensionsTest { assert(item.filters.isEmpty()) - val result = item.withFilters("categoryDisplayName") + val result = item.withFilters("categoryDisplayName", listOf("categoryUid")) assert((result as TrackerLineListItem.Category).filters.size == 1) + assert((result.filters.first() as DataFilter.In).values.isNotEmpty()) } }