Skip to content

Commit

Permalink
Merge pull request #20390 from wordpress-mobile/fix/loading-state-of-…
Browse files Browse the repository at this point in the history
…traffic-chart

Fix the loading state of the traffic chart
  • Loading branch information
ravishanker authored Mar 3, 2024
2 parents 1a67bc0 + c069412 commit a1cdc18
Showing 1 changed file with 23 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,6 @@ class UiModelMapper
return mapStatsWithOverview(PostDetailType.POST_OVERVIEW, useCaseModels, showError)
}

fun mapViewsVisitorsDetailStats(
useCaseModels: List<UseCaseModel>,
showError: (Int) -> Unit
): UiModel {
return mapStatsWithOverview(TimeStatsType.OVERVIEW, useCaseModels, showError)
}

@Suppress("CyclomaticComplexMethod")
private fun mapStatsWithOverview(
overViewType: StatsType,
Expand All @@ -105,30 +98,30 @@ class UiModelMapper
return if (!allFailing && (overviewHasData || !overviewIsFailing)) {
if (useCaseModels.isNotEmpty()) {
UiModel.Success(useCaseModels.mapNotNull { useCaseModel ->
if ((useCaseModel.type == overViewType) && useCaseModel.data != null) {
StatsBlock.Success(useCaseModel.type, useCaseModel.data)
} else {
when (useCaseModel.state) {
SUCCESS -> StatsBlock.Success(useCaseModel.type, useCaseModel.data ?: listOf())
ERROR -> useCaseModel.stateData?.let {
StatsBlock.Error(
useCaseModel.type,
useCaseModel.stateData
)
}
LOADING -> useCaseModel.stateData?.let {
StatsBlock.Loading(
useCaseModel.type,
useCaseModel.stateData
)
}
EMPTY -> useCaseModel.stateData?.let {
StatsBlock.EmptyBlock(
useCaseModel.type,
useCaseModel.stateData
)
}
when {
useCaseModel.state == LOADING -> useCaseModel.stateData?.let {
StatsBlock.Loading(useCaseModel.type, useCaseModel.stateData)
}

useCaseModel.type == overViewType && useCaseModel.data != null -> StatsBlock.Success(
useCaseModel.type,
useCaseModel.data
)

useCaseModel.state == SUCCESS -> StatsBlock.Success(
useCaseModel.type,
useCaseModel.data ?: listOf()
)

useCaseModel.state == ERROR -> useCaseModel.stateData?.let {
StatsBlock.Error(useCaseModel.type, useCaseModel.stateData)
}

useCaseModel.state == EMPTY -> useCaseModel.stateData?.let {
StatsBlock.EmptyBlock(useCaseModel.type, useCaseModel.stateData)
}

else -> null
}
})
} else {
Expand Down

0 comments on commit a1cdc18

Please sign in to comment.