Skip to content

Commit

Permalink
fix: [ANDROAPP-6354] line listing filters for orgUnit and category (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mmmateos authored Dec 10, 2024
1 parent 5465d6d commit d8754d4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> = emptyList(),
): TrackerLineListItem {
return when (this) {
TrackerLineListItem.CreatedBy -> this
TrackerLineListItem.LastUpdatedBy -> this
Expand Down Expand Up @@ -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),
),
)

Expand All @@ -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),
),
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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())
}
}

0 comments on commit d8754d4

Please sign in to comment.